@discordjs/collection
Advanced tools
Comparing version 3.0.0-dev.1732925557-f5445c810 to 3.0.0-dev.1733141130-5f0d28c0f
@@ -375,6 +375,7 @@ /** | ||
* The sort method sorts the items of a collection in place and returns it. | ||
* The default sort order is according to string Unicode code points. | ||
* If a comparison function is not provided, the function sorts by element values, using the same stringwise comparison algorithm as | ||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort | Array.sort()}. | ||
* | ||
* @param compareFunction - Specifies a function that defines the sort order. | ||
* If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element. | ||
* @param compareFunction - Specifies a function that defines the sort order. The return value of this function should be negative if | ||
* `a` comes before `b`, positive if `b` comes before `a`, or zero if `a` and `b` are considered equal. | ||
* @example | ||
@@ -481,11 +482,11 @@ * ```ts | ||
/** | ||
* The sorted method sorts the items of a collection and returns it. | ||
* The default sort order is according to string Unicode code points. | ||
* The toSorted method returns a shallow copy of the collection with the items sorted. | ||
* If a comparison function is not provided, the function sorts by element values, using the same stringwise comparison algorithm as | ||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort | Array.sort()}. | ||
* | ||
* @param compareFunction - Specifies a function that defines the sort order. | ||
* If omitted, the collection is sorted according to each character's Unicode code point value, | ||
* according to the string conversion of each element. | ||
* @param compareFunction - Specifies a function that defines the sort order. The return value of this function should be negative if | ||
* `a` comes before `b`, positive if `b` comes before `a`, or zero if `a` and `b` are considered equal. | ||
* @example | ||
* ```ts | ||
* collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp); | ||
* const sortedCollection = collection.toSorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp); | ||
* ``` | ||
@@ -495,2 +496,7 @@ */ | ||
toJSON(): [Key, Value][]; | ||
/** | ||
* Emulates the default sort comparison algorithm used in ECMAScript. Equivalent to calling the | ||
* {@link https://tc39.es/ecma262/multipage/indexed-collections.html#sec-comparearrayelements | CompareArrayElements} | ||
* operation with arguments `firstValue`, `secondValue` and `undefined`. | ||
*/ | ||
private static defaultSort; | ||
@@ -497,0 +503,0 @@ /** |
@@ -386,6 +386,7 @@ "use strict"; | ||
* The sort method sorts the items of a collection in place and returns it. | ||
* The default sort order is according to string Unicode code points. | ||
* If a comparison function is not provided, the function sorts by element values, using the same stringwise comparison algorithm as | ||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort | Array.sort()}. | ||
* | ||
* @param compareFunction - Specifies a function that defines the sort order. | ||
* If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element. | ||
* @param compareFunction - Specifies a function that defines the sort order. The return value of this function should be negative if | ||
* `a` comes before `b`, positive if `b` comes before `a`, or zero if `a` and `b` are considered equal. | ||
* @example | ||
@@ -549,11 +550,11 @@ * ```ts | ||
/** | ||
* The sorted method sorts the items of a collection and returns it. | ||
* The default sort order is according to string Unicode code points. | ||
* The toSorted method returns a shallow copy of the collection with the items sorted. | ||
* If a comparison function is not provided, the function sorts by element values, using the same stringwise comparison algorithm as | ||
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort | Array.sort()}. | ||
* | ||
* @param compareFunction - Specifies a function that defines the sort order. | ||
* If omitted, the collection is sorted according to each character's Unicode code point value, | ||
* according to the string conversion of each element. | ||
* @param compareFunction - Specifies a function that defines the sort order. The return value of this function should be negative if | ||
* `a` comes before `b`, positive if `b` comes before `a`, or zero if `a` and `b` are considered equal. | ||
* @example | ||
* ```ts | ||
* collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp); | ||
* const sortedCollection = collection.toSorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp); | ||
* ``` | ||
@@ -567,4 +568,15 @@ */ | ||
} | ||
/** | ||
* Emulates the default sort comparison algorithm used in ECMAScript. Equivalent to calling the | ||
* {@link https://tc39.es/ecma262/multipage/indexed-collections.html#sec-comparearrayelements | CompareArrayElements} | ||
* operation with arguments `firstValue`, `secondValue` and `undefined`. | ||
*/ | ||
static defaultSort(firstValue, secondValue) { | ||
return Number(firstValue > secondValue) || Number(firstValue === secondValue) - 1; | ||
if (firstValue === void 0) return secondValue === void 0 ? 0 : 1; | ||
if (secondValue === void 0) return -1; | ||
const x = String(firstValue); | ||
const y = String(secondValue); | ||
if (x < y) return -1; | ||
if (y < x) return 1; | ||
return 0; | ||
} | ||
@@ -596,3 +608,3 @@ /** | ||
// src/index.ts | ||
var version = "3.0.0-dev.1732925557-f5445c810"; | ||
var version = "3.0.0-dev.1733141130-5f0d28c0f"; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -599,0 +611,0 @@ 0 && (module.exports = { |
{ | ||
"$schema": "https://json.schemastore.org/package.json", | ||
"name": "@discordjs/collection", | ||
"version": "3.0.0-dev.1732925557-f5445c810", | ||
"version": "3.0.0-dev.1733141130-5f0d28c0f", | ||
"description": "Utility data structure used in discord.js", | ||
@@ -65,4 +65,4 @@ "exports": { | ||
"vitest": "^2.1.5", | ||
"@discordjs/scripts": "^0.1.0", | ||
"@discordjs/api-extractor": "^7.38.1" | ||
"@discordjs/api-extractor": "^7.38.1", | ||
"@discordjs/scripts": "^0.1.0" | ||
}, | ||
@@ -69,0 +69,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
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
224344
1721
0