UNPKG

@fink/std-lib

Version:
106 lines (68 loc) 2.13 kB
const { ˆnew } = require("@fink/js-interop/reflect.js"); const { is_instance, get_type } = require("@fink/js-interop/reflect.js"); const { String, TextEncoder, TextDecoder } = require("@fink/js-interop/globals.js"); const from_char_codes = String.fromCharCode; exports.from_char_codes = from_char_codes; const from_code_points = String.fromCodePoint; exports.from_code_points = from_code_points; const char_code = (str, idx) => str.charCodeAt(idx); exports.char_code = char_code; const code_point = (str, idx) => str.codePointAt(idx); exports.code_point = code_point; // TODO: support offsets? const ends_with = (str, end, ...args) => str.endsWith(end, ...args); exports.ends_with = ends_with; const starts_with = (str, end, ...args) => str.startsWith(end, ...args); exports.starts_with = starts_with; const slice = (str, ...args) => str.slice(...args); exports.slice = slice; const pad_start = (str, target_len, pad_str) => str.padStart(target_len, pad_str); exports.pad_start = pad_start; const pad_end = (str, target_len, pad_str) => str.padEnd(target_len, pad_str); exports.pad_end = pad_end; const trim = str => str.trim(); exports.trim = trim; const trim_start = str => str.trimStart(); exports.trim_start = trim_start; const trim_end = str => str.trimEnd(); exports.trim_end = trim_end; const repeat = (str, num) => str.repeat(num); exports.repeat = repeat; const lower_case = str => str.toLowerCase(); exports.lower_case = lower_case; const upper_case = str => str.toUpperCase(); exports.upper_case = upper_case; const raw = String.raw; exports.raw = raw; const encode = (text, encoding) => { const encoder = ˆnew(TextEncoder, encoding); return encoder.encode(text); }; exports.encode = encode; const decode = (bytes, encoding) => { const encoder = ˆnew(TextDecoder, encoding); return encoder.decode(bytes); }; exports.decode = decode; const is_str = str => { const ˆvalue_1 = str; if (`string` === get_type(ˆvalue_1)) { return true; } if (is_instance(ˆvalue_1, String)) { return true; } { return false; } }; exports.is_str = is_str;