@discordjs/collection
Advanced tools
Comparing version 0.5.0 to 0.6.0-dev.1644067357.5f4b44d
@@ -365,2 +365,28 @@ /** | ||
/** | ||
* Merges two Collections together into a new Collection. | ||
* @param other The other Collection to merge with | ||
* @param whenInSelf Function getting the result if the entry only exists in this Collection | ||
* @param whenInOther Function getting the result if the entry only exists in the other Collection | ||
* @param whenInBoth Function getting the result if the entry exists in both Collections | ||
* | ||
* @example | ||
* // Sums up the entries in two collections. | ||
* coll.merge( | ||
* other, | ||
* x => ({ keep: true, value: x }), | ||
* y => ({ keep: true, value: y }), | ||
* (x, y) => ({ keep: true, value: x + y }), | ||
* ); | ||
* | ||
* @example | ||
* // Intersects two collections in a left-biased manner. | ||
* coll.merge( | ||
* other, | ||
* x => ({ keep: false }), | ||
* y => ({ keep: false }), | ||
* (x, _) => ({ keep: true, value: x }), | ||
* ); | ||
*/ | ||
merge<T, R>(other: ReadonlyCollection<K, T>, whenInSelf: (value: V, key: K) => Keep<R>, whenInOther: (valueOther: T, key: K) => Keep<R>, whenInBoth: (value: V, valueOther: T, key: K) => Keep<R>): Collection<K, R>; | ||
/** | ||
* The sorted method sorts the items of a collection and returns it. | ||
@@ -380,2 +406,12 @@ * The sort is not necessarily stable in Node 10 or older. | ||
private static defaultSort; | ||
/** | ||
* Creates a Collection from a list of entries. | ||
* @param entries The list of entries | ||
* @param combine Function to combine an existing entry with a new one | ||
* | ||
* @example | ||
* Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y); | ||
* // returns Collection { "a" => 3, "b" => 2 } | ||
*/ | ||
static combineEntries<K, V>(entries: Iterable<[K, V]>, combine: (firstValue: V, secondValue: V, key: K) => V): Collection<K, V>; | ||
} | ||
@@ -385,4 +421,13 @@ /** | ||
*/ | ||
declare type Keep<V> = { | ||
keep: true; | ||
value: V; | ||
} | { | ||
keep: false; | ||
}; | ||
/** | ||
* @internal | ||
*/ | ||
declare type Comparator<K, V> = (firstValue: V, secondValue: V, firstKey: K, secondKey: K) => number; | ||
export { Collection, CollectionConstructor, Comparator, ReadonlyCollection, Collection as default }; | ||
export { Collection, CollectionConstructor, Comparator, Keep, ReadonlyCollection, Collection as default }; |
@@ -1,2 +0,2 @@ | ||
var s=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var d=(n,e,i)=>e in n?s(n,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):n[e]=i;var V=n=>s(n,"__esModule",{value:!0}),h=(n,e)=>s(n,"name",{value:e,configurable:!0});var b=(n,e)=>{for(var i in e)s(n,i,{get:e[i],enumerable:!0})},y=(n,e,i,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of K(e))!p.call(n,l)&&(i||l!=="default")&&s(n,l,{get:()=>e[l],enumerable:!(t=f(e,l))||t.enumerable});return n};var v=(n=>(e,i)=>n&&n.get(e)||(i=y(V({}),e,1),n&&n.set(e,i),i))(typeof WeakMap!="undefined"?new WeakMap:0);var a=(n,e,i)=>(d(n,typeof e!="symbol"?e+"":e,i),i);var k={};b(k,{Collection:()=>c,default:()=>T});var r=class extends Map{ensure(e,i){if(this.has(e))return this.get(e);let t=i(e,this);return this.set(e,t),t}hasAll(...e){return e.every(i=>super.has(i))}hasAny(...e){return e.some(i=>super.has(i))}first(e){if(typeof e=="undefined")return this.values().next().value;if(e<0)return this.last(e*-1);e=Math.min(this.size,e);let i=this.values();return Array.from({length:e},()=>i.next().value)}firstKey(e){if(typeof e=="undefined")return this.keys().next().value;if(e<0)return this.lastKey(e*-1);e=Math.min(this.size,e);let i=this.keys();return Array.from({length:e},()=>i.next().value)}last(e){let i=[...this.values()];return typeof e=="undefined"?i[i.length-1]:e<0?this.first(e*-1):e?i.slice(-e):[]}lastKey(e){let i=[...this.keys()];return typeof e=="undefined"?i[i.length-1]:e<0?this.firstKey(e*-1):e?i.slice(-e):[]}at(e){return e=Math.floor(e),[...this.values()].at(e)}keyAt(e){return e=Math.floor(e),[...this.keys()].at(e)}random(e){let i=[...this.values()];return typeof e=="undefined"?i[Math.floor(Math.random()*i.length)]:!i.length||!e?[]:Array.from({length:Math.min(e,i.length)},()=>i.splice(Math.floor(Math.random()*i.length),1)[0])}randomKey(e){let i=[...this.keys()];return typeof e=="undefined"?i[Math.floor(Math.random()*i.length)]:!i.length||!e?[]:Array.from({length:Math.min(e,i.length)},()=>i.splice(Math.floor(Math.random()*i.length),1)[0])}reverse(){let e=[...this.entries()].reverse();this.clear();for(let[i,t]of e)this.set(i,t);return this}find(e,i){typeof i!="undefined"&&(e=e.bind(i));for(let[t,l]of this)if(e(l,t,this))return l}findKey(e,i){typeof i!="undefined"&&(e=e.bind(i));for(let[t,l]of this)if(e(l,t,this))return t}sweep(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=this.size;for(let[l,o]of this)e(o,l,this)&&this.delete(l);return t-this.size}filter(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=new this.constructor[Symbol.species];for(let[l,o]of this)e(o,l,this)&&t.set(l,o);return t}partition(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=[new this.constructor[Symbol.species],new this.constructor[Symbol.species]];for(let[l,o]of this)e(o,l,this)?t[0].set(l,o):t[1].set(l,o);return t}flatMap(e,i){let t=this.map(e,i);return new this.constructor[Symbol.species]().concat(...t)}map(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=this.entries();return Array.from({length:this.size},()=>{let[l,o]=t.next().value;return e(o,l,this)})}mapValues(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=new this.constructor[Symbol.species];for(let[l,o]of this)t.set(l,e(o,l,this));return t}some(e,i){typeof i!="undefined"&&(e=e.bind(i));for(let[t,l]of this)if(e(l,t,this))return!0;return!1}every(e,i){typeof i!="undefined"&&(e=e.bind(i));for(let[t,l]of this)if(!e(l,t,this))return!1;return!0}reduce(e,i){let t;if(typeof i!="undefined"){t=i;for(let[o,u]of this)t=e(t,u,o,this);return t}let l=!0;for(let[o,u]of this){if(l){t=u,l=!1;continue}t=e(t,u,o,this)}if(l)throw new TypeError("Reduce of empty collection with no initial value");return t}each(e,i){return this.forEach(e,i),this}tap(e,i){return typeof i!="undefined"&&(e=e.bind(i)),e(this),this}clone(){return new this.constructor[Symbol.species](this)}concat(...e){let i=this.clone();for(let t of e)for(let[l,o]of t)i.set(l,o);return i}equals(e){if(!e)return!1;if(this===e)return!0;if(this.size!==e.size)return!1;for(let[i,t]of this)if(!e.has(i)||t!==e.get(i))return!1;return!0}sort(e=r.defaultSort){let i=[...this.entries()];i.sort((t,l)=>e(t[1],l[1],t[0],l[0])),super.clear();for(let[t,l]of i)super.set(t,l);return this}intersect(e){let i=new this.constructor[Symbol.species];for(let[t,l]of e)this.has(t)&&Object.is(l,this.get(t))&&i.set(t,l);return i}difference(e){let i=new this.constructor[Symbol.species];for(let[t,l]of e)this.has(t)||i.set(t,l);for(let[t,l]of this)e.has(t)||i.set(t,l);return i}sorted(e=r.defaultSort){return new this.constructor[Symbol.species](this).sort((i,t,l,o)=>e(i,t,l,o))}toJSON(){return[...this.values()]}static defaultSort(e,i){return Number(e>i)||Number(e===i)-1}},c=r;h(c,"Collection"),a(c,"default",r);var T=c;module.exports=v(k);0&&(module.exports={Collection}); | ||
var h=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var v=(o,e,i)=>e in o?h(o,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):o[e]=i;var k=o=>h(o,"__esModule",{value:!0}),p=(o,e)=>h(o,"name",{value:e,configurable:!0});var T=(o,e)=>{for(var i in e)h(o,i,{get:e[i],enumerable:!0})},C=(o,e,i,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of d(e))!b.call(o,l)&&(i||l!=="default")&&h(o,l,{get:()=>e[l],enumerable:!(t=y(e,l))||t.enumerable});return o};var m=(o=>(e,i)=>o&&o.get(e)||(i=C(k({}),e,1),o&&o.set(e,i),i))(typeof WeakMap!="undefined"?new WeakMap:0);var V=(o,e,i)=>(v(o,typeof e!="symbol"?e+"":e,i),i);var g={};T(g,{Collection:()=>a,default:()=>w});var u=class extends Map{ensure(e,i){if(this.has(e))return this.get(e);let t=i(e,this);return this.set(e,t),t}hasAll(...e){return e.every(i=>super.has(i))}hasAny(...e){return e.some(i=>super.has(i))}first(e){if(typeof e=="undefined")return this.values().next().value;if(e<0)return this.last(e*-1);e=Math.min(this.size,e);let i=this.values();return Array.from({length:e},()=>i.next().value)}firstKey(e){if(typeof e=="undefined")return this.keys().next().value;if(e<0)return this.lastKey(e*-1);e=Math.min(this.size,e);let i=this.keys();return Array.from({length:e},()=>i.next().value)}last(e){let i=[...this.values()];return typeof e=="undefined"?i[i.length-1]:e<0?this.first(e*-1):e?i.slice(-e):[]}lastKey(e){let i=[...this.keys()];return typeof e=="undefined"?i[i.length-1]:e<0?this.firstKey(e*-1):e?i.slice(-e):[]}at(e){return e=Math.floor(e),[...this.values()].at(e)}keyAt(e){return e=Math.floor(e),[...this.keys()].at(e)}random(e){let i=[...this.values()];return typeof e=="undefined"?i[Math.floor(Math.random()*i.length)]:!i.length||!e?[]:Array.from({length:Math.min(e,i.length)},()=>i.splice(Math.floor(Math.random()*i.length),1)[0])}randomKey(e){let i=[...this.keys()];return typeof e=="undefined"?i[Math.floor(Math.random()*i.length)]:!i.length||!e?[]:Array.from({length:Math.min(e,i.length)},()=>i.splice(Math.floor(Math.random()*i.length),1)[0])}reverse(){let e=[...this.entries()].reverse();this.clear();for(let[i,t]of e)this.set(i,t);return this}find(e,i){typeof i!="undefined"&&(e=e.bind(i));for(let[t,l]of this)if(e(l,t,this))return l}findKey(e,i){typeof i!="undefined"&&(e=e.bind(i));for(let[t,l]of this)if(e(l,t,this))return t}sweep(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=this.size;for(let[l,n]of this)e(n,l,this)&&this.delete(l);return t-this.size}filter(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=new this.constructor[Symbol.species];for(let[l,n]of this)e(n,l,this)&&t.set(l,n);return t}partition(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=[new this.constructor[Symbol.species],new this.constructor[Symbol.species]];for(let[l,n]of this)e(n,l,this)?t[0].set(l,n):t[1].set(l,n);return t}flatMap(e,i){let t=this.map(e,i);return new this.constructor[Symbol.species]().concat(...t)}map(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=this.entries();return Array.from({length:this.size},()=>{let[l,n]=t.next().value;return e(n,l,this)})}mapValues(e,i){typeof i!="undefined"&&(e=e.bind(i));let t=new this.constructor[Symbol.species];for(let[l,n]of this)t.set(l,e(n,l,this));return t}some(e,i){typeof i!="undefined"&&(e=e.bind(i));for(let[t,l]of this)if(e(l,t,this))return!0;return!1}every(e,i){typeof i!="undefined"&&(e=e.bind(i));for(let[t,l]of this)if(!e(l,t,this))return!1;return!0}reduce(e,i){let t;if(typeof i!="undefined"){t=i;for(let[n,r]of this)t=e(t,r,n,this);return t}let l=!0;for(let[n,r]of this){if(l){t=r,l=!1;continue}t=e(t,r,n,this)}if(l)throw new TypeError("Reduce of empty collection with no initial value");return t}each(e,i){return this.forEach(e,i),this}tap(e,i){return typeof i!="undefined"&&(e=e.bind(i)),e(this),this}clone(){return new this.constructor[Symbol.species](this)}concat(...e){let i=this.clone();for(let t of e)for(let[l,n]of t)i.set(l,n);return i}equals(e){if(!e)return!1;if(this===e)return!0;if(this.size!==e.size)return!1;for(let[i,t]of this)if(!e.has(i)||t!==e.get(i))return!1;return!0}sort(e=u.defaultSort){let i=[...this.entries()];i.sort((t,l)=>e(t[1],l[1],t[0],l[0])),super.clear();for(let[t,l]of i)super.set(t,l);return this}intersect(e){let i=new this.constructor[Symbol.species];for(let[t,l]of e)this.has(t)&&Object.is(l,this.get(t))&&i.set(t,l);return i}difference(e){let i=new this.constructor[Symbol.species];for(let[t,l]of e)this.has(t)||i.set(t,l);for(let[t,l]of this)e.has(t)||i.set(t,l);return i}merge(e,i,t,l){let n=new this.constructor[Symbol.species],r=new Set([...this.keys(),...e.keys()]);for(let s of r){let f=this.has(s),K=e.has(s);if(f&&K){let c=l(this.get(s),e.get(s),s);c.keep&&n.set(s,c.value)}else if(f){let c=i(this.get(s),s);c.keep&&n.set(s,c.value)}else if(K){let c=t(e.get(s),s);c.keep&&n.set(s,c.value)}}return n}sorted(e=u.defaultSort){return new this.constructor[Symbol.species](this).sort((i,t,l,n)=>e(i,t,l,n))}toJSON(){return[...this.values()]}static defaultSort(e,i){return Number(e>i)||Number(e===i)-1}static combineEntries(e,i){let t=new u;for(let[l,n]of e)t.has(l)?t.set(l,i(t.get(l),n,l)):t.set(l,n);return t}},a=u;p(a,"Collection"),V(a,"default",u);var w=a;module.exports=m(g);0&&(module.exports={Collection}); | ||
//# sourceMappingURL=index.js.map |
148
package.json
{ | ||
"name": "@discordjs/collection", | ||
"version": "0.5.0", | ||
"description": "Utility data structure used in discord.js", | ||
"scripts": { | ||
"test": "jest --pass-with-no-tests", | ||
"build": "tsup", | ||
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts", | ||
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix", | ||
"docs": "typedoc --json docs/typedoc-out.json src/index.ts && node scripts/docs.mjs", | ||
"prepublishOnly": "yarn build && yarn lint && yarn test", | ||
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/collection/*'" | ||
}, | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.js" | ||
}, | ||
"directories": { | ||
"lib": "src", | ||
"test": "__tests__" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"contributors": [ | ||
"Crawl <icrawltogo@gmail.com>", | ||
"Amish Shah <amishshah.2k@gmail.com>", | ||
"SpaceEEC <spaceeec@yahoo.com>", | ||
"Vlad Frangu <kingdgrizzle@gmail.com>", | ||
"Antonio Roman <kyradiscord@gmail.com>" | ||
], | ||
"license": "Apache-2.0", | ||
"keywords": [ | ||
"map", | ||
"collection", | ||
"utility" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/discordjs/discord.js.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/discordjs/discord.js/issues" | ||
}, | ||
"homepage": "https://discord.js.org", | ||
"devDependencies": { | ||
"@babel/core": "^7.16.12", | ||
"@babel/preset-env": "^7.16.11", | ||
"@babel/preset-typescript": "^7.16.5", | ||
"@discordjs/ts-docgen": "^0.3.4", | ||
"@types/jest": "^27.0.3", | ||
"@types/node": "^16.11.6", | ||
"@typescript-eslint/eslint-plugin": "^5.10.0", | ||
"@typescript-eslint/parser": "^5.10.0", | ||
"eslint": "^8.7.0", | ||
"eslint-config-marine": "^9.3.2", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"jest": "^27.4.7", | ||
"prettier": "^2.5.1", | ||
"standard-version": "^9.3.2", | ||
"tsup": "^5.11.11", | ||
"typedoc": "^0.22.11", | ||
"typescript": "^4.5.5" | ||
}, | ||
"engines": { | ||
"node": ">=16.9.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} | ||
"name": "@discordjs/collection", | ||
"version": "0.6.0-dev.1644067357.5f4b44d", | ||
"description": "Utility data structure used in discord.js", | ||
"scripts": { | ||
"test": "jest --pass-with-no-tests", | ||
"build": "tsup", | ||
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts", | ||
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix", | ||
"docs": "typedoc --json docs/typedoc-out.json src/index.ts && node scripts/docs.mjs", | ||
"prepublishOnly": "yarn build && yarn lint && yarn test", | ||
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/collection/*'" | ||
}, | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.js" | ||
}, | ||
"directories": { | ||
"lib": "src", | ||
"test": "__tests__" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"contributors": [ | ||
"Crawl <icrawltogo@gmail.com>", | ||
"Amish Shah <amishshah.2k@gmail.com>", | ||
"SpaceEEC <spaceeec@yahoo.com>", | ||
"Vlad Frangu <kingdgrizzle@gmail.com>", | ||
"Antonio Roman <kyradiscord@gmail.com>" | ||
], | ||
"license": "Apache-2.0", | ||
"keywords": [ | ||
"map", | ||
"collection", | ||
"utility" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/discordjs/discord.js.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/discordjs/discord.js/issues" | ||
}, | ||
"homepage": "https://discord.js.org", | ||
"devDependencies": { | ||
"@babel/core": "^7.17.0", | ||
"@babel/preset-env": "^7.16.11", | ||
"@babel/preset-typescript": "^7.16.5", | ||
"@discordjs/ts-docgen": "^0.3.4", | ||
"@types/jest": "^27.0.3", | ||
"@types/node": "^16.11.6", | ||
"@typescript-eslint/eslint-plugin": "^5.10.2", | ||
"@typescript-eslint/parser": "^5.10.2", | ||
"eslint": "^8.8.0", | ||
"eslint-config-marine": "^9.3.2", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"jest": "^27.4.7", | ||
"prettier": "^2.5.1", | ||
"tsup": "^5.11.13", | ||
"typedoc": "^0.22.11", | ||
"typescript": "^4.5.5" | ||
}, | ||
"engines": { | ||
"node": ">=16.9.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"stableVersion": "0.6.0-dev" | ||
} |
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
120357
17
467
9