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
-
Starting today, you can install
[email protected]
from 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
cloneDeep
function → PR #81The
cloneDeep
function creates a deep copy of an object or array.Map
instances, andSet
instances by default.CloningStrategy
implementation.🔗 Docs / Source / Tests
Add
once
function → 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
castArrayIfExists
function 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
castArray
function ensures that the input value is always returned as an array.🔗 Docs / Source / Tests
Convert an array to a map → PR #58
The
mapify
function allows you to convert an array into aMap
object, where the keys and values are determined by provided functions.🔗 Docs / Source / Tests
Round a number to a specified precision → PR #53
The
round
function allows you to round a number to a specified precision.Math.floor
orMath.ceil
) can be provided. The default rounding function isMath.round
.🔗 Docs / Source / Tests
Allow deep traversal of objects and arrays → PR #59
The
traverse
function recursively visits each property of an object (or each element of an array) and its nested objects or arrays.TraverseOptions
object.🔗 Docs / Source / Tests
Calculate string similarity → PR #122
The
similarity
function 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
castComparator
function allows you to create a comparator function that can be passed intoArray.prototype.sort
.Parameters:
mapping
is either a property name or a mapping function.compare
is an optional custom compare function (e.g. forlocaleCompare
use cases).reverse
reverses 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
castMapping
to 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
clamp
function restricts a number to be within a specified range.Parameters:
value
is the number to clamp.min
is the minimum value (inclusive).max
is the maximum value (inclusive).🔗 Docs / Source / Tests
Add
unzip
function → PR #64The
unzip
function 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
filterKey
to retrieve a filtering function. The returned function expects an object and a key, and returnstrue
if 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
isPlainObject
function 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
Result
tuple → PR #172New functions have been added to help work with "Result" tuples, which represent the success or failure of a
tryit
call.isResult
checks if a value is a Result tuple.isResultOk
checks if a Result tuple represents a successful operation.isResultErr
checks 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
isIntString
function returnstrue
if the input is a string that represents an integer.🔗 Docs / Source / Tests
Check for an error → PR #173
The
isError
function returnstrue
for objects that inherit fromError
.🔗 Docs / Source / Tests
Check for a boolean → commit adc419d
The
isBoolean
function returnstrue
for 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
isRegExp
function returnstrue
forRegExp
instances, even if they are subclass instances or from other realms.🔗 Docs / Source / Tests
Check for a Set object → PR #77
The
isSet
function returnstrue
forSet
instances, even if they are subclass instances or from other realms.🔗 Docs / Source / Tests
Check for a Map object → PR #77
The
isMap
function returnstrue
forMap
instances, even if they are subclass instances or from other realms.🔗 Docs / Source / Tests
Check for a WeakMap object → PR #77
The
isWeakMap
andisWeakSet
functions returntrue
forWeakMap
andWeakSet
instances, 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
lerp
function 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
noop
function 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
always
function 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
flip
function 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
debounce
function to run immediately → PR #128The
debounce
function now accepts aleading
option. When true, the source function is called immediately on the first invocation of the debounced function, and subsequent calls will be debounced.Add
trigger
method tothrottle
function → PR #135The
throttle
function now includes atrigger
method on the returned throttled function. This allows the wrapped function to be invoked immediately, bypassing any throttling that may be in effect. After thetrigger
method 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
trailing
option tothrottle
function → PR #127The
throttle
function now accepts an optionaltrailing
option, 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
mapify
callbacks → PR #100The
mapify
function now provides anindex
argument to thegetKey
andgetValue
callbacks. 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
castComparator
function now accepts an optionalreverse
argument that, whentrue
, will reverse the order of the comparison.Allow
pick
function to accept a callback for advanced picking → PR #30The
pick
function can also accept a predicate function as the filter argument. This allows for more complex filtering logic beyond simple key inclusion or exclusion.Let
select
function work without a condition callback → PR #9The
select
function now allows you to omit thecondition
callback parameter. When thecondition
parameter is not provided, any nullish values returned by your mapping function will be filtered out.Allow keys of any type in the
unique
function → PR #10The
unique
function now supports any value as the key for identifying unique items in the array, not just strings, numbers, or symbols. ThetoKey
callback argument can return any kind of value.Allow keys of any type in the
intersects
function → PR #11The
intersects
function now allows theidentity
callback argument to return any value, instead of just a string, number, or symbol.As a result, you can now omit the
identity
callback for arrays of objects.Bug Fixes
Fix camel-cased to pascal-cased string conversion → PR #178
The
pascal
function 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
toggle
function has been updated to pass an index of-1
when calling thetoKey
function with theitem
to be toggled. This ensures that thetoKey
function can correctly identify the item, even if it doesn't exist in the array.Previously, the
toKey
function 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
crush
function 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
assign
function has been updated to correctly handle the case where a nested object is being overridden with anull
value. Previously, the function would incorrectly preserve the nested object, even when the override value wasnull
.Handle falsy input as expected in
toggle
→ PR #82The
toggle
function now handles falsy input more consistently. Previously, a falsyitem
argument would be ignored, neither added nor removed from the array. Now, this only happens forundefined
values. As such, you should still avoid havingundefined
in your array when usingtoggle
with it (since it still can't be removed bytoggle
).toInt
andtoFloat
should not throw on symbols → PR #67The
toInt
andtoFloat
functions now handle symbols more gracefully. Instead of throwing an error, they will returnNaN
if the input value is a symbol, and fall back to the provided default value if one is specified.Use
typeof
inisFunction
→ commit 6ad96f4The
isFunction
utility now uses thetypeof
operator 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 withcall
andapply
properties would be falsely identified as a function.Avoid using
isObject
internally and useisPlainObject
instead → PR #18The internal use of
isObject
has been replaced withisPlainObject
to 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
set
function → PR #15The
set
function has been improved to correctly handle keys that start with numbers. It now uses theisIntString
function to detect if a key should be treated as an array index.Other Improvements
Performance
for
loop instead ofArray.fill().map()
→ PR #63for
loop and direct array updates instead ofreduce()
→ PR #33key
generator more than once per item and avoid the use of an arrow function in the loop. → PR #60for
loop and individual object property assignments instead → PR #37while
loop 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 thememo
function. → commit 877a1e4TryitResult<T>
type which represents the return type of thetryit
function. → commit f044364UppercaseKeys
andLowercaseKeys
types from thelowerize
andupperize
functions respectively. → commit 96b28b9FilteredKeys
type that extracts the keys of an object that pass a given filter. → commit 6a6f899Assign
type to represent the return type of theassign
function. → PR #142Type Fixes
assign
return type more accurate. → PR #142group
's return type is compatible withmapValues
's function type. → PR #24isArray
work withreadonly
array types. → commit 88c12b6isArray
return type forunknown
input type. → PR #72isArray
return type. → commit 9257535isPromise
return type with its logic. → PR #175keys
argument to be a readonly array. → PR #272select
function more option-friendly by acceptingnull
orundefined
for thecondition
argument. → commit c9cfcd0items
argument to be a readonly array → PR #14Omit
on return type and givefilter
argument a safer type → PR #12shift
function to accept a readonly array type. → PR #126sum
. → PR #143zip
to 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