@rushstack/node-core-library
Advanced tools
Comparing version 3.50.2 to 3.51.0
@@ -11,3 +11,2 @@ /** | ||
export declare class LegacyAdapters { | ||
private static _useTimsort; | ||
/** | ||
@@ -29,5 +28,6 @@ * This function wraps a function with a callback in a promise. | ||
* | ||
* @deprecated | ||
* Use native Array.sort(), since Node < 14 is no longer supported | ||
* @remarks | ||
* On NodeJS 11.x and later, this method simply calls the native `Array.sort()`. | ||
* For earlier versions, it uses an implementation of Timsort, which is the same algorithm used by modern NodeJS. | ||
*/ | ||
@@ -34,0 +34,0 @@ static sortStable<T>(array: T[], compare?: (a: T, b: T) => number): void; |
"use strict"; | ||
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
// See LICENSE in the project root for license information. | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LegacyAdapters = void 0; | ||
const timsort_1 = require("timsort"); | ||
const semver = __importStar(require("semver")); | ||
/** | ||
@@ -89,20 +64,12 @@ * Helper functions used when interacting with APIs that do not follow modern coding practices. | ||
* | ||
* @deprecated | ||
* Use native Array.sort(), since Node < 14 is no longer supported | ||
* @remarks | ||
* On NodeJS 11.x and later, this method simply calls the native `Array.sort()`. | ||
* For earlier versions, it uses an implementation of Timsort, which is the same algorithm used by modern NodeJS. | ||
*/ | ||
static sortStable(array, compare) { | ||
if (LegacyAdapters._useTimsort === undefined) { | ||
LegacyAdapters._useTimsort = semver.major(process.versions.node) < 11; | ||
} | ||
if (LegacyAdapters._useTimsort) { | ||
(0, timsort_1.sort)(array, compare); | ||
} | ||
else { | ||
Array.prototype.sort.call(array, compare); | ||
} | ||
Array.prototype.sort.call(array, compare); | ||
} | ||
} | ||
exports.LegacyAdapters = LegacyAdapters; | ||
LegacyAdapters._useTimsort = undefined; | ||
//# sourceMappingURL=LegacyAdapters.js.map |
/** | ||
* Operations for sorting collections. | ||
* | ||
* @remarks | ||
* NOTE: Prior to Node 11.x, the `Array.sort()` algorithm is not guaranteed to be stable. For maximum | ||
* compatibility, consider using {@link LegacyAdapters.sortStable} instead of `Array.sort()`. | ||
* | ||
* @public | ||
@@ -42,7 +38,7 @@ */ | ||
/** | ||
* Returns true if the array is already sorted. | ||
* Returns true if the collection is already sorted. | ||
*/ | ||
static isSorted<T>(array: T[], comparer?: (x: any, y: any) => number): boolean; | ||
static isSorted<T>(collection: Iterable<T>, comparer?: (x: any, y: any) => number): boolean; | ||
/** | ||
* Returns true if the array is already sorted by the specified key. | ||
* Returns true if the collection is already sorted by the specified key. | ||
* | ||
@@ -56,3 +52,3 @@ * @example | ||
*/ | ||
static isSortedBy<T>(array: T[], keySelector: (element: T) => any, comparer?: (x: any, y: any) => number): boolean; | ||
static isSortedBy<T>(collection: Iterable<T>, keySelector: (element: T) => any, comparer?: (x: any, y: any) => number): boolean; | ||
/** | ||
@@ -59,0 +55,0 @@ * Sorts the entries in a Map object according to the map keys. |
@@ -6,10 +6,5 @@ "use strict"; | ||
exports.Sort = void 0; | ||
const LegacyAdapters_1 = require("./LegacyAdapters"); | ||
/** | ||
* Operations for sorting collections. | ||
* | ||
* @remarks | ||
* NOTE: Prior to Node 11.x, the `Array.sort()` algorithm is not guaranteed to be stable. For maximum | ||
* compatibility, consider using {@link LegacyAdapters.sortStable} instead of `Array.sort()`. | ||
* | ||
* @public | ||
@@ -80,11 +75,12 @@ */ | ||
comparer = Sort.compareByValue) { | ||
LegacyAdapters_1.LegacyAdapters.sortStable(array, (x, y) => comparer(keySelector(x), keySelector(y))); | ||
array.sort((x, y) => comparer(keySelector(x), keySelector(y))); | ||
} | ||
/** | ||
* Returns true if the array is already sorted. | ||
* Returns true if the collection is already sorted. | ||
*/ | ||
static isSorted(collection, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
static isSorted(array, comparer = Sort.compareByValue) { | ||
comparer = Sort.compareByValue) { | ||
let previous = undefined; | ||
for (const element of array) { | ||
for (const element of collection) { | ||
if (comparer(previous, element) > 0) { | ||
@@ -98,3 +94,3 @@ return false; | ||
/** | ||
* Returns true if the array is already sorted by the specified key. | ||
* Returns true if the collection is already sorted by the specified key. | ||
* | ||
@@ -108,3 +104,3 @@ * @example | ||
*/ | ||
static isSortedBy(array, | ||
static isSortedBy(collection, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
@@ -115,3 +111,3 @@ keySelector, | ||
let previousKey = undefined; | ||
for (const element of array) { | ||
for (const element of collection) { | ||
const key = keySelector(element); | ||
@@ -171,8 +167,8 @@ if (comparer(previousKey, key) > 0) { | ||
keySelector, keyComparer = Sort.compareByValue) { | ||
const array = Array.from(set); | ||
// Sorting a set is expensive, so first check whether it's already sorted. | ||
if (Sort.isSortedBy(array, keySelector, keyComparer)) { | ||
if (Sort.isSortedBy(set, keySelector, keyComparer)) { | ||
return; | ||
} | ||
LegacyAdapters_1.LegacyAdapters.sortStable(array, (x, y) => keyComparer(keySelector(x), keySelector(y))); | ||
const array = Array.from(set); | ||
array.sort((x, y) => keyComparer(keySelector(x), keySelector(y))); | ||
set.clear(); | ||
@@ -199,8 +195,8 @@ for (const item of array) { | ||
static sortSet(set, comparer = Sort.compareByValue) { | ||
const array = Array.from(set); | ||
// Sorting a set is expensive, so first check whether it's already sorted. | ||
if (Sort.isSorted(array, comparer)) { | ||
if (Sort.isSorted(set, comparer)) { | ||
return; | ||
} | ||
LegacyAdapters_1.LegacyAdapters.sortStable(array, (x, y) => comparer(x, y)); | ||
const array = Array.from(set); | ||
array.sort((x, y) => comparer(x, y)); | ||
set.clear(); | ||
@@ -207,0 +203,0 @@ for (const item of array) { |
{ | ||
"name": "@rushstack/node-core-library", | ||
"version": "3.50.2", | ||
"version": "3.51.0", | ||
"description": "Core libraries that every NodeJS toolchain project should use", | ||
@@ -21,3 +21,2 @@ "main": "lib/index.js", | ||
"semver": "~7.3.0", | ||
"timsort": "~0.3.0", | ||
"z-schema": "~5.0.2" | ||
@@ -33,4 +32,3 @@ }, | ||
"@types/resolve": "1.17.1", | ||
"@types/semver": "7.3.5", | ||
"@types/timsort": "0.3.0" | ||
"@types/semver": "7.3.5" | ||
}, | ||
@@ -37,0 +35,0 @@ "scripts": { |
Sorry, the diff of this file is too big to display
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
8
8
1012411
13279
- Removedtimsort@~0.3.0
- Removedtimsort@0.3.0(transitive)