Ruby modules in TypeScript
TypeScript implementations of 44 Ruby standard library functions across 3 modules. Each function is individually importable and tree-shakeable.
Array- bsearch
- bsearch_index
- compact
- filter_map
- first
- flatten
- group_by
- last
- permutation
- sample
- slice_when
- tally
- uniq
- zip
- capitalize
- chomp
- chop
- delete_prefix
- delete_suffix
- downcase
- end_with
- gsub
- include
- length
- reverse
- start_with
- strip
- tr
- upcase
We have 44 Ruby functions so far - help us add more
Got a rainy Sunday afternoon and a taste for a porting puzzle?
- Get inspiration from the Ruby core documentation.
- 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 44/942 shipped · 577 next 5%
Locutus tracks 16 upstream namespaces for Ruby 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 official Ruby core and stdlib plain-value surfaces rather than the broader gem ecosystem.
In progress
Next
Ruby Math helpers map cleanly to JS numbers.
acoshasinhatan2atanherferfcfrexpgammahypotldexplgamma
Shipped (15)
-
capitalize -
chomp -
chop -
delete_prefix -
delete_suffix -
downcase -
end_with? -
gsub -
include? -
length -
reverse -
start_with? -
strip -
tr -
upcase
Next
Most Ruby String methods are strong plain-value portability targets.
-@[][]=*%++@<<<<==~>>=ascii_only?between?capitalize!casecmpcasecmp?centercharschomp!chop!chrclampclearcodepointsconcatcountdedupdeletedelete_prefix!delete_suffix!delete!downcase!dumpempty?getbytegrapheme_clustersgsub!hexindexinsertlinesljustlstriplstrip!matchmatch?nextnext!octordpartitionprependreplacereverse!rindexrjustrpartitionrstriprstrip!scanscrubscrub!setbytesizesliceslice!splitsqueezesqueeze!strip!subsub!succsucc!sumswapcaseswapcase!to_cto_fto_ito_rto_strto_symtr_str_s!tr!undumpunicode_normalizeunicode_normalize!unicode_normalized?unpackunpack1upcase!uptovalid_encoding?
Explicit non-goals (18)
-
bRuby's binary-string clone helper adds little value in JS. -
byteindexByte-oriented string APIs do not fit Locutus' current plain-value model. -
byterindexByte-oriented string APIs do not fit Locutus' current plain-value model. -
bytesByte-oriented string APIs do not fit Locutus' current plain-value model. -
bytesizeByte-oriented string APIs do not fit Locutus' current plain-value model. -
bytesliceByte-oriented string APIs do not fit Locutus' current plain-value model. -
bytespliceByte-oriented string APIs do not fit Locutus' current plain-value model. -
cryptPassword-hash wrappers are security-sensitive and not a good Locutus target. -
each_byteEnumerator-driven iteration APIs are better expressed directly in JS. -
each_charEnumerator-driven iteration APIs are better expressed directly in JS. -
each_codepointEnumerator-driven iteration APIs are better expressed directly in JS. -
each_grapheme_clusterEnumerator-driven iteration APIs are better expressed directly in JS. -
each_lineEnumerator-driven iteration APIs are better expressed directly in JS. -
encodeEncoding-object semantics do not fit Locutus' plain-value model. -
encode!Encoding-object semantics do not fit Locutus' plain-value model. -
encodingEncoding objects are not a stable plain-value target. -
force_encodingEncoding mutation does not fit Locutus' plain-value model. -
internSymbol-table interning does not fit Locutus' plain-value model.
Shipped (14)
Next
Most Ruby Array methods map naturally onto JS arrays and plain objects.
-[][]=*&+<<|all?any?appendassocatchunkchunk_whileclearcollectcollect_concatcollect!combinationcompact!concatcountcycledeconstructdeletedelete_atdelete_ifdetectdifferencedigdropdrop_whileempty?entriesfetchfillfilterfilter!findfind_allfind_indexflat_mapflatten!grepgrep_vinclude?indexinjectinsertintersect?intersectionjoinkeep_iflengthmapmap!maxmax_bymember?minmin_byminmaxminmax_bynone?one?partitionpopprependproductpushrassocreducerejectreject!repeated_combinationrepeated_permutationreplacereversereverse_eachreverse!rindexrotaterotate!selectselect!shiftshuffleshuffle!sizesliceslice_afterslice_beforeslice!sortsort_bysort_by!sort!sumtaketake_whileto_ato_aryto_htransposeunionuniq!unshiftvalues_at
Explicit non-goals (11)
-
chainLazy enumerator chaining is not a stable plain-value target. -
eachEnumerator-driven iteration APIs are better expressed directly in JS. -
each_consEnumerator-driven iteration APIs are better expressed directly in JS. -
each_entryEnumerator-driven iteration APIs are better expressed directly in JS. -
each_indexEnumerator-driven iteration APIs are better expressed directly in JS. -
each_sliceEnumerator-driven iteration APIs are better expressed directly in JS. -
each_with_indexEnumerator-driven iteration APIs are better expressed directly in JS. -
each_with_objectEnumerator-driven iteration APIs are better expressed directly in JS. -
lazyLazy enumerators do not fit Locutus' plain-value model. -
packBinary packing semantics do not map cleanly to JS plain values. -
to_setRuby Set values are not a stable plain-value target for Locutus.
Hash instance methods
Next
Hash readers and pure transforms often map cleanly onto JS objects and entry arrays.
[][]=<<=>>=all?any?assocchunkchunk_whilecollectcollect_concatcompactcountcycledeconstruct_keysdetectdigdropdrop_whileempty?entriesexceptfetchfetch_valuesfilterfilter_mapfindfind_allfind_indexfirstflat_mapflattengrepgrep_vgroup_byhas_key?has_value?include?injectinvertkeykey?keyslengthmapmaxmax_bymember?mergeminmin_byminmaxminmax_bynone?one?partitionrassocreducerejectreverse_eachselectsizesliceslice_afterslice_beforeslice_whensortsort_bysumtaketake_whiletallyto_ato_hto_hashto_proctransform_keystransform_valuesuniqupdatevalue?valuesvalues_atzip
Explicit non-goals (33)
-
chainLazy enumerator chaining is not a stable plain-value target. -
clearHash mutation is outside Locutus' value-only model. -
compact!Bang methods mutate caller-owned hash state. -
compare_by_identityIdentity-based key semantics do not match plain JS object behavior. -
compare_by_identity?Identity-based key semantics do not match plain JS object behavior. -
defaultDefault-proc semantics depend on mutable hash behavior and callable state. -
default_procDefault-proc semantics depend on callable runtime state. -
default_proc=Changing hash defaults mutates caller-owned state. -
default=Changing hash defaults mutates caller-owned state. -
deleteHash mutation is outside Locutus' value-only model. -
delete_ifHash mutation is outside Locutus' value-only model. -
eachEnumerator-driven iteration APIs are better expressed directly in JS. -
each_consEnumerator-driven iteration APIs are better expressed directly in JS. -
each_entryEnumerator-driven iteration APIs are better expressed directly in JS. -
each_keyEnumerator-driven iteration APIs are better expressed directly in JS. -
each_pairEnumerator-driven iteration APIs are better expressed directly in JS. -
each_sliceEnumerator-driven iteration APIs are better expressed directly in JS. -
each_valueEnumerator-driven iteration APIs are better expressed directly in JS. -
each_with_indexEnumerator-driven iteration APIs are better expressed directly in JS. -
each_with_objectEnumerator-driven iteration APIs are better expressed directly in JS. -
filter!Bang methods mutate caller-owned hash state. -
keep_ifHash mutation is outside Locutus' value-only model. -
lazyLazy enumerators do not fit Locutus' plain-value model. -
merge!Bang methods mutate caller-owned hash state. -
rehashHash rehashing depends on Ruby's mutable identity semantics. -
reject!Bang methods mutate caller-owned hash state. -
replaceHash mutation is outside Locutus' value-only model. -
select!Bang methods mutate caller-owned hash state. -
shiftHash mutation is outside Locutus' value-only model. -
storeHash mutation is outside Locutus' value-only model. -
to_setRuby Set values are not a stable plain-value target for Locutus. -
transform_keys!Bang methods mutate caller-owned hash state. -
transform_values!Bang methods mutate caller-owned hash state.
Integer instance methods
Next
Ruby Integer helpers are strong scalar portability targets.
--@[]***/&%^++@<<<<=>>=>>|~absabs2allbits?angleanybits?argbetween?bit_lengthceilceildivchrclampcoerceconjconjugatedenominatordigitsdivdivmodeven?fdivfinite?floorgcdgcdlcmiimagimaginaryinfinite?integer?lcmmagnitudemodulonegative?nextnobits?nonzero?numeratorodd?ordphasepolarpositive?powpredquorationalizerealreal?rectrectangularremainderroundsingleton_method_addedsizestepsuccto_cto_fto_ito_inttruncatezero?
Explicit non-goals (4)
-
downtoEnumerator-style integer iteration does not fit Locutus' plain-value model. -
timesEnumerator-style integer iteration does not fit Locutus' plain-value model. -
to_rRational values do not fit Locutus' current plain-value model. -
uptoEnumerator-style integer iteration does not fit Locutus' plain-value model.
Float instance methods
Next
Ruby Float helpers are strong scalar portability targets.
--@***/%++@<<=>>=absabs2angleargbetween?ceilclampcoerceconjconjugatedenominatordivdivmodfdivfinite?flooriimagimaginaryinfinite?integer?magnitudemodulonan?negative?next_floatnonzero?numeratorphasepolarpositive?prev_floatquorationalizerealreal?rectrectangularremainderroundsingleton_method_addedstepto_cto_fto_ito_inttruncatezero?
Explicit non-goals (1)
-
to_rRational values do not fit Locutus' current plain-value model.
Enumerable instance methods
Next
Most Enumerable transforms can be represented over arrays and plain values.
all?any?chunkchunk_whilecollectcollect_concatcompactcountdetectdropdrop_whileentriesfilterfilter_mapfindfind_allfind_indexfirstflat_mapgrepgrep_vgroup_byinclude?injectmapmaxmax_bymember?minmin_byminmaxminmax_bynone?one?partitionreducerejectreverse_eachselectslice_afterslice_beforeslice_whensortsort_bysumtaketake_whiletallyto_ato_huniqzip
Explicit non-goals (9)
-
chainLazy enumerator chaining is not a stable plain-value target. -
cyclePotentially unbounded iteration does not fit Locutus' plain-value model. -
each_consEnumerator-driven iteration APIs are better expressed directly in JS. -
each_entryEnumerator-driven iteration APIs are better expressed directly in JS. -
each_sliceEnumerator-driven iteration APIs are better expressed directly in JS. -
each_with_indexEnumerator-driven iteration APIs are better expressed directly in JS. -
each_with_objectEnumerator-driven iteration APIs are better expressed directly in JS. -
lazyLazy enumerators do not fit Locutus' plain-value model. -
to_setRuby Set values are not a stable plain-value target for Locutus.
Numeric instance methods
Next
Scalar numeric helpers are strong Ruby portability targets.
-@%+@<=>absabs2angleargceilclonecoerceconjconjugatedenominatordivdivmoddupeql?fdivfinite?flooriimagimaginaryinfinite?integer?magnitudemodulonegative?nonzero?numeratorphasepolarpositive?quorealreal?rectrectangularremainderroundsingleton_method_addedstepto_cto_inttruncatezero?
MatchData instance methods
Next
Match boundary offsets have a clean plain-value contract.
beginendoffset
Capture extraction has a clean plain-value contract.
captures
Match-size helpers have a clean plain-value contract.
length
Capture-name enumeration has a clean plain-value contract.
names
Plain substring extraction has a clean plain-value contract.
post_matchpre_match
Source-string access has a clean plain-value contract.
string
Capture materialization has a clean plain-value contract.
to_a
Explicit non-goals (10)
-
[]Match objects depend on richer regex-engine state than one stable plain-value contract. -
byteoffsetMatch objects depend on richer regex-engine state than one stable plain-value contract. -
deconstructMatch objects depend on richer regex-engine state than one stable plain-value contract. -
deconstruct_keysMatch objects depend on richer regex-engine state than one stable plain-value contract. -
matchMatch objects depend on richer regex-engine state than one stable plain-value contract. -
match_lengthMatch objects depend on richer regex-engine state than one stable plain-value contract. -
named_capturesMatch objects depend on richer regex-engine state than one stable plain-value contract. -
regexpRegex-object access does not fit one stable plain-value contract. -
sizeMatch objects depend on richer regex-engine state than one stable plain-value contract. -
values_atMatch objects depend on richer regex-engine state than one stable plain-value contract.
Range instance methods
Next
Scalar boundary readers have a clean plain-value contract.
beginend
Membership predicates have a clean plain-value contract.
cover?include?
Boundary readers have a clean plain-value contract.
firstlast
Scalar extrema readers have a clean plain-value contract.
maxminminmax
Size helpers have a clean plain-value contract.
size
Explicit non-goals (62)
-
%Range iteration and object semantics do not map cleanly to plain JS values by default. -
all?Range iteration and object semantics do not map cleanly to plain JS values by default. -
any?Range iteration and object semantics do not map cleanly to plain JS values by default. -
bsearchRange iteration and object semantics do not map cleanly to plain JS values by default. -
chainRange iteration and object semantics do not map cleanly to plain JS values by default. -
chunkRange iteration and object semantics do not map cleanly to plain JS values by default. -
chunk_whileRange iteration and object semantics do not map cleanly to plain JS values by default. -
collectRange iteration and object semantics do not map cleanly to plain JS values by default. -
collect_concatRange iteration and object semantics do not map cleanly to plain JS values by default. -
compactRange iteration and object semantics do not map cleanly to plain JS values by default. -
countRange iteration and object semantics do not map cleanly to plain JS values by default. -
cycleRange iteration and object semantics do not map cleanly to plain JS values by default. -
detectRange iteration and object semantics do not map cleanly to plain JS values by default. -
dropRange iteration and object semantics do not map cleanly to plain JS values by default. -
drop_whileRange iteration and object semantics do not map cleanly to plain JS values by default. -
eachRange iteration and object semantics do not map cleanly to plain JS values by default. -
each_consRange iteration and object semantics do not map cleanly to plain JS values by default. -
each_entryRange iteration and object semantics do not map cleanly to plain JS values by default. -
each_sliceRange iteration and object semantics do not map cleanly to plain JS values by default. -
each_with_indexRange iteration and object semantics do not map cleanly to plain JS values by default. -
each_with_objectRange iteration and object semantics do not map cleanly to plain JS values by default. -
entriesRange iteration and object semantics do not map cleanly to plain JS values by default. -
exclude_end?Range iteration and object semantics do not map cleanly to plain JS values by default. -
filterRange iteration and object semantics do not map cleanly to plain JS values by default. -
filter_mapRange iteration and object semantics do not map cleanly to plain JS values by default. -
findRange iteration and object semantics do not map cleanly to plain JS values by default. -
find_allRange iteration and object semantics do not map cleanly to plain JS values by default. -
find_indexRange iteration and object semantics do not map cleanly to plain JS values by default. -
flat_mapRange iteration and object semantics do not map cleanly to plain JS values by default. -
grepRange iteration and object semantics do not map cleanly to plain JS values by default. -
grep_vRange iteration and object semantics do not map cleanly to plain JS values by default. -
group_byRange iteration and object semantics do not map cleanly to plain JS values by default. -
injectRange iteration and object semantics do not map cleanly to plain JS values by default. -
lazyRange iteration and object semantics do not map cleanly to plain JS values by default. -
mapRange iteration and object semantics do not map cleanly to plain JS values by default. -
max_byRange iteration and object semantics do not map cleanly to plain JS values by default. -
member?Range iteration and object semantics do not map cleanly to plain JS values by default. -
min_byRange iteration and object semantics do not map cleanly to plain JS values by default. -
minmax_byRange iteration and object semantics do not map cleanly to plain JS values by default. -
none?Range iteration and object semantics do not map cleanly to plain JS values by default. -
one?Range iteration and object semantics do not map cleanly to plain JS values by default. -
overlap?Range iteration and object semantics do not map cleanly to plain JS values by default. -
partitionRange iteration and object semantics do not map cleanly to plain JS values by default. -
reduceRange iteration and object semantics do not map cleanly to plain JS values by default. -
rejectRange iteration and object semantics do not map cleanly to plain JS values by default. -
reverse_eachRange iteration and object semantics do not map cleanly to plain JS values by default. -
selectRange iteration and object semantics do not map cleanly to plain JS values by default. -
slice_afterRange iteration and object semantics do not map cleanly to plain JS values by default. -
slice_beforeRange iteration and object semantics do not map cleanly to plain JS values by default. -
slice_whenRange iteration and object semantics do not map cleanly to plain JS values by default. -
sortRange iteration and object semantics do not map cleanly to plain JS values by default. -
sort_byRange iteration and object semantics do not map cleanly to plain JS values by default. -
stepRange iteration and object semantics do not map cleanly to plain JS values by default. -
sumRange iteration and object semantics do not map cleanly to plain JS values by default. -
takeRange iteration and object semantics do not map cleanly to plain JS values by default. -
take_whileRange iteration and object semantics do not map cleanly to plain JS values by default. -
tallyRange iteration and object semantics do not map cleanly to plain JS values by default. -
to_aRange iteration and object semantics do not map cleanly to plain JS values by default. -
to_hRange iteration and object semantics do not map cleanly to plain JS values by default. -
to_setRange iteration and object semantics do not map cleanly to plain JS values by default. -
uniqRange iteration and object semantics do not map cleanly to plain JS values by default. -
zipRange iteration and object semantics do not map cleanly to plain JS values by default.
Comparable instance methods
Next
Comparable predicates over scalar values are strong Ruby portability targets.
<<===>>=between?clamp
File singleton methods
Next
Path decomposition helpers have a clean plain-string contract.
basenamedirnameextname
Path joining has a clean plain-string contract.
join
Path composition has a clean plain-string contract.
path
Explicit non-goals (56)
-
absolute_pathFile metadata and I/O helpers depend on host filesystem state. -
absolute_path?File metadata and I/O helpers depend on host filesystem state. -
atimeFile metadata and I/O helpers depend on host filesystem state. -
birthtimeFile metadata and I/O helpers depend on host filesystem state. -
blockdev?File metadata and I/O helpers depend on host filesystem state. -
chardev?File metadata and I/O helpers depend on host filesystem state. -
chmodFile metadata and I/O helpers depend on host filesystem state. -
chownFile metadata and I/O helpers depend on host filesystem state. -
ctimeFile metadata and I/O helpers depend on host filesystem state. -
deleteFile metadata and I/O helpers depend on host filesystem state. -
directory?File metadata and I/O helpers depend on host filesystem state. -
empty?File metadata and I/O helpers depend on host filesystem state. -
executable_real?File metadata and I/O helpers depend on host filesystem state. -
executable?File metadata and I/O helpers depend on host filesystem state. -
exist?File metadata and I/O helpers depend on host filesystem state. -
expand_pathFile metadata and I/O helpers depend on host filesystem state. -
file?File metadata and I/O helpers depend on host filesystem state. -
fnmatchFile metadata and I/O helpers depend on host filesystem state. -
fnmatch?File metadata and I/O helpers depend on host filesystem state. -
ftypeFile metadata and I/O helpers depend on host filesystem state. -
grpowned?File metadata and I/O helpers depend on host filesystem state. -
identical?File metadata and I/O helpers depend on host filesystem state. -
lchmodFile metadata and I/O helpers depend on host filesystem state. -
lchownFile metadata and I/O helpers depend on host filesystem state. -
linkFile metadata and I/O helpers depend on host filesystem state. -
lstatFile metadata and I/O helpers depend on host filesystem state. -
lutimeFile metadata and I/O helpers depend on host filesystem state. -
mkfifoFile metadata and I/O helpers depend on host filesystem state. -
mtimeFile metadata and I/O helpers depend on host filesystem state. -
owned?File metadata and I/O helpers depend on host filesystem state. -
pipe?File metadata and I/O helpers depend on host filesystem state. -
readable_real?File metadata and I/O helpers depend on host filesystem state. -
readable?File metadata and I/O helpers depend on host filesystem state. -
readlinkFile metadata and I/O helpers depend on host filesystem state. -
realdirpathFile metadata and I/O helpers depend on host filesystem state. -
realpathFile metadata and I/O helpers depend on host filesystem state. -
renameFile metadata and I/O helpers depend on host filesystem state. -
setgid?File metadata and I/O helpers depend on host filesystem state. -
setuid?File metadata and I/O helpers depend on host filesystem state. -
sizeFile metadata and I/O helpers depend on host filesystem state. -
size?File metadata and I/O helpers depend on host filesystem state. -
socket?File metadata and I/O helpers depend on host filesystem state. -
splitFile metadata and I/O helpers depend on host filesystem state. -
statFile metadata and I/O helpers depend on host filesystem state. -
sticky?File metadata and I/O helpers depend on host filesystem state. -
symlinkFile metadata and I/O helpers depend on host filesystem state. -
symlink?File metadata and I/O helpers depend on host filesystem state. -
truncateFile metadata and I/O helpers depend on host filesystem state. -
umaskFile metadata and I/O helpers depend on host filesystem state. -
unlinkFile metadata and I/O helpers depend on host filesystem state. -
utimeFile metadata and I/O helpers depend on host filesystem state. -
world_readable?File metadata and I/O helpers depend on host filesystem state. -
world_writable?File metadata and I/O helpers depend on host filesystem state. -
writable_real?File metadata and I/O helpers depend on host filesystem state. -
writable?File metadata and I/O helpers depend on host filesystem state. -
zero?File metadata and I/O helpers depend on host filesystem state.
Regexp instance methods
Next
Pattern-source readers have a clean plain-value contract.
source
Explicit non-goals (11)
-
=~Match-data- and engine-oriented regex object APIs are not direct plain-value targets. -
~Match-data- and engine-oriented regex object APIs are not direct plain-value targets. -
casefold?Match-data- and engine-oriented regex object APIs are not direct plain-value targets. -
encodingMatch-data- and engine-oriented regex object APIs are not direct plain-value targets. -
fixed_encoding?Match-data- and engine-oriented regex object APIs are not direct plain-value targets. -
matchMatch-data- and engine-oriented regex object APIs are not direct plain-value targets. -
match?Match-data- and engine-oriented regex object APIs are not direct plain-value targets. -
named_capturesMatch-data- and engine-oriented regex object APIs are not direct plain-value targets. -
namesMatch-data- and engine-oriented regex object APIs are not direct plain-value targets. -
optionsMatch-data- and engine-oriented regex object APIs are not direct plain-value targets. -
timeoutMatch-data- and engine-oriented regex object APIs are not direct plain-value targets.