diff options
author | versecafe <147033096+versecafe@users.noreply.github.com> | 2024-09-03 08:54:02 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-03 14:54:02 +0100 |
commit | ee334747949c6696a0128d1ce709078ecc564598 (patch) | |
tree | 6099b3f73f4d0b371ee2046ee3288d3400cd54a7 /src/gleam_stdlib.mjs | |
parent | a349b6273717d42c232079b0bfcf5002d10e10d3 (diff) | |
download | gleam_stdlib-ee334747949c6696a0128d1ce709078ecc564598.tar.gz gleam_stdlib-ee334747949c6696a0128d1ce709078ecc564598.zip |
Add `to_precision` to `gleam/float` (#668)
Diffstat (limited to 'src/gleam_stdlib.mjs')
-rw-r--r-- | src/gleam_stdlib.mjs | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/src/gleam_stdlib.mjs b/src/gleam_stdlib.mjs index 9fe6caa..50ebb46 100644 --- a/src/gleam_stdlib.mjs +++ b/src/gleam_stdlib.mjs @@ -426,7 +426,7 @@ export function compile_regex(pattern, options) { export function regex_split(regex, string) { return List.fromArray( string.split(regex).map((item) => (item === undefined ? "" : item)), - ); + ); } export function regex_scan(regex, string) { @@ -448,7 +448,7 @@ export function regex_scan(regex, string) { } export function regex_replace(regex, original_string, replacement) { - return original_string.replaceAll(regex, replacement) + return original_string.replaceAll(regex, replacement); } export function new_map() { @@ -550,8 +550,7 @@ export function encode64(bit_array, padding) { if (padding) { if (k === 1) { base64 += "=="; - } - else if (k === 2) { + } else if (k === 2) { base64 += "="; } } @@ -566,7 +565,7 @@ export function decode64(sBase64) { const length = binString.length; const array = new Uint8Array(length); for (let i = 0; i < length; i++) { - array[i] = binString.charCodeAt(i); + array[i] = binString.charCodeAt(i); } return new Ok(new BitArray(array)); } catch { @@ -827,25 +826,40 @@ export function inspect(v) { } function inspectString(str) { - let new_str = "\""; + let new_str = '"'; for (let i = 0; i < str.length; i++) { let char = str[i]; switch (char) { - case '\n': new_str += "\\n"; break; - case '\r': new_str += "\\r"; break; - case '\t': new_str += "\\t"; break; - case '\f': new_str += "\\f"; break; - case '\\': new_str += "\\\\"; break; - case '\"': new_str += "\\\""; break; + case "\n": + new_str += "\\n"; + break; + case "\r": + new_str += "\\r"; + break; + case "\t": + new_str += "\\t"; + break; + case "\f": + new_str += "\\f"; + break; + case "\\": + new_str += "\\\\"; + break; + case '"': + new_str += '\\"'; + break; default: - if (char < ' ' || (char > '~' && char < '\u{00A0}')) { - new_str += "\\u{" + char.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0") + "}"; + if (char < " " || (char > "~" && char < "\u{00A0}")) { + new_str += + "\\u{" + + char.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0") + + "}"; } else { new_str += char; } } } - new_str += "\""; + new_str += '"'; return new_str; } |