@discordjs/collection
Advanced tools
Comparing version 2.1.1-dev.1721153481-918f43411 to 2.1.1-dev.1721153951-efa16a609
@@ -45,6 +45,4 @@ "use strict"; | ||
ensure(key, defaultValueGenerator) { | ||
if (this.has(key)) | ||
return this.get(key); | ||
if (typeof defaultValueGenerator !== "function") | ||
throw new TypeError(`${defaultValueGenerator} is not a function`); | ||
if (this.has(key)) return this.get(key); | ||
if (typeof defaultValueGenerator !== "function") throw new TypeError(`${defaultValueGenerator} is not a function`); | ||
const defaultValue = defaultValueGenerator(key, this); | ||
@@ -73,6 +71,4 @@ this.set(key, defaultValue); | ||
first(amount) { | ||
if (amount === void 0) | ||
return this.values().next().value; | ||
if (amount < 0) | ||
return this.last(amount * -1); | ||
if (amount === void 0) return this.values().next().value; | ||
if (amount < 0) return this.last(amount * -1); | ||
amount = Math.min(this.size, amount); | ||
@@ -83,6 +79,4 @@ const iter = this.values(); | ||
firstKey(amount) { | ||
if (amount === void 0) | ||
return this.keys().next().value; | ||
if (amount < 0) | ||
return this.lastKey(amount * -1); | ||
if (amount === void 0) return this.keys().next().value; | ||
if (amount < 0) return this.lastKey(amount * -1); | ||
amount = Math.min(this.size, amount); | ||
@@ -94,8 +88,5 @@ const iter = this.keys(); | ||
const arr = [...this.values()]; | ||
if (amount === void 0) | ||
return arr[arr.length - 1]; | ||
if (amount < 0) | ||
return this.first(amount * -1); | ||
if (!amount) | ||
return []; | ||
if (amount === void 0) return arr[arr.length - 1]; | ||
if (amount < 0) return this.first(amount * -1); | ||
if (!amount) return []; | ||
return arr.slice(-amount); | ||
@@ -105,8 +96,5 @@ } | ||
const arr = [...this.keys()]; | ||
if (amount === void 0) | ||
return arr[arr.length - 1]; | ||
if (amount < 0) | ||
return this.firstKey(amount * -1); | ||
if (!amount) | ||
return []; | ||
if (amount === void 0) return arr[arr.length - 1]; | ||
if (amount < 0) return this.firstKey(amount * -1); | ||
if (!amount) return []; | ||
return arr.slice(-amount); | ||
@@ -140,6 +128,4 @@ } | ||
const arr = [...this.values()]; | ||
if (amount === void 0) | ||
return arr[Math.floor(Math.random() * arr.length)]; | ||
if (!arr.length || !amount) | ||
return []; | ||
if (amount === void 0) return arr[Math.floor(Math.random() * arr.length)]; | ||
if (!arr.length || !amount) return []; | ||
return Array.from( | ||
@@ -152,6 +138,4 @@ { length: Math.min(amount, arr.length) }, | ||
const arr = [...this.keys()]; | ||
if (amount === void 0) | ||
return arr[Math.floor(Math.random() * arr.length)]; | ||
if (!arr.length || !amount) | ||
return []; | ||
if (amount === void 0) return arr[Math.floor(Math.random() * arr.length)]; | ||
if (!arr.length || !amount) return []; | ||
return Array.from( | ||
@@ -169,14 +153,10 @@ { length: Math.min(amount, arr.length) }, | ||
this.clear(); | ||
for (const [key, value] of entries) | ||
this.set(key, value); | ||
for (const [key, value] of entries) this.set(key, value); | ||
return this; | ||
} | ||
find(fn, thisArg) { | ||
if (typeof fn !== "function") | ||
throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) | ||
fn = fn.bind(thisArg); | ||
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) fn = fn.bind(thisArg); | ||
for (const [key, val] of this) { | ||
if (fn(val, key, this)) | ||
return val; | ||
if (fn(val, key, this)) return val; | ||
} | ||
@@ -186,9 +166,6 @@ return void 0; | ||
findKey(fn, thisArg) { | ||
if (typeof fn !== "function") | ||
throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) | ||
fn = fn.bind(thisArg); | ||
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) fn = fn.bind(thisArg); | ||
for (const [key, val] of this) { | ||
if (fn(val, key, this)) | ||
return key; | ||
if (fn(val, key, this)) return key; | ||
} | ||
@@ -198,6 +175,4 @@ return void 0; | ||
findLast(fn, thisArg) { | ||
if (typeof fn !== "function") | ||
throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) | ||
fn = fn.bind(thisArg); | ||
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) fn = fn.bind(thisArg); | ||
const entries = [...this.entries()]; | ||
@@ -207,4 +182,3 @@ for (let index = entries.length - 1; index >= 0; index--) { | ||
const key = entries[index][0]; | ||
if (fn(val, key, this)) | ||
return val; | ||
if (fn(val, key, this)) return val; | ||
} | ||
@@ -214,6 +188,4 @@ return void 0; | ||
findLastKey(fn, thisArg) { | ||
if (typeof fn !== "function") | ||
throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) | ||
fn = fn.bind(thisArg); | ||
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) fn = fn.bind(thisArg); | ||
const entries = [...this.entries()]; | ||
@@ -223,4 +195,3 @@ for (let index = entries.length - 1; index >= 0; index--) { | ||
const val = entries[index][1]; | ||
if (fn(val, key, this)) | ||
return key; | ||
if (fn(val, key, this)) return key; | ||
} | ||
@@ -230,10 +201,7 @@ return void 0; | ||
sweep(fn, thisArg) { | ||
if (typeof fn !== "function") | ||
throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) | ||
fn = fn.bind(thisArg); | ||
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) fn = fn.bind(thisArg); | ||
const previousSize = this.size; | ||
for (const [key, val] of this) { | ||
if (fn(val, key, this)) | ||
this.delete(key); | ||
if (fn(val, key, this)) this.delete(key); | ||
} | ||
@@ -243,10 +211,7 @@ return previousSize - this.size; | ||
filter(fn, thisArg) { | ||
if (typeof fn !== "function") | ||
throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) | ||
fn = fn.bind(thisArg); | ||
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) fn = fn.bind(thisArg); | ||
const results = new this.constructor[Symbol.species](); | ||
for (const [key, val] of this) { | ||
if (fn(val, key, this)) | ||
results.set(key, val); | ||
if (fn(val, key, this)) results.set(key, val); | ||
} | ||
@@ -256,6 +221,4 @@ return results; | ||
partition(fn, thisArg) { | ||
if (typeof fn !== "function") | ||
throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) | ||
fn = fn.bind(thisArg); | ||
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) fn = fn.bind(thisArg); | ||
const results = [ | ||
@@ -279,6 +242,4 @@ new this.constructor[Symbol.species](), | ||
map(fn, thisArg) { | ||
if (typeof fn !== "function") | ||
throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) | ||
fn = fn.bind(thisArg); | ||
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) fn = fn.bind(thisArg); | ||
const iter = this.entries(); | ||
@@ -291,19 +252,13 @@ return Array.from({ length: this.size }, () => { | ||
mapValues(fn, thisArg) { | ||
if (typeof fn !== "function") | ||
throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) | ||
fn = fn.bind(thisArg); | ||
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) fn = fn.bind(thisArg); | ||
const coll = new this.constructor[Symbol.species](); | ||
for (const [key, val] of this) | ||
coll.set(key, fn(val, key, this)); | ||
for (const [key, val] of this) coll.set(key, fn(val, key, this)); | ||
return coll; | ||
} | ||
some(fn, thisArg) { | ||
if (typeof fn !== "function") | ||
throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) | ||
fn = fn.bind(thisArg); | ||
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) fn = fn.bind(thisArg); | ||
for (const [key, val] of this) { | ||
if (fn(val, key, this)) | ||
return true; | ||
if (fn(val, key, this)) return true; | ||
} | ||
@@ -313,9 +268,6 @@ return false; | ||
every(fn, thisArg) { | ||
if (typeof fn !== "function") | ||
throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) | ||
fn = fn.bind(thisArg); | ||
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) fn = fn.bind(thisArg); | ||
for (const [key, val] of this) { | ||
if (!fn(val, key, this)) | ||
return false; | ||
if (!fn(val, key, this)) return false; | ||
} | ||
@@ -337,9 +289,7 @@ return true; | ||
reduce(fn, initialValue) { | ||
if (typeof fn !== "function") | ||
throw new TypeError(`${fn} is not a function`); | ||
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`); | ||
let accumulator; | ||
const iterator = this.entries(); | ||
if (initialValue === void 0) { | ||
if (this.size === 0) | ||
throw new TypeError("Reduce of empty collection with no initial value"); | ||
if (this.size === 0) throw new TypeError("Reduce of empty collection with no initial value"); | ||
accumulator = iterator.next().value[1]; | ||
@@ -362,4 +312,3 @@ } else { | ||
reduceRight(fn, initialValue) { | ||
if (typeof fn !== "function") | ||
throw new TypeError(`${fn} is not a function`); | ||
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`); | ||
const entries = [...this.entries()]; | ||
@@ -369,4 +318,3 @@ let accumulator; | ||
if (initialValue === void 0) { | ||
if (entries.length === 0) | ||
throw new TypeError("Reduce of empty collection with no initial value"); | ||
if (entries.length === 0) throw new TypeError("Reduce of empty collection with no initial value"); | ||
accumulator = entries[entries.length - 1][1]; | ||
@@ -386,6 +334,4 @@ index = entries.length - 1; | ||
each(fn, thisArg) { | ||
if (typeof fn !== "function") | ||
throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) | ||
fn = fn.bind(thisArg); | ||
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) fn = fn.bind(thisArg); | ||
for (const [key, value] of this) { | ||
@@ -397,6 +343,4 @@ fn(value, key, this); | ||
tap(fn, thisArg) { | ||
if (typeof fn !== "function") | ||
throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) | ||
fn = fn.bind(thisArg); | ||
if (typeof fn !== "function") throw new TypeError(`${fn} is not a function`); | ||
if (thisArg !== void 0) fn = fn.bind(thisArg); | ||
fn(this); | ||
@@ -428,4 +372,3 @@ return this; | ||
for (const coll of collections) { | ||
for (const [key, val] of coll) | ||
newColl.set(key, val); | ||
for (const [key, val] of coll) newColl.set(key, val); | ||
} | ||
@@ -443,8 +386,5 @@ return newColl; | ||
equals(collection) { | ||
if (!collection) | ||
return false; | ||
if (this === collection) | ||
return true; | ||
if (this.size !== collection.size) | ||
return false; | ||
if (!collection) return false; | ||
if (this === collection) return true; | ||
if (this.size !== collection.size) return false; | ||
for (const [key, value] of this) { | ||
@@ -494,4 +434,3 @@ if (!collection.has(key) || value !== collection.get(key)) { | ||
for (const [key, value] of this) { | ||
if (other.has(key)) | ||
coll.set(key, value); | ||
if (other.has(key)) coll.set(key, value); | ||
} | ||
@@ -519,4 +458,3 @@ return coll; | ||
for (const [key, value] of other) { | ||
if (!coll.has(key)) | ||
coll.set(key, value); | ||
if (!coll.has(key)) coll.set(key, value); | ||
} | ||
@@ -542,4 +480,3 @@ return coll; | ||
for (const [key, value] of this) { | ||
if (!other.has(key)) | ||
coll.set(key, value); | ||
if (!other.has(key)) coll.set(key, value); | ||
} | ||
@@ -564,8 +501,6 @@ return coll; | ||
for (const [key, value] of this) { | ||
if (!other.has(key)) | ||
coll.set(key, value); | ||
if (!other.has(key)) coll.set(key, value); | ||
} | ||
for (const [key, value] of other) { | ||
if (!this.has(key)) | ||
coll.set(key, value); | ||
if (!this.has(key)) coll.set(key, value); | ||
} | ||
@@ -610,12 +545,9 @@ return coll; | ||
const result = whenInBoth(this.get(key), other.get(key), key); | ||
if (result.keep) | ||
coll.set(key, result.value); | ||
if (result.keep) coll.set(key, result.value); | ||
} else if (hasInSelf) { | ||
const result = whenInSelf(this.get(key), key); | ||
if (result.keep) | ||
coll.set(key, result.value); | ||
if (result.keep) coll.set(key, result.value); | ||
} else if (hasInOther) { | ||
const result = whenInOther(other.get(key), key); | ||
if (result.keep) | ||
coll.set(key, result.value); | ||
if (result.keep) coll.set(key, result.value); | ||
} | ||
@@ -679,3 +611,3 @@ } | ||
// src/index.ts | ||
var version = "2.1.1-dev.1721153481-918f43411"; | ||
var version = "2.1.1-dev.1721153951-efa16a609"; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -682,0 +614,0 @@ 0 && (module.exports = { |
{ | ||
"$schema": "https://json.schemastore.org/package.json", | ||
"name": "@discordjs/collection", | ||
"version": "2.1.1-dev.1721153481-918f43411", | ||
"version": "2.1.1-dev.1721153951-efa16a609", | ||
"description": "Utility data structure used in discord.js", | ||
@@ -52,5 +52,5 @@ "exports": { | ||
"devDependencies": { | ||
"@favware/cliff-jumper": "^3.0.2", | ||
"@favware/cliff-jumper": "^3.0.3", | ||
"@types/node": "18.18.8", | ||
"@vitest/coverage-v8": "^1.5.0", | ||
"@vitest/coverage-v8": "^1.6.0", | ||
"cross-env": "^7.0.3", | ||
@@ -61,9 +61,9 @@ "esbuild-plugin-version-injector": "^1.2.1", | ||
"eslint-formatter-pretty": "^6.0.1", | ||
"prettier": "^3.2.5", | ||
"tsup": "^8.0.2", | ||
"turbo": "^1.13.2", | ||
"prettier": "^3.3.0", | ||
"tsup": "^8.1.0", | ||
"turbo": "^1.13.3", | ||
"typescript": "^5.4.5", | ||
"vitest": "^1.5.0", | ||
"@discordjs/scripts": "^0.1.0", | ||
"@discordjs/api-extractor": "^7.38.1" | ||
"vitest": "^1.6.0", | ||
"@discordjs/api-extractor": "^7.38.1", | ||
"@discordjs/scripts": "^0.1.0" | ||
}, | ||
@@ -70,0 +70,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
215307
1673