aboutsummaryrefslogtreecommitdiff
path: root/src/gleam_stdlib.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'src/gleam_stdlib.mjs')
-rw-r--r--src/gleam_stdlib.mjs18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/gleam_stdlib.mjs b/src/gleam_stdlib.mjs
index 632c668..2b0a6e1 100644
--- a/src/gleam_stdlib.mjs
+++ b/src/gleam_stdlib.mjs
@@ -392,11 +392,11 @@ export function regex_scan(regex, string) {
const submatches = [];
for (let n = match.length - 1; n > 0; n--) {
if (match[n]) {
- submatches[n-1] = new Some(match[n])
- continue
+ submatches[n - 1] = new Some(match[n]);
+ continue;
}
- if(submatches.length > 0) {
- submatches[n-1] = new None()
+ if (submatches.length > 0) {
+ submatches[n - 1] = new None();
}
}
return new RegexMatch(content, List.fromArray(submatches));
@@ -564,6 +564,10 @@ export function classify_dynamic(data) {
return "Map";
} else if (typeof data === "number") {
return "Float";
+ } else if (data === null) {
+ return "Null";
+ } else if (data === undefined) {
+ return "Nil";
} else {
let type = typeof data;
return type.charAt(0).toUpperCase() + type.slice(1);
@@ -633,6 +637,12 @@ export function decode_map(data) {
if (data instanceof PMap) {
return new Ok(PMap.fromMap(data));
}
+ if (data == null) {
+ return decoder_error("Map", data);
+ }
+ if (typeof data !== "object") {
+ return decoder_error("Map", data);
+ }
const proto = Object.getPrototypeOf(data);
if (proto === Object.prototype || proto === null) {
return new Ok(PMap.fromObject(data));