1.0.22 • Published 3 years ago
giganto v1.0.22
Giganto
Installation
<script src="PATH/TO/index.js"></script>
npm i giganto
# or
yarn add giganto
const _ = require('giganto');
const array = [0, 1, false, 2, '', 3, NaN, 4, undefined, 5, 6, Boolean(0)];
_.compact(array);
// => [0, 1, 2, 3, 4, 5, 6]
import _ from 'giganto';
const array = [
{ user: 'Ben', active: false },
{ user: 'Vic', active: true },
{ user: 'Nat', active: false },
{ user: 'Den', active: false },
];
_.dropRightWhile(array, ({ active }) => !active);
// => [{ user: 'Ben', active: false }, { user: 'Vic', active: true }]
Why Giganto?
Usage
_.chunk(['a', 'b', 'c', 'd'], 2);
// => [['a', 'b'], ['c', 'd']]
_.chunk(['a', 'b', 'c', 'd'], 3);
// => [['a', 'b', 'c'], ['d']]
_.compact([0, 1, false, 2, '', 3, NaN, 4, undefined, 5, 6, Boolean(0)]);
// => [0, 1, 2, 3, 4, 5, 6]
const array = [1, { user: 'Vic' }];
_.concat(array, 2, [3], [[4]], { user: 'Nat' });
// => [1, { user: 'Vic' }, 2, [3], [[4]], { user: 'Nat' }]
console.log(array);
// => [1, { user: 'Vic' }]
_.difference([2, 1], [2, 3]);
// => [1]
_.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
// => [1.2]
_.differenceBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], ({ x }) => x);
// => [{ 'x': 2 }]
_.differenceWith([1, 2, 3, 6], [4, 5, 2, 2, 1], _.isEqual);
// => [3, 6]
_.differenceWith([{ x: 2 }, { x: 1 }], [{ x: 1 }], (a, b) => a.x === b.x);
// => [{ 'x': 2 }]
_.drop([1, 2, 3]);
// => [2, 3]
_.drop([1, 2, 3], 2);
// => [3]
_.drop([1, 2, 3], 5);
// => []
_.drop([1, 2, 3], 0);
// => [1, 2, 3]
_.dropRight([1, 2, 3]);
// => [1, 2]
_.dropRight([1, 2, 3], 2);
// => [1]
_.dropRight([1, 2, 3], 5);
// => []
_.dropRight([1, 2, 3], 0);
// => [1, 2, 3]
const users = [
{ user: 'Ben', active: false },
{ user: 'Vic', active: true },
{ user: 'Nat', active: false },
{ user: 'Den', active: false },
];
_.dropRightWhile(users, ({ active }) => !active);
// => [{ user: 'Ben', active: false }, { user: 'Vic', active: true }]
const users = [
{ user: 'Ben', active: false },
{ user: 'Vic', active: true },
{ user: 'Nat', active: false },
{ user: 'Den', active: false },
];
_.dropWhile(users, ({ active }) => !active);
// => [{ user: 'Vic', active: true }, { user: 'Nat', active: false }, { user: 'Den', active: false }]
_.fill([1, 2, 3, 4], 'N', 0, -2);
// => ['N', 'N', 3, 4]
_.fill([1, 2, 3, 4], 'N', 1, 3);
// => [1, 'N', 'N', 4]
const users = [
{ user: 'Ben', active: false },
{ user: 'Vic', active: true },
{ user: 'Nat', active: false },
{ user: 'Den', active: false },
];
_.findIndex(users, ({ user }) => user === 'Vic');
// => 1
const users = [
{ user: 'Ben', active: false },
{ user: 'Vic', active: true },
{ user: 'Nat', active: false },
{ user: 'Den', active: false },
];
_.findLastIndex(users, ({ user }) => user !== 'Den');
// => 2
_.flatten([1, [2, [3, [4]], 5]]);
// => [1, 2, [3, [4]], 5]
_.flatten([1, [2, [3, [4]], 5]], 5);
// => [1, 2, 3, 4, 5]
_.fromPairs([
['a', 1],
['b', 2],
['a', 2],
]);
// => {a: 2, b: 2}
const users = [
{ user: 'Vic', active: true },
{ user: 'Nat', active: false },
{ user: 'Den', active: false },
];
_.head(users);
// => { user: 'Vic', active: true }
_.indexOf([1, 2, 1, 2, 5], 2);
// => 1
_.indexOf([1, 2, 1, 2, 5], 2, 3);
// => 3
_.initial([1, 2, 3]);
// => [1, 2]
_.intersection([2, 1], [2, 3]);
// => [2]
_.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
// => [2.1]
_.intersectionBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], ({ x }) => x);
// => [{ 'x': 1 }]
_.intersectionWith([1, 2, 3, 6], [4, 5, 2, 2, 1], _.isEqual);
// => [1, 2]
_.intersectionWith([{ x: 2 }, { x: 1 }], [{ x: 1 }], (a, b) => a.x === b.x);
// => [{ 'x': 1 }]
_.join(['a', 'b', 'c'], '~');
// => 'a~b~c'
const users = [
{ user: 'Vic', active: true },
{ user: 'Nat', active: false },
{ user: 'Den', active: false },
];
_.last(users);
// => { user: 'Den', active: false }
_.lastIndexOf([1, 2, 1, 2, 5], 2);
// => 3
const users = [
{ user: 'Ben', active: false },
{ user: 'Vic', active: true },
{ user: 'Nat', active: false },
{ user: 'Den', active: false },
];
_.nth(users, 2);
// => { user: 'Nat', active: false }
_.nth(users, -3);
// => { user: 'Vic', active: true }
const array = ['a', 'b', 'c', 'a', 'b', 'c'];
_.pull(array, 'a', 'c');
console.log(array);
// => ['b', 'b']
const array = ['a', 'b', 'c', 'a', 'b', 'c'];
_.pullAll(array, ['a', 'c']);
console.log(array);
// => ['b', 'b']
const users = [
{ user: 'Ben', active: false },
{ user: 'Vic', active: true },
{ user: 'Nat', active: false },
{ user: 'Den', active: false },
];
_.pullAllBy(
users,
[
{ user: 'Vic', active: true },
{ user: 'Nat', active: false },
],
({ user }) => user,
);
console.log(users);
// => [{ user: 'Ben', active: false }, { user: 'Den', active: false }]
const array = [
{ x: 1, y: 2 },
{ x: 3, y: 4 },
{ x: 5, y: 6 },
];
_.pullAllWith(array, [{ x: 3, y: 4 }], _.isEqual);
console.log(array);
// => [{ x: 1, y: 2 }, { x: 5, y: 6 }]
const array = ['a', 'b', 'c', 'd'];
_.pullAt(array, [0, 2]);
// => ['b', 'd']
console.log(array);
// => ['a', 'c']
const users = [
{ user: 'Ben', active: false },
{ user: 'Vic', active: true },
{ user: 'Nat', active: false },
{ user: 'Den', active: false },
];
const array = _.remove(users, ({ active }) => !active);
console.log(users);
// => [{ user: 'Vic', active: true }]
console.log(array);
// => [{ user: 'Ben', active: false }, { user: 'Nat', active: false }, { user: 'Den', active: false }]
const array = [1, 2, 3];
_.reverse(array);
// => [3, 2, 1]
console.log(array);
// => [3, 2, 1]
const array = [1, 2, 3];
_.slice(array, 1, 2);
// => [2]
_.slice(array, 1);
// => [2, 3]
const array = [30, 50, 60, 70];
_.sortedIndex(array, 40);
// => 1
const users = [
{ user: 'Ben', age: 30 },
{ user: 'Nat', age: 50 },
{ user: 'Den', age: 60 },
];
_.sortedIndexBy(users, { user: 'Vic', age: 40 }, ({ age }) => age);
// => 1
const array = [40, 50, 50, 50, 60];
_.sortedIndexOf(array, 50);
// => 1
_.sortedIndexOf(array, 41);
// => -1
const array = [4, 5, 5, 5, 6];
_.sortedIndexBy(array, 5);
// => 4
const users = [
{ user: 'Ben', age: 30 },
{ user: 'Vic', age: 40 },
{ user: 'Vic', age: 40 },
{ user: 'Nat', age: 50 },
{ user: 'Den', age: 60 },
];
_.sortedLastIndexBy(users, { user: 'Vic', age: 40 }, ({ age }) => age);
// => 3
const array = [40, 50, 50, 50, 60];
_.sortedIndexOf(array, 50);
// => 3
_.sortedIndexOf(array, 41);
// => -1
_.tail([1, 2, 3]);
// => [2, 3]
_.take([1, 2, 3]);
// => [1]
_.take([1, 2, 3], 2);
// => [1, 2]
_.take([1, 2, 3], 5);
// => [1, 2, 3]
_.take([1, 2, 3], 0);
// => []
_.take([1, 2, 3], -1);
// => []
_.takeRight([1, 2, 3]);
// => [3]
_.takeRight([1, 2, 3], 2);
// => [2, 3]
_.takeRight([1, 2, 3], 5);
// => [1, 2, 3]
_.takeRight([1, 2, 3], 0);
// => []
_.takeRight([1, 2, 3], -1);
// => []
const users = [
{ user: 'Ben', active: false },
{ user: 'Vic', active: true },
{ user: 'Nat', active: false },
{ user: 'Den', active: false },
];
_.takeRightWhile(users, ({ active }) => !active);
// => [{ user: 'Nat', active: false }, { user: 'Den', active: false }]
const users = [
{ user: 'Ben', active: true },
{ user: 'Vic', active: true },
{ user: 'Nat', active: false },
{ user: 'Den', active: true },
];
_.takeWhile(users, ({ active }) => active);
// => [{ user: 'Ben', active: true }, { user: 'Vic', active: true }]
_.union([2], [1, 2, 5, 2]);
// => [2, 1, 5]
_.union(2, 2, 3, 3, 1);
// => [2, 3, 1]
_.union(2, 2, 3, 3, 1, [4], [1]);
// => [2, 3, 1, 4]
_.unionBy([2.1], [1.2, 2.3], Math.floor);
// => [2.1, 1.2]
const users = [
{ user: 'Ben', active: false },
{ user: 'Vic', active: true },
{ user: 'Nat', active: false },
{ user: 'Den', active: false },
];
_.unionBy(users, [{ user: 'Nat', active: true }], [{ user: 'Lat', active: false }], ({ active }) => active);
// => [{ user: 'Ben', active: false }, { user: 'Vic', active: true }]
const objects = [
{ x: 1, y: 2 },
{ x: 2, y: 1 },
];
const others = [
{ x: 1, y: 1 },
{ x: 1, y: 2 },
];
_.unionWith(objects, others, ({ x }) => isEqual(x, 2));
// => [{x: 2, y: 1}]
const users = [
{ user: 'Ben', active: false },
{ user: 'Vic', active: true },
{ user: 'Nat', active: false },
{ user: 'Den', active: false },
];
_.unionWith(
users,
[{ user: 'Nat', active: true }],
[{ user: 'Nat', active: false }],
({ user }) => user.startsWith('N') && user.endsWith('t'),
);
// => [{ user: 'Nat', active: false }, { user: 'Nat', active: true }]
_.uniq([2, 1, 2]);
// => [2, 1]
_.uniqBy([2.1, 1.2, 2.3], Math.floor);
// => [2.1, 1.2]
const users = [
{ user: 'Ben', active: false },
{ user: 'Vic', active: true },
{ user: 'Nat', active: false },
{ user: 'Den', active: false },
];
_.uniqBy(users, ({ active }) => active);
// => [{ user: 'Ben', active: false }, { user: 'Vic', active: true }]
const objects = [
{ x: 1, y: 2 },
{ x: 2, y: 1 },
{ x: 1, y: 1 },
{ x: 1, y: 2 },
];
_.uniqWith(objects, ({ y }) => isEqual(y, 2));
// => [{ x: 1, y: 2 }]
const users = [
{ user: 'Ben', active: false },
{ user: 'Vic', active: true },
{ user: 'Nat', active: false },
{ user: 'Den', active: false },
{ user: 'Nat', active: true },
{ user: 'Nat', active: false },
];
_.uniqWith(users, ({ user }) => user.startsWith('N') && user.endsWith('t'));
// => [{ user: 'Nat', active: false }, { user: 'Nat', active: true }]
const zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
// => [['a', 1, true], ['b', 2, false]]
_.unzip(zipped);
// => [['a', 'b'], [1, 2], [true, false]]
const array = zip([1, 2], [10, 20], [100, 200]);
// => [[1, 10, 100], [2, 20, 200]]
_.unzipWith(array, (a, b) => a + b);
// => [3, 30, 300]
_.without([2, 1, 2, 3], 1, 2);
// => [3]
_.xor([2, 1], [2, 3]);
// => [1, 3]
_.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
// => [1.2, 3.4]
const users = [
{ user: 'Ben', active: false },
{ user: 'Vic', active: true },
{ user: 'Nat', active: false },
{ user: 'Den', active: false },
];
_.xorBy(
users,
[
{ user: 'Nat', active: false },
{ user: 'Vic', active: true },
],
({ user }) => user,
);
// => [{ user: 'Ben', active: false }, { user: 'Den', active: false }]
const objects = [
{ x: 1, y: 2 },
{ x: 2, y: 1 },
];
const others = [
{ x: 1, y: 1 },
{ x: 1, y: 2 },
];
_.xorWith(objects, others, _.isEqual);
// => [{ x: 2, y: 1 }, { x: 1, y: 1 }]
_.zip(['a', 'b'], [1, 2, 3], [true, false]);
// => [['a', 1, true], ['b', 2, false], [undefined, 3, undefined]]
_.zipWith([1, 2, 5, 6], [10, 20, 5, 5], [100, 200, 5, 6], (a, b, c) => a + b + c);
// => [111, 222, 15, 17]
1.0.19
3 years ago
1.0.18
3 years ago
1.0.17
3 years ago
1.0.16
3 years ago
1.0.9
3 years ago
1.0.8
3 years ago
1.0.7
3 years ago
1.0.6
3 years ago
1.0.5
3 years ago
1.0.4
3 years ago
1.0.3
3 years ago
1.0.22
3 years ago
1.0.21
3 years ago
1.0.20
3 years ago
1.0.11
3 years ago
1.0.10
3 years ago
1.0.15
3 years ago
1.0.14
3 years ago
1.0.13
3 years ago
1.0.12
3 years ago
1.0.2
3 years ago
1.0.1
3 years ago
1.0.0
3 years ago