@nothing-but/utils
Advanced tools
Comparing version 0.1.0 to 0.2.0
# @nothing-but/utils | ||
## 0.2.0 | ||
### Minor Changes | ||
- 97ab7cb: Add misc module and more array funcitons | ||
## 0.1.0 | ||
@@ -4,0 +10,0 @@ |
@@ -1,1 +0,1 @@ | ||
export { f as binaryInsert, e as binaryInsertUnique, g as binaryInsertWith, c as binarySearch, d as binarySearchWith, p as pickRandom, b as pickRandomExclidingOne, r as randomIterate, w as wrap } from '../array-dbc2c38a.js'; | ||
export { j as binaryInsert, h as binaryInsertUnique, k as binaryInsertWith, f as binarySearch, g as binarySearchWith, d as deduped, e as equals, i as includesSameMembers, m as mutateFilter, p as pickRandom, b as pickRandomExclidingOne, c as randomIterate, r as remove, w as wrap } from '../array-2ae64097.js'; |
@@ -1,6 +0,7 @@ | ||
export { binaryInsert, binaryInsertUnique, binaryInsertWith, binarySearch, binarySearchWith, pickRandom, pickRandomExclidingOne, randomIterate, wrap } from '../chunk/F2TQ5ZET.js'; | ||
export { binaryInsert, binaryInsertUnique, binaryInsertWith, binarySearch, binarySearchWith, deduped, equals, includesSameMembers, mutateFilter, pickRandom, pickRandomExclidingOne, randomIterate, remove, wrap } from '../chunk/TULCZLWC.js'; | ||
import '../chunk/OZRPOR2F.js'; | ||
import '../chunk/I42HF3LR.js'; | ||
import '../chunk/233FGWLT.js'; | ||
import '../chunk/PSUTF5FZ.js'; | ||
import '../chunk/5ZKAE4VZ.js'; | ||
import '../chunk/QR25BPRP.js'; |
@@ -1,5 +0,6 @@ | ||
export { a as array } from '../array-dbc2c38a.js'; | ||
export { a as array } from '../array-2ae64097.js'; | ||
export { e as ease } from '../ease-8473b216.js'; | ||
export { m as math } from '../math-b7f74671.js'; | ||
export { t as trig } from '../trig-0a2cca0d.js'; | ||
export { t as types } from '../types-ba0945a2.js'; | ||
export { m as misc } from '../misc-515f5ec0.js'; | ||
export { t as trig } from '../trig-3450e0d6.js'; | ||
export { t as types } from '../types-053e3c12.js'; |
@@ -1,6 +0,7 @@ | ||
export { array_exports as array } from '../chunk/F2TQ5ZET.js'; | ||
export { array_exports as array } from '../chunk/TULCZLWC.js'; | ||
export { ease_exports as ease } from '../chunk/OZRPOR2F.js'; | ||
export { math_exports as math } from '../chunk/I42HF3LR.js'; | ||
export { misc_exports as misc } from '../chunk/233FGWLT.js'; | ||
export { trig_exports as trig } from '../chunk/PSUTF5FZ.js'; | ||
import '../chunk/5ZKAE4VZ.js'; | ||
export { types_exports as types } from '../chunk/QR25BPRP.js'; |
@@ -1,2 +0,2 @@ | ||
import '../types-ba0945a2.js'; | ||
export { F as Force, S as Segment, a as Vec, V as VecString, Z as ZERO, o as force, p as forceToVec, v as vec, e as vecAdd, l as vecAngle, d as vecDifference, k as vecDistance, i as vecDivide, b as vecEquals, g as vecMultiply, h as vecProduct, j as vecQuotient, m as vecRotate, n as vecRotateAround, c as vecSubtract, f as vecSum, z as zero } from '../trig-0a2cca0d.js'; | ||
import '../types-053e3c12.js'; | ||
export { F as Force, S as Segment, a as Vec, V as VecString, Z as ZERO, o as force, p as forceToVec, v as vec, e as vecAdd, l as vecAngle, d as vecDifference, k as vecDistance, i as vecDivide, b as vecEquals, g as vecMultiply, h as vecProduct, j as vecQuotient, m as vecRotate, n as vecRotateAround, c as vecSubtract, f as vecSum, z as zero } from '../trig-3450e0d6.js'; |
@@ -1,1 +0,1 @@ | ||
export { b as AnyClass, a as AnyFunction, A as AnyObject, D as DeepPartialAny, E as EmptyObject, n as Enumerate, i as ExtractIfPossible, d as Falsy, F as FalsyValue, I as ItemsOf, M as Many, e as Modify, f as ModifyDeep, l as Narrow, m as NoInfer, g as NonIterable, N as Noop, P as Position, c as Primitive, R as RequiredKeys, j as Simplify, S as Size, h as Tail, T as Truthy, k as UnboxLazy, U as UnionToIntersection } from '../types-ba0945a2.js'; | ||
export { A as AnyClass, b as AnyFunction, a as AnyObject, D as DeepPartialAny, E as EmptyObject, n as Enumerate, i as ExtractIfPossible, d as Falsy, F as FalsyValue, I as ItemsOf, M as Many, e as Modify, f as ModifyDeep, l as Narrow, m as NoInfer, g as NonIterable, N as Noop, P as Position, c as Primitive, R as RequiredKeys, j as Simplify, S as Size, h as Tail, T as Truthy, k as UnboxLazy, U as UnionToIntersection } from '../types-053e3c12.js'; |
{ | ||
"name": "@nothing-but/utils", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"license": "MIT", | ||
@@ -50,2 +50,8 @@ "author": "Damian Tarnawski <gthetarnav@gmail.com>", | ||
}, | ||
"./misc": { | ||
"import": { | ||
"types": "./dist/misc/index.d.ts", | ||
"default": "./dist/misc/index.js" | ||
} | ||
}, | ||
"./trig": { | ||
@@ -75,2 +81,5 @@ "import": { | ||
], | ||
"misc": [ | ||
"./dist/misc/index.d.ts" | ||
], | ||
"trig": [ | ||
@@ -77,0 +86,0 @@ "./dist/trig/index.d.ts" |
import { math } from '.' | ||
/** | ||
* Check shallow array equality | ||
*/ | ||
export function equals(a: readonly unknown[], b: readonly unknown[]): boolean { | ||
return a === b || (a.length === b.length && a.every((e, i) => e === b[i])) | ||
} | ||
export function wrap<T>(arr: readonly T[], index: number): T | undefined { | ||
@@ -7,2 +14,58 @@ return arr[math.remainder(index, arr.length)] | ||
/** | ||
* Checks if both arrays contain the same values. | ||
* Order doesn't matter. | ||
* Arrays must not contain duplicates. (be the same lengths) | ||
*/ | ||
export function includesSameMembers(a: readonly unknown[], b: readonly unknown[]) { | ||
if (a === b) return true | ||
if (a.length !== b.length) return false | ||
const copy = b.slice() | ||
let found = 0 | ||
a_loop: for (let i = 0; i < a.length; i++) { | ||
const a_item = a[i] | ||
for (let j = found; j < b.length; j++) { | ||
const b_item = copy[j] | ||
if (a_item === b_item) { | ||
;[copy[j], copy[found]] = [copy[found], copy[j]] | ||
found = j + 1 | ||
continue a_loop | ||
} | ||
} | ||
return false | ||
} | ||
return true | ||
} | ||
export function deduped<T>(array: readonly T[]): T[] { | ||
return Array.from(new Set(array)) | ||
} | ||
export function mutateFilter<T, S extends T>( | ||
array: T[], | ||
predicate: (value: T, index: number, array: T[]) => value is S, | ||
): void | ||
export function mutateFilter<T>( | ||
array: T[], | ||
predicate: (value: T, index: number, array: T[]) => unknown, | ||
): void | ||
export function mutateFilter<T>( | ||
array: T[], | ||
predicate: (value: T, index: number, array: T[]) => unknown, | ||
): void { | ||
const temp = array.filter(predicate) | ||
array.length = 0 | ||
array.push.apply(array, temp) | ||
} | ||
export function remove<T>(array: T[], item: T): void { | ||
array.splice(array.indexOf(item), 1) | ||
} | ||
export const pickRandom = <T>(arr: readonly T[]): T | undefined => arr[math.randomInt(arr.length)] | ||
@@ -9,0 +72,0 @@ |
export * as array from './array' | ||
export * as ease from './ease' | ||
export * as math from './math' | ||
export * as misc from './misc' | ||
export * as trig from './trig' | ||
export * as types from './types' |
@@ -12,5 +12,5 @@ import fs from 'fs' | ||
// Enable this to write export conditions to package.json | ||
// writePackageJson: true, | ||
writePackageJson: true, | ||
dropConsole: true, | ||
}, | ||
) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
81811
39
2317
0