@stacksjs/arrays 0.74.3 → 0.74.5

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/helpers.d.ts CHANGED
@@ -141,19 +141,6 @@ export declare function at<T>(array: readonly T[], index: number): T;
141
141
  * ```
142
142
  */
143
143
  export declare function move<T>(array: T[], from: number, to: number): T[];
144
- /**
145
- * Clamp a number to the index range of an array.
146
- *
147
- * @category Array
148
- * @example
149
- * ```ts
150
- * clampArrayRange([1, 2, 3], 0) // 0
151
- * clampArrayRange([1, 2, 3], 1) // 1
152
- * clampArrayRange([1, 2, 3], 2) // 2
153
- * clampArrayRange([1, 2, 3], 3) // 2
154
- * clampArrayRange([1, 2, 3], 4) // 2
155
- * clampArrayRange([1, 2, 3], -1) // 0
156
- */
157
144
  export declare function clampArrayRange(arr: readonly unknown[], n: number): number;
158
145
  /**
159
146
  * Get random items from an array
package/dist/helpers.js CHANGED
@@ -1 +1 @@
1
- import{clamp}from"@stacksjs/utils";export function toArray(array){array=array??[];return Array.isArray(array)?array:[array]}export function flatten(array){return toArray(array).reduce((acc,val)=>acc.concat(Array.isArray(val)?flatten(val):val),[])}export function mergeArrayable(...args){return args.flatMap((i)=>toArray(i))}export function partition(array,...filters){const result=Array.from({length:filters.length+1}).fill(null).map(()=>[]);array.forEach((e,idx,arr)=>{let i=0;for(const filter of filters){if(filter(e,idx,arr)){result[i].push(e);return}i+=1}result[i].push(e)});return result}export function uniq(array){return Array.from(new Set(array))}export function unique(array){return uniq(array)}export function uniqueBy(array,equalFn){return array.reduce((acc,cur)=>{if(acc.findIndex((item)=>equalFn(cur,item))===-1)acc.push(cur);return acc},[])}export function last(array){return at(array,-1)}export function remove(array,value){if(!array)return!1;const index=array.indexOf(value);if(index>=0){array.splice(index,1);return!0}return!1}export function at(array,index){const len=array.length;if(!len)return;if(index<0)index+=len;return array[index]}export function move(array,from,to){const len=array.length;if(!len)return[];if(from<0)from+=len;if(to<0)to+=len;const item=array.splice(from,1)[0];array.splice(to,0,item);return array}export function clampArrayRange(arr,n){return clamp(n,0,arr.length-1)}export function sample(arr,count){return Array.from({length:count},()=>arr[Math.floor(Math.random()*arr.length)])}export function shuffle(array){for(let i=array.length-1;i>0;i--){const j=Math.floor(Math.random()*(i+1));[array[i],array[j]]=[array[j],array[i]]}return array}
1
+ export function toArray(array){array=array??[];return Array.isArray(array)?array:[array]}export function flatten(array){return toArray(array).reduce((acc,val)=>acc.concat(Array.isArray(val)?flatten(val):val),[])}export function mergeArrayable(...args){return args.flatMap((i)=>toArray(i))}export function partition(array,...filters){const result=Array.from({length:filters.length+1}).fill(null).map(()=>[]);array.forEach((e,idx,arr)=>{let i=0;for(const filter of filters){if(filter(e,idx,arr)){result[i].push(e);return}i+=1}result[i].push(e)});return result}export function uniq(array){return Array.from(new Set(array))}export function unique(array){return uniq(array)}export function uniqueBy(array,equalFn){return array.reduce((acc,cur)=>{if(acc.findIndex((item)=>equalFn(cur,item))===-1)acc.push(cur);return acc},[])}export function last(array){return at(array,-1)}export function remove(array,value){if(!array)return!1;const index=array.indexOf(value);if(index>=0){array.splice(index,1);return!0}return!1}export function at(array,index){const len=array.length;if(!len)return;if(index<0)index+=len;return array[index]}export function move(array,from,to){const len=array.length;if(!len)return[];if(from<0)from+=len;if(to<0)to+=len;const item=array.splice(from,1)[0];array.splice(to,0,item);return array}function clamp(n,min,max){return Math.min(max,Math.max(min,n))}export function clampArrayRange(arr,n){return clamp(n,0,arr.length-1)}export function sample(arr,count){return Array.from({length:count},()=>arr[Math.floor(Math.random()*arr.length)])}export function shuffle(array){for(let i=array.length-1;i>0;i--){const j=Math.floor(Math.random()*(i+1));[array[i],array[j]]=[array[j],array[i]]}return array}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/arrays",
3
3
  "type": "module",
4
- "version": "0.74.3",
4
+ "version": "0.74.5",
5
5
  "description": "The Stacks array utilities.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [
@@ -58,9 +58,7 @@
58
58
  "test": "bun test",
59
59
  "prepublishOnly": "bun run build"
60
60
  },
61
- "dependencies": {
62
- "@stacksjs/utils": "0.74.3"
63
- },
61
+ "dependencies": {},
64
62
  "devDependencies": {
65
63
  "better-dx": "^0.2.24"
66
64
  },