Repository navigation
@knitkode/utils@3.0.1
·
1 commit
to main
since this release
Patch Changes
-
113cd75Thanks @kuus! - Fix several helpers:isExternalUrlcompares against the givencurrentUrl(it used to always fall back tolocation.href) and works outside the browser. It only matches URLs starting withhttp(s)://, compares hosts case-insensitively and supports hosts without a dot such aslocalhost.isServerNowandisBrowserNowno longer throw wherewindowis not declared, like in Node.js.roundrounds whendecimalsis falsy (round(1.7)is2, it used to truncate to1). WithtrailingZeroesit returns the formatted string (round(1.2, 2, true)is"1.20"), the only way to keep the zeroes.ensureInttruncates numbers like it already did with strings (ensureInt(1.9)is1, it used to round to2). Non numeric input givesNaN.slugifyreplaces underscores and the other punctuation with the separator (slugify("foo_bar")is"foo-bar").removeAccentskeeps the case of the replaced letters ("École"gives"Ecole", it used to give"ecole").titleCasecapitalises words starting with any letter ("élan vital"gives"Élan Vital").isFloat(Infinity)isfalse.- The
Splittype matches the runtime for empty strings and trailing delimiters (split("a,", ",")is typed["a", ""]). encodeencodes line breaks and characters from code point 1000 up (€, CJK, emoji), which it used to corrupt, anddecodereverses them. The output of the other characters is unchanged, anddecodestill reads values encoded by previous versions.
-
89e3ba6Thanks @kuus! - Fix more helpers:throttlepasses its arguments to the throttled function (it used to throw or drop them), which also fixes the throttled listeners of@knitkode/dom.- Cookies:
setCookieapplies the defaultpath=/and writesexpires(days orDate) correctly, soremoveCookiereally removes the cookie.setCookieno longer throws wheredocumentis not declared. getNoncereturnsnullinstead of throwing where__webpack_nonce__is not declared.objectFlatkeepsnullvalues instead of throwing,objectMergeWithDefaultsno longer mutates the defaults and appliesdeleteIfNullto nested objects,objectSortByKeysMatchingalways puts the matching key first.removeDuplicatesByKeycompares values withSameValueZero(1and"1"are different, keys like"toString"are kept).chunkByChunksreturns the requested number of chunks in unbalanced mode,chunkBySizewith a size below 1 returns the whole array (it used to loop forever).createPalettekeeps the order of the given shades.- URLs:
buildUrlQueryStringencodes the keys too,getUrlQueryParamsignores the hash and decodes the keys,getUrlHashPathnamestrips the#and the leading slashes,getParamAsIntreturns the fallback for non numeric values,parseURLreturnsnullfor invalid ports. debouncePromisewithisImmediatesettles the promises of the calls made during the wait, with the immediate call result.invariantis typed as an assertion and its messages follow the documented[lib:prefix]: messageformat ("Invariant failed"without a message).- Types:
Defer()type-checks as documented andDeferredhas itspromise,ArrayOfAllresolves to"Incomplete"for incomplete lists.
-
b131ad6Thanks @kuus! - ExportchangeCaseCapital,changeCaseNone,changeCasePascalSnake,removeDuplicatesandrenderfrom the package root. They were only available from their own subpaths (e.g.@knitkode/utils/render), which still work.