v12.2.0 – Radashi's first stable release #285
aleclarson
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Starting today, you can install
radashi@12.2.0from NPM. This is the first stable release of Radashi, which we've been incubating for more than 4 months, starting on June 23.Now, we look forward to merging more pull requests, attracting more contributors, and inspiring more talented folks to join us in building (and just as important, maintaining) the next-generation utility toolkit that is Radashi.
Lastly, I'd like to ask everyone to check out the proposed features open for discussion, and we hope you'll share with us any ideas you may have as well. Remember, this is a community effort. Your perspective is valuable and it will help us make Radashi better with your needs in mind.
New Functions
Add
cloneDeepfunction → PR #81The
cloneDeepfunction creates a deep copy of an object or array.Mapinstances, andSetinstances by default.CloningStrategyimplementation.🔗 Docs / Source / Tests
Add
oncefunction → PR #80Create a wrapper around a given function such that it executes at most once.
_.once.reset(fn)to clear the stored result and allow the function to execute again.🔗 Docs / Source / Tests
Cast a non-nullish value into an array → PR #97
The
castArrayIfExistsfunction ensures that a non-nullish input value is always returned as an array.🔗 Docs / Source / Tests
Cast a value into an array → PR #97
The
castArrayfunction ensures that the input value is always returned as an array.🔗 Docs / Source / Tests
Convert an array to a map → PR #58
The
mapifyfunction allows you to convert an array into aMapobject, where the keys and values are determined by provided functions.🔗 Docs / Source / Tests
Round a number to a specified precision → PR #53
The
roundfunction allows you to round a number to a specified precision.Math.floororMath.ceil) can be provided. The default rounding function isMath.round.🔗 Docs / Source / Tests
Allow deep traversal of objects and arrays → PR #59
The
traversefunction recursively visits each property of an object (or each element of an array) and its nested objects or arrays.TraverseOptionsobject.🔗 Docs / Source / Tests
Calculate string similarity → PR #122
The
similarityfunction calculates the Levenshtein distance between two input strings, which represents the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other.🔗 Docs / Source / Tests
Cast a value into a comparator function → PR #34
The
castComparatorfunction allows you to create a comparator function that can be passed intoArray.prototype.sort.Parameters:
mappingis either a property name or a mapping function.compareis an optional custom compare function (e.g. forlocaleCompareuse cases).reversereverses the comparison order if set totrue.🔗 Docs / Source / Tests
Cast a value into a mapping function → PR #43
Improve your own utility function by adding a flexible value-mapping option, using
castMappingto retrieve a mapping function.The following types can be casted into a mapping function:
🔗 Docs / Source / Tests
Limit the range of a variable number → PR #106
The
clampfunction restricts a number to be within a specified range.Parameters:
valueis the number to clamp.minis the minimum value (inclusive).maxis the maximum value (inclusive).🔗 Docs / Source / Tests
Add
unzipfunction → PR #64The
unzipfunction creates an array of ungrouped elements, where each resulting array contains all elements at a specific index from the input arrays. It's the functional opposite ofzip.🔗 Docs / Source / Tests
Allow filtering of object keys → PR #28
Improve your own utility function by adding a flexible key-filtering option, using
filterKeyto retrieve a filtering function. The returned function expects an object and a key, and returnstrueif the key passes the filter.The following types can be casted into a filtering function:
true.🔗 Docs / Source / Tests
Check for a plain object → PR #16
The
isPlainObjectfunction can be used to determine if a value is a plain object, as opposed to an instance of a custom class or a special object likeDate.🔗 Docs / Source / Tests
Check for a
Resulttuple → PR #172New functions have been added to help work with "Result" tuples, which represent the success or failure of a
tryitcall.isResultchecks if a value is a Result tuple.isResultOkchecks if a Result tuple represents a successful operation.isResultErrchecks if a Result tuple represents a failed operation.🔗 isResult Docs / Source / Tests
🔗 isResultOk Docs / Source / Tests
🔗 isResultErr Docs / Source / Tests
Check for an integer string → commit fa500d3
The
isIntStringfunction returnstrueif the input is a string that represents an integer.🔗 Docs / Source / Tests
Check for an error → PR #173
The
isErrorfunction returnstruefor objects that inherit fromError.🔗 Docs / Source / Tests
Check for a boolean → commit adc419d
The
isBooleanfunction returnstruefor boolean primitives. Boxed boolean values (e.g.new Boolean(false)) are not considered booleans by this function.🔗 Docs / Source / Tests
Check for a RegExp object → PR #77
The
isRegExpfunction returnstrueforRegExpinstances, even if they are subclass instances or from other realms.🔗 Docs / Source / Tests
Check for a Set object → PR #77
The
isSetfunction returnstrueforSetinstances, even if they are subclass instances or from other realms.🔗 Docs / Source / Tests
Check for a Map object → PR #77
The
isMapfunction returnstrueforMapinstances, even if they are subclass instances or from other realms.🔗 Docs / Source / Tests
Check for a WeakMap object → PR #77
The
isWeakMapandisWeakSetfunctions returntrueforWeakMapandWeakSetinstances, respectively, even if they are subclass instances or from other realms.🔗 isWeakMap Docs / Source / Tests
🔗 isWeakSet Docs / Source / Tests
Interpolate between two numbers → PR #86
The
lerpfunction is used to linearly interpolate between two numbers based on a specified ratio between 0 and 1. For example, a ratio of 0.5 would return the number exactly halfway between the two input numbers.🔗 Docs / Source / Tests
noop and always → commit eb77c8f
The
noopfunction is a callback that does nothing and returnsundefined.You don't call this directly. It's often useful in default parameters or destructuring to ensure a callback is defined.
The
alwaysfunction creates a function that always returns the same value. This can be useful for providing a constant value as a callback. Note that the following example is overkill (for constant values, use an arrow function instead), but it demonstrates the concept:🔗 noop Docs / Source / Tests
🔗 always Docs / Source / Tests
Flip the arguments of a function → PR #35
The
flipfunction returns a new function that swaps the first two arguments of the original function.This is most useful for reversing the order of a "comparator" (i.e. a function used for sorting), which effectively reverses the sort order.
🔗 Docs / Source / Tests
New Features
Allow
debouncefunction to run immediately → PR #128The
debouncefunction now accepts aleadingoption. When true, the source function is called immediately on the first invocation of the debounced function, and subsequent calls will be debounced.Add
triggermethod tothrottlefunction → PR #135The
throttlefunction now includes atriggermethod on the returned throttled function. This allows the wrapped function to be invoked immediately, bypassing any throttling that may be in effect. After thetriggermethod is called, a new throttled call will be allowed after the specified interval has passed.This can be useful when you want to ensure a function is called at least once, even if it's being throttled.
Add
trailingoption tothrottlefunction → PR #127The
throttlefunction now accepts an optionaltrailingoption, which controls whether the wrapped function should be called after the throttle period if it was invoked during the throttled time.This can be useful when you want to ensure the function is called at the end of a series of rapid invocations, even if it's being throttled.
Provide index to
mapifycallbacks → PR #100The
mapifyfunction now provides anindexargument to thegetKeyandgetValuecallbacks. This allows you to base the key or value on the current index of the array item, in addition to the item itself.Add reversible
castComparator→ commit 1d7937eThe
castComparatorfunction now accepts an optionalreverseargument that, whentrue, will reverse the order of the comparison.Allow
pickfunction to accept a callback for advanced picking → PR #30The
pickfunction can also accept a predicate function as the filter argument. This allows for more complex filtering logic beyond simple key inclusion or exclusion.Let
selectfunction work without a condition callback → PR #9The
selectfunction now allows you to omit theconditioncallback parameter. When theconditionparameter is not provided, any nullish values returned by your mapping function will be filtered out.Allow keys of any type in the
uniquefunction → PR #10The
uniquefunction now supports any value as the key for identifying unique items in the array, not just strings, numbers, or symbols. ThetoKeycallback argument can return any kind of value.Allow keys of any type in the
intersectsfunction → PR #11The
intersectsfunction now allows theidentitycallback argument to return any value, instead of just a string, number, or symbol.As a result, you can now omit the
identitycallback for arrays of objects.Bug Fixes
Fix camel-cased to pascal-cased string conversion → PR #178
The
pascalfunction now correctly handles camel-cased strings, fixing issues with inputs like"helloWorld". It uses a regex to identify word boundaries and preserve existing capitalization.Use -1 as index for
toKey()with toggleditem→ PR #167The
togglefunction has been updated to pass an index of-1when calling thetoKeyfunction with theitemto be toggled. This ensures that thetoKeyfunction can correctly identify the item, even if it doesn't exist in the array.Previously, the
toKeyfunction was called with the current index of the item in the array, which could lead to incorrect behavior if the item didn't exist.Fix handling of period-containing property names → PR #95
The
crushfunction has been updated to correctly handle object properties with periods in their names. Previously, such properties would always have an undefined value in the resulting object.Fix null handling in
assign→ PR #112The
assignfunction has been updated to correctly handle the case where a nested object is being overridden with anullvalue. Previously, the function would incorrectly preserve the nested object, even when the override value wasnull.Handle falsy input as expected in
toggle→ PR #82The
togglefunction now handles falsy input more consistently. Previously, a falsyitemargument would be ignored, neither added nor removed from the array. Now, this only happens forundefinedvalues. As such, you should still avoid havingundefinedin your array when usingtogglewith it (since it still can't be removed bytoggle).toIntandtoFloatshould not throw on symbols → PR #67The
toIntandtoFloatfunctions now handle symbols more gracefully. Instead of throwing an error, they will returnNaNif the input value is a symbol, and fall back to the provided default value if one is specified.Use
typeofinisFunction→ commit 6ad96f4The
isFunctionutility now uses thetypeofoperator instead of duck typing to determine if a value is a function. This ensures the type-guarded value can actually be called like a function, where before an object withcallandapplyproperties would be falsely identified as a function.Avoid using
isObjectinternally and useisPlainObjectinstead → PR #18The internal use of
isObjecthas been replaced withisPlainObjectto ensure that objects created withObject.create(null)are handled correctly. This change improves the consistency and robustness of the library.Avoid false positive of array index in
setfunction → PR #15The
setfunction has been improved to correctly handle keys that start with numbers. It now uses theisIntStringfunction to detect if a key should be treated as an array index.Other Improvements
Performance
forloop instead ofArray.fill().map()→ PR #63forloop and direct array updates instead ofreduce()→ PR #33keygenerator more than once per item and avoid the use of an arrow function in the loop. → PR #60forloop and individual object property assignments instead → PR #37whileloop and string concatenation instead ofArray.from().reduce()→ PR #32Refactoring
range()unnecessarily, reducing the size ofretry. → commit 5d60893Added Types
MemoOptions<T>type which represents the options object passed to thememofunction. → commit 877a1e4TryitResult<T>type which represents the return type of thetryitfunction. → commit f044364UppercaseKeysandLowercaseKeystypes from thelowerizeandupperizefunctions respectively. → commit 96b28b9FilteredKeystype that extracts the keys of an object that pass a given filter. → commit 6a6f899Assigntype to represent the return type of theassignfunction. → PR #142Type Fixes
assignreturn type more accurate. → PR #142group's return type is compatible withmapValues's function type. → PR #24isArraywork withreadonlyarray types. → commit 88c12b6isArrayreturn type forunknowninput type. → PR #72isArrayreturn type. → commit 9257535isPromisereturn type with its logic. → PR #175keysargument to be a readonly array. → PR #272selectfunction more option-friendly by acceptingnullorundefinedfor theconditionargument. → commit c9cfcd0itemsargument to be a readonly array → PR #14Omiton return type and givefilterargument a safer type → PR #12shiftfunction to accept a readonly array type. → PR #126sum. → PR #143zipto accept readonly arrays. → commit f7d93ccThis discussion was created from the release v12.2.0 – Radashi's first stable release.
Beta Was this translation helpful? Give feedback.
All reactions