Rust modules in TypeScript
TypeScript implementations of 23 Rust standard library functions across 1 module. Each function is individually importable and tree-shakeable.
str- contains
- ends_with
- find
- len
- lines
- match_indices
- replace
- rfind
- rsplit_once
- rsplit_terminator
- rsplitn
- split_inclusive
- split_once
- split_terminator
- splitn
- starts_with
- strip_prefix
- strip_suffix
- to_lowercase
- to_uppercase
- trim
- trim_end
- trim_start
We have 23 Rust functions so far - help us add more
Got a rainy Sunday afternoon and a taste for a porting puzzle?
- Get inspiration from the Rust std::str docs.
- Click "New file" in the appropriate folder on GitHub. This will fork the project to your account, directly add the file to it, and send a Pull Request to us.
We will then review it. If it's useful to the project and in line with our contributing guidelines your work will become part of Locutus and you'll be automatically credited in the authors section accordingly.
Upstream Surface Inventory 23/216 shipped · 166 next 11%
Locutus tracks 12 upstream namespaces for Rust and sorts them into what is already shipped, what we still want, what we intentionally keep, and what still needs a decision.
This inventory now tracks a broader slice of Rust core/std primitives and slice helpers first, excluding the wider crate ecosystem.
Shipped (23)
Next
Remaining string helpers are useful plain-value portability targets unless they depend on iterators or byte semantics.
is_asciirepeatsplit_ascii_whitespace
Explicit non-goals (8)
-
bytesByte iterators do not fit Locutus' current plain-value model. -
char_indicesIterator-returning APIs do not fit Locutus' plain-value model. -
charsIterator-returning APIs do not fit Locutus' plain-value model. -
matchesIterator-returning APIs do not fit Locutus' plain-value model. -
parseGeneric trait-driven parsing does not map cleanly to JS plain values. -
rmatch_indicesIterator-returning APIs do not fit Locutus' plain-value model. -
rmatchesIterator-returning APIs do not fit Locutus' plain-value model. -
trim_matchesPattern-driven trimming does not map cleanly to one stable plain-value contract.
f32 primitive methods
Next
Scalar floating-point helpers are strong Rust portability targets.
absacosacoshasinasinhatanatan2atanhcbrtceilclampcopysigncoscoshexpexp_m1exp2floorfracthypotis_finiteis_infiniteis_nanis_normallnln_1ploglog10log2maxminmul_addpowfpowireciproundsignumsinsinhsqrttantanhto_degreesto_radianstotal_cmptrunc
f64 primitive methods
Next
Scalar floating-point helpers are strong Rust portability targets.
absacosacoshasinasinhatanatan2atanhcbrtceilclampcopysigncoscoshexpexp_m1exp2floorfracthypotis_finiteis_infiniteis_nanis_normallnln_1ploglog10log2maxminmul_addpowfpowireciproundsignumsinsinhsqrttantanhto_degreesto_radianstotal_cmptrunc
char primitive methods
Next
Character classification and ASCII-case helpers are strong plain-value portability targets.
from_digitis_alphabeticis_alphanumericis_asciiis_ascii_alphabeticis_ascii_alphanumericis_ascii_controlis_ascii_digitis_ascii_graphicis_ascii_hexdigitis_ascii_lowercaseis_ascii_punctuationis_ascii_uppercaseis_ascii_whitespaceis_controlis_digitis_lowercaseis_numericis_uppercaseis_whitespacelen_utf16len_utf8to_ascii_lowercaseto_ascii_uppercaseto_digit
Explicit non-goals (6)
-
encode_utf16Iterator-like encoding sinks do not fit Locutus' plain-value model. -
escape_debugEscape iterators do not fit Locutus' plain-value model. -
escape_defaultEscape iterators do not fit Locutus' plain-value model. -
escape_unicodeEscape iterators do not fit Locutus' plain-value model. -
to_lowercaseMulti-codepoint case iterators do not fit one stable plain-value contract. -
to_uppercaseMulti-codepoint case iterators do not fit one stable plain-value contract.
i32 primitive methods
Next
Signed integer helpers are strong Rust portability targets.
abschecked_abschecked_addchecked_subclampis_negativeis_positivemaxminpowsignum
u32 primitive methods
Next
Unsigned integer helpers are strong Rust portability targets.
checked_addchecked_subclampis_power_of_twomaxminnext_power_of_twopow
usize primitive methods
Next
Pointer-sized integer helpers are strong Rust portability targets.
checked_addchecked_subclampis_power_of_twomaxminnext_power_of_twopow
slice primitive methods
Next
Search helpers have a clean plain-value contract.
binary_search
Membership helpers have a clean plain-value contract.
contains
Boundary checks have a clean plain-value contract.
ends_withstarts_with
Boundary readers have a clean plain-value contract.
firstlast
Size helpers have a clean plain-value contract.
len
Explicit non-goals (7)
-
binary_search_byMany slice methods are iterator- or mutability-heavy rather than one stable plain-value contract. -
binary_search_by_keyMany slice methods are iterator- or mutability-heavy rather than one stable plain-value contract. -
getMany slice methods are iterator- or mutability-heavy rather than one stable plain-value contract. -
is_emptyMany slice methods are iterator- or mutability-heavy rather than one stable plain-value contract. -
partition_pointMany slice methods are iterator- or mutability-heavy rather than one stable plain-value contract. -
strip_prefixMany slice methods are iterator- or mutability-heavy rather than one stable plain-value contract. -
strip_suffixMany slice methods are iterator- or mutability-heavy rather than one stable plain-value contract.
std::cmp functions
Next
Comparison helpers over plain values are strong Rust portability targets.
maxmax_bymax_by_keyminmin_bymin_by_key
bool primitive methods
Next
Boolean combinator helpers have a clean plain-value contract.
thenthen_some
Option methods
Next
Optional-value predicates have a clean plain-value contract.
is_noneis_some
Explicit non-goals (3)
-
mapOption combinators revolve around sum-type wrappers rather than one stable plain-value contract. -
ok_orOption combinators revolve around sum-type wrappers rather than one stable plain-value contract. -
unwrap_orOption combinators revolve around sum-type wrappers rather than one stable plain-value contract.
Result methods
Next
Result predicates have a clean plain-value contract.
is_erris_ok
Explicit non-goals (3)
-
mapResult combinators revolve around sum-type wrappers rather than one stable plain-value contract. -
map_errResult combinators revolve around sum-type wrappers rather than one stable plain-value contract. -
unwrap_orResult combinators revolve around sum-type wrappers rather than one stable plain-value contract.