Current section

Files

Jump to
gossamer src gossamer string.ffi.mjs
Raw

src/gossamer/string.ffi.mjs

// src/gossamer/string.ffi.ts
import * as $order from "../../gleam_stdlib/gleam/order.mjs";
import { fromArray, toArray } from "../utils/list.ffi.mjs";
import { toNormalizationForm } from "./string/normalization_form.ffi.mjs";
import { indexToResult, toResult } from "../utils/result.ffi.mjs";
var from_char_code = (code) => String.fromCharCode(code);
var from_char_codes = (codes) => String.fromCharCode(...toArray(codes));
var from_code_point = (code) => toResult.fromThrows(() => String.fromCodePoint(code));
var from_code_points = (codes) => toResult.fromThrows(() => String.fromCodePoint(...toArray(codes)));
var at = (string, index) => toResult(string.at(index));
var char_code_at = (string, index) => {
const code = string.charCodeAt(index);
return Number.isNaN(code) ? toResult(void 0) : toResult(code);
};
var code_point_at = (string, index) => toResult(string.codePointAt(index));
var normalize = (string) => string.normalize();
var normalize_with = (string, form) => string.normalize(toNormalizationForm(form));
var locale_compare = (string, other) => {
const result = string.localeCompare(other);
if (result < 0) return $order.Order$Lt();
if (result > 0) return $order.Order$Gt();
return $order.Order$Eq();
};
var to_locale_lower_case = (string) => string.toLocaleLowerCase();
var to_locale_upper_case = (string) => string.toLocaleUpperCase();
var is_well_formed = (string) => string.isWellFormed();
var to_well_formed = (string) => string.toWellFormed();
var index_of = (string, search) => indexToResult(string.indexOf(search));
var index_of_from = (string, search, position) => indexToResult(string.indexOf(search, position));
var last_index_of = (string, search) => indexToResult(string.lastIndexOf(search));
var last_index_of_from = (string, search, position) => indexToResult(string.lastIndexOf(search, position));
var slice = (string, start, end) => string.slice(start, end);
var length = (string) => string.length;
var concat = (string, other) => string.concat(other);
var includes = (string, search) => string.includes(search);
var includes_from = (string, search, position) => string.includes(search, position);
var starts_with = (string, prefix) => string.startsWith(prefix);
var starts_with_from = (string, prefix, position) => string.startsWith(prefix, position);
var ends_with = (string, suffix) => string.endsWith(suffix);
var ends_with_within = (string, suffix, length2) => string.endsWith(suffix, length2);
var replace = (string, pattern, replacement) => string.replace(pattern, replacement);
var replace_all = (string, pattern, replacement) => string.replaceAll(pattern, replacement);
var split = (string, separator) => fromArray(string.split(separator));
var split_with_limit = (string, separator, limit) => fromArray(string.split(separator, limit));
var to_lower_case = (string) => string.toLowerCase();
var to_upper_case = (string) => string.toUpperCase();
var trim = (string) => string.trim();
var trim_start = (string) => string.trimStart();
var trim_end = (string) => string.trimEnd();
var repeat = (string, times) => {
return toResult.fromThrows(() => string.repeat(times));
};
var pad_start = (string, target_length, pad) => toResult.fromThrows(() => string.padStart(target_length, pad));
var pad_end = (string, target_length, pad) => toResult.fromThrows(() => string.padEnd(target_length, pad));
var substring = (string, start, end) => string.substring(start, end);
export {
at,
char_code_at,
code_point_at,
concat,
ends_with,
ends_with_within,
from_char_code,
from_char_codes,
from_code_point,
from_code_points,
includes,
includes_from,
index_of,
index_of_from,
is_well_formed,
last_index_of,
last_index_of_from,
length,
locale_compare,
normalize,
normalize_with,
pad_end,
pad_start,
repeat,
replace,
replace_all,
slice,
split,
split_with_limit,
starts_with,
starts_with_from,
substring,
to_locale_lower_case,
to_locale_upper_case,
to_lower_case,
to_upper_case,
to_well_formed,
trim,
trim_end,
trim_start
};