@fink/std-lib
Version:
fink standard lib
43 lines (40 loc) • 1.64 kB
JavaScript
import { ˆnew } from "@fink/js-interop/reflect.js";
import { is_instance, get_type } from "@fink/js-interop/reflect.js";
import { String, TextEncoder, TextDecoder } from "@fink/js-interop/globals.js";
export const from_char_codes = String.fromCharCode;
export const from_code_points = String.fromCodePoint;
export const char_code = (str, idx) => str.charCodeAt(idx);
export const code_point = (str, idx) => str.codePointAt(idx);
// TODO: support offsets?
export const ends_with = (str, end, ...args) => str.endsWith(end, ...args);
export const starts_with = (str, end, ...args) => str.startsWith(end, ...args);
export const slice = (str, ...args) => str.slice(...args);
export const pad_start = (str, target_len, pad_str) => str.padStart(target_len, pad_str);
export const pad_end = (str, target_len, pad_str) => str.padEnd(target_len, pad_str);
export const trim = str => str.trim();
export const trim_start = str => str.trimStart();
export const trim_end = str => str.trimEnd();
export const repeat = (str, num) => str.repeat(num);
export const lower_case = str => str.toLowerCase();
export const upper_case = str => str.toUpperCase();
export const raw = String.raw;
export const encode = (text, encoding) => {
const encoder = ˆnew(TextEncoder, encoding);
return encoder.encode(text);
};
export const decode = (bytes, encoding) => {
const encoder = ˆnew(TextDecoder, encoding);
return encoder.decode(bytes);
};
export 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;
}
};