es-toolkit 1.47.0-dev.1833 → 1.47.0-dev.1835
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.global.js
CHANGED
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
${a?`function print() { __p += Array.prototype.join.call(arguments, ''); }`:``}
|
|
6
6
|
${t.variable?o:`with(obj) {\n${o}\n}`}
|
|
7
7
|
return __p;
|
|
8
|
-
}`,f=_a(()=>Function(...c,`${u}return ${d}`)(...l));if(f.source=d,f instanceof Error)throw f;return f}function Tc(e){return R(e).toLowerCase()}function Ec(e){return R(e).toUpperCase()}function Dc(e,t,n){if(e==null)return``;if(n!=null||t==null)return e.toString().trim();switch(typeof t){case`object`:return Array.isArray(t)?Un(e,t.flatMap(e=>e.toString().split(``))):Un(e,t.toString().split(``));default:return Un(e,t.toString().split(``))}}function Oc(e,t,n){return e==null?``:n!=null||t==null?e.toString().trimEnd():Vn(e,t.toString().split(``))}function kc(e,t,n){return e==null?``:n!=null||t==null?e.toString().trimStart():Hn(e,t.toString().split(``))}let Ac=/[\u200d\ud800-\udfff\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff\ufe0e\ufe0f]/;function jc(e,t){e=e==null?``:`${e}`;let n=30,r=`...`;H(t)&&(n=Mc(t.length),r=`omission`in t?`${t.omission}`:`...`);let i=e.length,a=Array.from(r).length,o=Math.max(n-a,0),s;if(Ac.test(e)&&(s=Array.from(e),i=s.length),n>=i)return e;if(i<=a)return r;let c=s===void 0?e.slice(0,o):s?.slice(0,o).join(``),l=t?.separator;if(!l)return c+=r,c;let u=l instanceof RegExp?l.source:l,d=`u`+(l instanceof RegExp?l.flags.replace(`u`,``):``),f=RegExp(`(?<result>.*(?:(?!${u}).))(?:${u})`,d).exec(c);return(f?.groups?f.groups.result:c)+r}function Mc(e){return e==null?30:e<=0?0:e}function Nc(e){return Gn(R(e))}function Pc(e){return Kn($s(Qs(e)))}function Fc(e){return qn(R(e))}let Ic=`\\p{Lu}`,Lc=`\\p{Ll}`,Rc=`(?:[\\p{Lm}\\p{Lo}]\\p{M}*)`,zc=`(?:['’](?:d|ll|m|re|s|t|ve))?`,Bc=`(?:['’](?:D|LL|M|RE|S|T|VE))?`,Vc=`[\\p{Z}\\p{P}\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\xd7\\xf7]`,Hc=`(?:${Ic}|${Rc})`,Uc=`(?:${Lc}|${Rc})`,Wc=RegExp([`${Ic}?${Lc}+${zc}(?=${Vc}|${Ic}|$)`,`${Hc}+${Bc}(?=${Vc}|${Ic}${Uc}|$)`,`${Ic}?${Uc}+${zc}`,`${Ic}+${Bc}`,`\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])`,`\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])`,`\\d+`,`\\p{Emoji_Presentation}`,`\\p{Extended_Pictographic}`].join(`|`),`gu`);function Gc(e,t=Wc,n){let r=R(e);return n&&(t=Wc),typeof t==`number`&&(t=t.toString()),Array.from(r.match(t)??[]).filter(e=>e!==``)}function Kc(e){let t=e.length,n=e.map(e=>{let t=e[0],n=e[1];if(!cn(n))throw TypeError(`Expected a function`);return[G(t),n]});return function(...e){for(let r=0;r<t;r++){let t=n[r],i=t[0],a=t[1];if(i.apply(this,e))return a.apply(this,e)}}}function qc(e){return()=>e}function Jc(e,t){return e==null||Number.isNaN(e)?t:e}function Yc(e,t){return typeof e==`string`&&typeof t==`string`?e>t:v(e)>v(t)}function Xc(e,t){return typeof e==`string`&&typeof t==`string`?e>=t:v(e)>=v(t)}function Zc(e,t,...n){if(n=n.flat(1),e!=null)switch(typeof t){case`string`:return typeof e==`object`&&Object.hasOwn(e,t)?Qc(e,[t],n):Qc(e,z(t),n);case`number`:case`symbol`:return Qc(e,[t],n);default:return Array.isArray(t)?Qc(e,t,n):Qc(e,[t],n)}}function Qc(e,t,n){let r=B(e,t.slice(0,-1),e);if(r==null)return;let i=J(t),a=i?.valueOf();return i=typeof a==`number`?L(a):String(i),B(r,i)?.apply(r,n)}function $c(e,t){return typeof e==`string`&&typeof t==`string`?e<t:v(e)<v(t)}function el(e,t){return typeof e==`string`&&typeof t==`string`?e<=t:v(e)<=v(t)}function tl(e,...t){return function(n){return Zc(n,e,t)}}function nl(e,...t){return function(n){return Zc(e,n,t)}}function rl(){return Date.now()}function il(...e){e.length===1&&Array.isArray(e[0])&&(e=e[0]);let t=e.map(e=>G(e));return function(...e){return t.map(t=>t.apply(this,e))}}function al(...e){return function(...t){for(let n=0;n<e.length;++n){let r=e[n];if(!Array.isArray(r)){if(!G(r).apply(this,t))return!1;continue}for(let e=0;e<r.length;++e)if(!G(r[e]).apply(this,t))return!1}return!0}}function ol(...e){return function(...t){for(let n=0;n<e.length;++n){let r=e[n];if(!Array.isArray(r)){if(G(r).apply(this,t))return!0;continue}for(let e=0;e<r.length;++e)if(G(r[e]).apply(this,t))return!0}return!1}}function sl(){return[]}function cl(){return!1}function ll(){return{}}function ul(){return``}function dl(){return!0}function fl(e){return e==null?0:Di(
|
|
8
|
+
}`,f=_a(()=>Function(...c,`${u}return ${d}`)(...l));if(f.source=d,f instanceof Error)throw f;return f}function Tc(e){return R(e).toLowerCase()}function Ec(e){return R(e).toUpperCase()}function Dc(e,t,n){if(e==null)return``;if(n!=null||t==null)return e.toString().trim();switch(typeof t){case`object`:return Array.isArray(t)?Un(e,t.flatMap(e=>e.toString().split(``))):Un(e,t.toString().split(``));default:return Un(e,t.toString().split(``))}}function Oc(e,t,n){return e==null?``:n!=null||t==null?e.toString().trimEnd():Vn(e,t.toString().split(``))}function kc(e,t,n){return e==null?``:n!=null||t==null?e.toString().trimStart():Hn(e,t.toString().split(``))}let Ac=/[\u200d\ud800-\udfff\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff\ufe0e\ufe0f]/;function jc(e,t){e=e==null?``:`${e}`;let n=30,r=`...`;H(t)&&(n=Mc(t.length),r=`omission`in t?`${t.omission}`:`...`);let i=e.length,a=Array.from(r).length,o=Math.max(n-a,0),s;if(Ac.test(e)&&(s=Array.from(e),i=s.length),n>=i)return e;if(i<=a)return r;let c=s===void 0?e.slice(0,o):s?.slice(0,o).join(``),l=t?.separator;if(!l)return c+=r,c;let u=l instanceof RegExp?l.source:l,d=`u`+(l instanceof RegExp?l.flags.replace(`u`,``):``),f=RegExp(`(?<result>.*(?:(?!${u}).))(?:${u})`,d).exec(c);return(f?.groups?f.groups.result:c)+r}function Mc(e){return e==null?30:e<=0?0:e}function Nc(e){return Gn(R(e))}function Pc(e){return Kn($s(Qs(e)))}function Fc(e){return qn(R(e))}let Ic=`\\p{Lu}`,Lc=`\\p{Ll}`,Rc=`(?:[\\p{Lm}\\p{Lo}]\\p{M}*)`,zc=`(?:['’](?:d|ll|m|re|s|t|ve))?`,Bc=`(?:['’](?:D|LL|M|RE|S|T|VE))?`,Vc=`[\\p{Z}\\p{P}\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\xd7\\xf7]`,Hc=`(?:${Ic}|${Rc})`,Uc=`(?:${Lc}|${Rc})`,Wc=RegExp([`${Ic}?${Lc}+${zc}(?=${Vc}|${Ic}|$)`,`${Hc}+${Bc}(?=${Vc}|${Ic}${Uc}|$)`,`${Ic}?${Uc}+${zc}`,`${Ic}+${Bc}`,`\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])`,`\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])`,`\\d+`,`\\p{Emoji_Presentation}`,`\\p{Extended_Pictographic}`].join(`|`),`gu`);function Gc(e,t=Wc,n){let r=R(e);return n&&(t=Wc),typeof t==`number`&&(t=t.toString()),Array.from(r.match(t)??[]).filter(e=>e!==``)}function Kc(e){let t=e.length,n=e.map(e=>{let t=e[0],n=e[1];if(!cn(n))throw TypeError(`Expected a function`);return[G(t),n]});return function(...e){for(let r=0;r<t;r++){let t=n[r],i=t[0],a=t[1];if(i.apply(this,e))return a.apply(this,e)}}}function qc(e){return()=>e}function Jc(e,t){return e==null||Number.isNaN(e)?t:e}function Yc(e,t){return typeof e==`string`&&typeof t==`string`?e>t:v(e)>v(t)}function Xc(e,t){return typeof e==`string`&&typeof t==`string`?e>=t:v(e)>=v(t)}function Zc(e,t,...n){if(n=n.flat(1),e!=null)switch(typeof t){case`string`:return typeof e==`object`&&Object.hasOwn(e,t)?Qc(e,[t],n):Qc(e,z(t),n);case`number`:case`symbol`:return Qc(e,[t],n);default:return Array.isArray(t)?Qc(e,t,n):Qc(e,[t],n)}}function Qc(e,t,n){let r=B(e,t.slice(0,-1),e);if(r==null)return;let i=J(t),a=i?.valueOf();return i=typeof a==`number`?L(a):String(i),B(r,i)?.apply(r,n)}function $c(e,t){return typeof e==`string`&&typeof t==`string`?e<t:v(e)<v(t)}function el(e,t){return typeof e==`string`&&typeof t==`string`?e<=t:v(e)<=v(t)}function tl(e,...t){return function(n){return Zc(n,e,t)}}function nl(e,...t){return function(n){return Zc(e,n,t)}}function rl(){return Date.now()}function il(...e){e.length===1&&Array.isArray(e[0])&&(e=e[0]);let t=e.map(e=>G(e));return function(...e){return t.map(t=>t.apply(this,e))}}function al(...e){return function(...t){for(let n=0;n<e.length;++n){let r=e[n];if(!Array.isArray(r)){if(!G(r).apply(this,t))return!1;continue}for(let e=0;e<r.length;++e)if(!G(r[e]).apply(this,t))return!1}return!0}}function ol(...e){return function(...t){for(let n=0;n<e.length;++n){let r=e[n];if(!Array.isArray(r)){if(G(r).apply(this,t))return!0;continue}for(let e=0;e<r.length;++e)if(G(r[e]).apply(this,t))return!0}return!1}}function sl(){return[]}function cl(){return!1}function ll(){return{}}function ul(){return``}function dl(){return!0}function fl(e){return e==null?0:Di(b(e),0,4294967295)}function pl(e){let t={},n=$(e);for(let r=0;r<n.length;r++){let i=n[r],a=e[i];i===`__proto__`?Object.defineProperty(t,i,{configurable:!0,enumerable:!0,value:a,writable:!0}):t[i]=a}return t}function ml(e){return e==null?0:Di(b(e),-uc,uc)}let hl=0;function gl(e=``){return`${e}${++hl}`}e.AbortError=Fe,e.Mutex=En,e.Semaphore=p,e.TimeoutError=Ie,e.add=qa,e.after=ha,e.allKeyed=Tn,e.ary=ga,e.assert=Yn,e.invariant=Yn,e.assign=yo,e.assignIn=wo,e.extend=wo,e.assignInWith=Eo,e.extendWith=Eo,e.assignWith=Oo,e.asyncNoop=ze,e.at=_i,e.attempt=_a,e.attemptAsync=Jn,e.before=va,e.bind=ya,e.bindAll=Zs,e.bindKey=ba,e.camelCase=ec,e.capitalize=Xs,e.cartesianProduct=t,e.castArray=Xn,e.ceil=Ya,e.chunk=Zn,e.clamp=Di,e.clone=Ao,e.cloneDeep=ur,e.cloneDeepWith=lr,e.cloneWith=Io,e.combinations=r,e.compact=Qn,e.concat=$n,e.cond=Kc,e.conforms=Fs,e.conformsTo=Ps,e.constant=qc,e.constantCase=kn,e.countBy=hr,e.create=Lo,e.curry=xa,e.curryRight=Ta,e.debounce=ka,e.deburr=Qs,e.defaultTo=Jc,e.defaults=Ro,e.defaultsDeep=zo,e.defer=Aa,e.delay=ja,e.difference=gr,e.differenceBy=vr,e.differenceWith=yr,e.divide=Xa,e.drop=br,e.dropRight=xr,e.dropRightWhile=Sr,e.dropWhile=wr,e.each=Er,e.forEach=Er,e.eachRight=Dr,e.forEachRight=Dr,e.endsWith=tc,e.eq=N,e.escape=nc,e.escapeRegExp=rc,e.every=Or,e.fill=Ar,e.filter=jr,e.filterAsync=h,e.find=Mr,e.findIndex=Nr,e.findKey=Wo,e.findLast=Pr,e.findLastIndex=Fr,e.findLastKey=Go,e.first=Ir,e.head=Ir,e.flatMap=Br,e.flatMapAsync=ee,e.flatMapDeep=Hr,e.flatMapDepth=Vr,e.flatten=Lr,e.flattenDeep=Ur,e.flattenDepth=Rr,e.flattenObject=Rt,e.flip=Ma,e.floor=Za,e.flow=Na,e.flowRight=Pa,e.forEachAsync=te,e.forIn=Ko,e.forInRight=qo,e.forOwn=Jo,e.forOwnRight=Yo,e.fromPairs=Xo,e.functions=Zo,e.functionsIn=Qo,e.get=B,e.groupBy=Wr,e.gt=Yc,e.gte=Xc,e.has=mr,e.hasIn=$o,e.identity=X,e.inRange=Qa,e.includes=Gr,e.indexOf=Kr,e.initial=qr,e.intersection=Jr,e.intersectionBy=Yr,e.intersectionWith=Zr,e.invert=es,e.invertBy=ts,e.invoke=Zc,e.invokeMap=$r,e.isArguments=pr,e.isArray=A,e.isArrayBuffer=Is,e.isArrayLike=I,e.isArrayLikeObject=q,e.isBlob=Qt,e.isBoolean=Ls,e.isBrowser=$t,e.isBuffer=Cs,e.isDate=Rs,e.isElement=zs,e.isEmpty=Bs,e.isEmptyObject=tn,e.isEqual=on,e.isEqualWith=Vs,e.isError=Hs,e.isFile=sn,e.isFinite=Us,e.isFunction=Ds,e.isInteger=Ws,e.isJSON=ln,e.isJSONArray=dn,e.isJSONObject=fn,e.isJSONValue=un,e.isLength=Os,e.isMap=Oi,e.isMatch=cr,e.isMatchWith=nr,e.isNaN=Ri,e.isNative=js,e.isNil=Mi,e.isNode=hn,e.isNotNil=gn,e.isNull=Ms,e.isNumber=Bi,e.isObject=H,e.isObjectLike=K,e.isPlainObject=M,e.isPrimitive=S,e.isPromise=vn,e.isRegExp=Gs,e.isSafeInteger=Ks,e.isSet=qs,e.isString=kr,e.isSubset=ce,e.isSubsetWith=le,e.isSymbol=_,e.isTypedArray=Z,e.isUndefined=Ns,e.isWeakMap=Js,e.isWeakSet=Ys,e.iteratee=G,e.join=ei,e.kebabCase=ic,e.keyBy=ni,e.keys=Q,e.keysIn=$,e.last=J,e.lastIndexOf=ri,e.limitAsync=m,e.lowerCase=ac,e.lowerFirst=oc,e.lt=$c,e.lte=el,e.map=zr,e.mapAsync=de,e.mapKeys=ns,e.mapValues=rs,e.matches=U,e.matchesProperty=W,e.max=$a,e.maxBy=eo,e.mean=ro,e.meanBy=io,e.median=at,e.medianBy=ot,e.memoize=Fa,e.merge=os,e.mergeWith=is,e.method=tl,e.methodOf=nl,e.min=ao,e.minBy=oo,e.multiply=so,e.negate=Si,e.noop=ho,e.now=rl,e.nth=ii,e.nthArg=Ia,e.omit=cs,e.omitBy=fs,e.once=La,e.orderBy=ui,e.over=il,e.overArgs=Ra,e.overEvery=al,e.overSome=ol,e.pad=sc,e.padEnd=cc,e.padStart=lc,e.parseInt=co,e.partial=za,e.partialRight=Ba,e.partition=di,e.pascalCase=zn,e.percentile=st,e.pick=ps,e.pickBy=ms,e.property=V,e.propertyOf=hs,e.pull=fi,e.pullAll=pi,e.pullAllBy=mi,e.pullAllWith=gi,e.pullAt=bi,e.random=lo,e.randomInt=ye,e.range=uo,e.rangeRight=fo,e.rearg=Va,e.reduce=ti,e.reduceAsync=he,e.reduceRight=xi,e.reject=Ci,e.remove=wi,e.repeat=dc,e.replace=fc,e.rest=Ha,e.result=gs,e.retry=tt,e.reverse=Ti,e.reverseString=Bn,e.round=po,e.sample=Ei,e.sampleSize=Ai,e.set=fa,e.setWith=_s,e.shuffle=Ni,e.size=Pi,e.slice=Fi,e.snakeCase=pc,e.some=Ii,e.sortBy=Li,e.sortKeys=Ut,e.sortedIndex=Vi,e.sortedIndexBy=zi,e.sortedIndexOf=Hi,e.sortedLastIndex=Wi,e.sortedLastIndexBy=Ui,e.sortedLastIndexOf=Gi,e.split=mc,e.spread=Ua,e.startCase=hc,e.startsWith=gc,e.stubArray=sl,e.stubFalse=cl,e.stubObject=ll,e.stubString=ul,e.stubTrue=dl,e.subtract=mo,e.sum=no,e.sumBy=to,e.tail=Ki,e.take=qi,e.takeRight=Ji,e.takeRightWhile=Yi,e.takeWhile=Xi,e.template=wc,e.templateSettings=Cc,e.throttle=Wa,e.timeout=Dn,e.times=_o,e.toArray=ki,e.toCamelCaseKeys=qt,e.toDefaulted=vs,e.toFilled=Te,e.toFinite=y,e.toInteger=b,e.toLength=fl,e.toLower=Tc,e.toMerged=Jt,e.toNumber=v,e.toPairs=xs,e.toPairsIn=Ss,e.toPath=z,e.toPlainObject=pl,e.toSafeInteger=ml,e.toSnakeCaseKeys=Xt,e.toString=R,e.toUpper=Ec,e.transform=ws,e.trim=Dc,e.trimEnd=Oc,e.trimStart=kc,e.truncate=jc,e.unary=Ga,e.unescape=Nc,e.union=Zi,e.unionBy=Qi,e.unionWith=$i,e.uniq=Xr,e.uniqBy=ea,e.uniqWith=ta,e.uniqueId=gl,e.unset=vi,e.unzip=na,e.unzipWith=ra,e.update=Ts,e.updateWith=da,e.upperCase=Pc,e.upperFirst=Fc,e.values=ji,e.valuesIn=Es,e.windowed=Ae,e.withTimeout=On,e.without=ia,e.words=Gc,e.wrap=Ka,e.xor=aa,e.xorBy=oa,e.xorWith=sa,e.zip=ca,e.zipObject=ua,e.zipObjectDeep=pa,e.zipWith=ma});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Converts the value to a valid index. A valid index is an integer that is greater than or equal to `0` and less than or equal to `2^32 - 1`.
|
|
4
4
|
*
|
|
5
|
-
* It converts the given value to
|
|
5
|
+
* It converts the given value to an integer. If the value is less than `0`, it returns `0`. If the value exceeds `2^32 - 1`, it returns `2^32 - 1`. Values that cannot be converted to a number (such as `NaN` or non-numeric strings) return `0`.
|
|
6
6
|
*
|
|
7
7
|
* @param {unknown} value - The value to convert to a valid index.
|
|
8
8
|
* @returns {number} The converted value.
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* toLength(1.9) // => 1
|
|
14
14
|
* toLength('42') // => 42
|
|
15
15
|
* toLength(null) // => 0
|
|
16
|
+
* toLength('a') // => 0
|
|
16
17
|
*/
|
|
17
18
|
declare function toLength(value: any): number;
|
|
18
19
|
//#endregion
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Converts the value to a valid index. A valid index is an integer that is greater than or equal to `0` and less than or equal to `2^32 - 1`.
|
|
4
4
|
*
|
|
5
|
-
* It converts the given value to
|
|
5
|
+
* It converts the given value to an integer. If the value is less than `0`, it returns `0`. If the value exceeds `2^32 - 1`, it returns `2^32 - 1`. Values that cannot be converted to a number (such as `NaN` or non-numeric strings) return `0`.
|
|
6
6
|
*
|
|
7
7
|
* @param {unknown} value - The value to convert to a valid index.
|
|
8
8
|
* @returns {number} The converted value.
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* toLength(1.9) // => 1
|
|
14
14
|
* toLength('42') // => 42
|
|
15
15
|
* toLength(null) // => 0
|
|
16
|
+
* toLength('a') // => 0
|
|
16
17
|
*/
|
|
17
18
|
declare function toLength(value: any): number;
|
|
18
19
|
//#endregion
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
const require_toInteger = require("./toInteger.js");
|
|
1
2
|
const require_clamp = require("../math/clamp.js");
|
|
2
3
|
const require_MAX_ARRAY_LENGTH = require("../_internal/MAX_ARRAY_LENGTH.js");
|
|
3
4
|
//#region src/compat/util/toLength.ts
|
|
4
5
|
/**
|
|
5
6
|
* Converts the value to a valid index. A valid index is an integer that is greater than or equal to `0` and less than or equal to `2^32 - 1`.
|
|
6
7
|
*
|
|
7
|
-
* It converts the given value to
|
|
8
|
+
* It converts the given value to an integer. If the value is less than `0`, it returns `0`. If the value exceeds `2^32 - 1`, it returns `2^32 - 1`. Values that cannot be converted to a number (such as `NaN` or non-numeric strings) return `0`.
|
|
8
9
|
*
|
|
9
10
|
* @param {unknown} value - The value to convert to a valid index.
|
|
10
11
|
* @returns {number} The converted value.
|
|
@@ -15,11 +16,11 @@ const require_MAX_ARRAY_LENGTH = require("../_internal/MAX_ARRAY_LENGTH.js");
|
|
|
15
16
|
* toLength(1.9) // => 1
|
|
16
17
|
* toLength('42') // => 42
|
|
17
18
|
* toLength(null) // => 0
|
|
19
|
+
* toLength('a') // => 0
|
|
18
20
|
*/
|
|
19
21
|
function toLength(value) {
|
|
20
22
|
if (value == null) return 0;
|
|
21
|
-
|
|
22
|
-
return require_clamp.clamp(length, 0, require_MAX_ARRAY_LENGTH.MAX_ARRAY_LENGTH);
|
|
23
|
+
return require_clamp.clamp(require_toInteger.toInteger(value), 0, require_MAX_ARRAY_LENGTH.MAX_ARRAY_LENGTH);
|
|
23
24
|
}
|
|
24
25
|
//#endregion
|
|
25
26
|
exports.toLength = toLength;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { toInteger } from "./toInteger.mjs";
|
|
1
2
|
import { clamp } from "../math/clamp.mjs";
|
|
2
3
|
import { MAX_ARRAY_LENGTH } from "../_internal/MAX_ARRAY_LENGTH.mjs";
|
|
3
4
|
//#region src/compat/util/toLength.ts
|
|
4
5
|
/**
|
|
5
6
|
* Converts the value to a valid index. A valid index is an integer that is greater than or equal to `0` and less than or equal to `2^32 - 1`.
|
|
6
7
|
*
|
|
7
|
-
* It converts the given value to
|
|
8
|
+
* It converts the given value to an integer. If the value is less than `0`, it returns `0`. If the value exceeds `2^32 - 1`, it returns `2^32 - 1`. Values that cannot be converted to a number (such as `NaN` or non-numeric strings) return `0`.
|
|
8
9
|
*
|
|
9
10
|
* @param {unknown} value - The value to convert to a valid index.
|
|
10
11
|
* @returns {number} The converted value.
|
|
@@ -15,10 +16,11 @@ import { MAX_ARRAY_LENGTH } from "../_internal/MAX_ARRAY_LENGTH.mjs";
|
|
|
15
16
|
* toLength(1.9) // => 1
|
|
16
17
|
* toLength('42') // => 42
|
|
17
18
|
* toLength(null) // => 0
|
|
19
|
+
* toLength('a') // => 0
|
|
18
20
|
*/
|
|
19
21
|
function toLength(value) {
|
|
20
22
|
if (value == null) return 0;
|
|
21
|
-
return clamp(
|
|
23
|
+
return clamp(toInteger(value), 0, MAX_ARRAY_LENGTH);
|
|
22
24
|
}
|
|
23
25
|
//#endregion
|
|
24
26
|
export { toLength };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
|
-
"version": "1.47.0-dev.
|
|
3
|
+
"version": "1.47.0-dev.1835+02fa0f53",
|
|
4
4
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
5
5
|
"homepage": "https://es-toolkit.dev",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|