Socket
Socket
Sign inDemoInstall

es-toolkit

Package Overview
Dependencies
Maintainers
2
Versions
740
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es-toolkit - npm Package Compare versions

Comparing version 1.8.0 to 1.9.0-dev.170

dist/array/flatten.d.mts

9

CHANGELOG.md
# es-toolkit Changelog
## Version v1.9.0
Released on July 10th, 2024.
- Add support for [head](https://es-toolkit.slash.page/reference/array/head.html) and [tail](https://es-toolkit.slash.page/reference/array/tail.html). (https://github.com/toss/es-toolkit/pull/131, https://github.com/toss/es-toolkit/pull/143).
- Add support for [unzip](https://es-toolkit.slash.page/reference/array/unzip.html). (https://github.com/toss/es-toolkit/pull/130)
- Add support for [flatten](https://es-toolkit.slash.page/reference/array/flatten.html), which is six times faster than `Array#flat`. (https://github.com/toss/es-toolkit/pull/147)
## Version v1.8.0

@@ -4,0 +13,0 @@

4

dist/array/index.d.ts

@@ -12,2 +12,3 @@ export { chunk } from './chunk.js';

export { fill } from './fill.js';
export { flatten } from './flatten.js';
export { forEachRight } from './forEachRight.js';

@@ -36,2 +37,3 @@ export { groupBy } from './groupBy.js';

export { uniqWith } from './uniqWith.js';
export { unzip } from './unzip.js';
export { unzipWith } from './unzipWith.js';

@@ -45,1 +47,3 @@ export { xor } from './xor.js';

export { without } from './without.js';
export { head } from './head.js';
export { tail } from './tail.js';

@@ -34,4 +34,6 @@ "use strict";

fill: () => fill,
flatten: () => flatten,
forEachRight: () => forEachRight,
groupBy: () => groupBy,
head: () => head,
intersection: () => intersection,

@@ -48,2 +50,3 @@ intersectionBy: () => intersectionBy,

shuffle: () => shuffle,
tail: () => tail,
take: () => take,

@@ -59,2 +62,3 @@ takeRight: () => takeRight,

uniqWith: () => uniqWith,
unzip: () => unzip,
unzipWith: () => unzipWith,

@@ -167,2 +171,19 @@ without: () => without,

// src/array/flatten.ts
function flatten(arr, depth = 1) {
const result = [];
const flooredDepth = Math.floor(depth);
const recursive = (arr2, currentDepth) => {
for (const item of arr2) {
if (Array.isArray(item) && currentDepth < flooredDepth) {
recursive(item, currentDepth + 1);
} else {
result.push(item);
}
}
};
recursive(arr, 0);
return result;
}
// src/array/forEachRight.ts

@@ -426,2 +447,20 @@ function forEachRight(arr, callback) {

// src/array/unzip.ts
function unzip(zipped) {
let maxLen = 0;
for (let i = 0; i < zipped.length; i++) {
if (zipped[i].length > maxLen) {
maxLen = zipped[i].length;
}
}
const result = new Array(maxLen);
for (let i = 0; i < maxLen; i++) {
result[i] = new Array(zipped.length);
for (let j = 0; j < zipped.length; j++) {
result[i][j] = zipped[j][i];
}
}
return result;
}
// src/array/unzipWith.ts

@@ -501,2 +540,20 @@ function unzipWith(target, iteratee) {

}
// src/array/head.ts
function head(arr) {
return arr[0];
}
// src/array/tail.ts
function tail(arr) {
const len = arr.length;
if (len <= 1) {
return [];
}
const result = new Array(len - 1);
for (let i = 1; i < len; i++) {
result[i - 1] = arr[i];
}
return result;
}
// Annotate the CommonJS export names for ESM import in node:

@@ -515,4 +572,6 @@ 0 && (module.exports = {

fill,
flatten,
forEachRight,
groupBy,
head,
intersection,

@@ -529,2 +588,3 @@ intersectionBy,

shuffle,
tail,
take,

@@ -540,2 +600,3 @@ takeRight,

uniqWith,
unzip,
unzipWith,

@@ -542,0 +603,0 @@ without,

@@ -12,2 +12,3 @@ export { chunk } from './array/chunk.js';

export { fill } from './array/fill.js';
export { flatten } from './array/flatten.js';
export { forEachRight } from './array/forEachRight.js';

@@ -36,2 +37,3 @@ export { groupBy } from './array/groupBy.js';

export { uniqWith } from './array/uniqWith.js';
export { unzip } from './array/unzip.js';
export { unzipWith } from './array/unzipWith.js';

@@ -45,2 +47,4 @@ export { xor } from './array/xor.js';

export { without } from './array/without.js';
export { head } from './array/head.js';
export { tail } from './array/tail.js';
export { AbortError } from './error/AbortError.js';

@@ -47,0 +51,0 @@ export { debounce } from './function/debounce.js';

@@ -52,4 +52,6 @@ "use strict";

fill: () => fill,
flatten: () => flatten,
forEachRight: () => forEachRight,
groupBy: () => groupBy,
head: () => head,
inRange: () => inRange,

@@ -85,2 +87,3 @@ intersection: () => intersection,

sum: () => sum,
tail: () => tail,
take: () => take,

@@ -97,2 +100,3 @@ takeRight: () => takeRight,

uniqWith: () => uniqWith,
unzip: () => unzip,
unzipWith: () => unzipWith,

@@ -205,2 +209,19 @@ without: () => without,

// src/array/flatten.ts
function flatten(arr, depth = 1) {
const result = [];
const flooredDepth = Math.floor(depth);
const recursive = (arr2, currentDepth) => {
for (const item of arr2) {
if (Array.isArray(item) && currentDepth < flooredDepth) {
recursive(item, currentDepth + 1);
} else {
result.push(item);
}
}
};
recursive(arr, 0);
return result;
}
// src/array/forEachRight.ts

@@ -464,2 +485,20 @@ function forEachRight(arr, callback) {

// src/array/unzip.ts
function unzip(zipped) {
let maxLen = 0;
for (let i = 0; i < zipped.length; i++) {
if (zipped[i].length > maxLen) {
maxLen = zipped[i].length;
}
}
const result = new Array(maxLen);
for (let i = 0; i < maxLen; i++) {
result[i] = new Array(zipped.length);
for (let j = 0; j < zipped.length; j++) {
result[i][j] = zipped[j][i];
}
}
return result;
}
// src/array/unzipWith.ts

@@ -540,2 +579,20 @@ function unzipWith(target, iteratee) {

// src/array/head.ts
function head(arr) {
return arr[0];
}
// src/array/tail.ts
function tail(arr) {
const len = arr.length;
if (len <= 1) {
return [];
}
const result = new Array(len - 1);
for (let i = 1; i < len; i++) {
result[i - 1] = arr[i];
}
return result;
}
// src/error/AbortError.ts

@@ -784,4 +841,6 @@ var AbortError = class extends Error {

fill,
flatten,
forEachRight,
groupBy,
head,
inRange,

@@ -817,2 +876,3 @@ intersection,

sum,
tail,
take,

@@ -829,2 +889,3 @@ takeRight,

uniqWith,
unzip,
unzipWith,

@@ -831,0 +892,0 @@ without,

11

dist/math/range.d.ts
/**
* Returns an array of numbers from `start` to `end`, incrementing by `step`.
*
* If `step` is not provided, it defaults to `1` for an
* ascending range and `-1` for a descending range.
* If `step` is not provided, it defaults to `1`.
*
* @param {number} start - The starting number of the range.
* @param {number} [end] - The end number of the range.
* @param {number} [step] - The step value for the range.
* @param {number} start - The starting number of the range (inclusive).
* @param {number} [end] - The end number of the range (exclusive).
* @param {number} [step] - The step value for the range. (default: 1)
* @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.

@@ -21,3 +20,3 @@ *

* @example
* // Returns []
* // Returns [0, -1, -2, -3]
* range(0, -4, -1);

@@ -24,0 +23,0 @@ *

@@ -19,3 +19,2 @@ /**

*/
type PropertyKey = string | number | symbol;
declare function invert<K extends PropertyKey, V extends PropertyKey>(obj: Record<K, V>): {

@@ -22,0 +21,0 @@ [key in V]: K;

{
"name": "es-toolkit",
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
"version": "1.8.0",
"version": "1.9.0-dev.170+85d46286",
"homepage": "https://es-toolkit.slash.page",

@@ -6,0 +6,0 @@ "bugs": "https://github.com/toss/es-toolkit/issues",

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

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

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc