Comparing version 2.2.0 to 2.3.0
@@ -1,1 +0,10 @@ | ||
export default function chunk<T>(array: Array<T>, size: number): Array<Array<T>>; | ||
/** | ||
* Groups the array elements into chunks of the given size. | ||
* | ||
* @param array - The array to generate chunks from | ||
* @param size - The size of a chunk | ||
* @returns An array of chunks of the given size | ||
* | ||
* @public | ||
*/ | ||
export default function chunk<ElementType>(array: ElementType[], size: number): ElementType[][]; |
'use strict' | ||
exports['default'] = chunk | ||
exports.default = chunk | ||
/** | ||
* Groups the array elements into chunks of the given size. | ||
* | ||
* @param array - The array to generate chunks from | ||
* @param size - The size of a chunk | ||
* @returns An array of chunks of the given size | ||
* | ||
* @public | ||
*/ | ||
function chunk(array, size) { | ||
@@ -6,0 +15,0 @@ var maxChunks = Math.ceil(array.length / size) |
@@ -1,1 +0,9 @@ | ||
export default function cloneDeep<InputType extends unknown>(input: InputType): InputType; | ||
/** | ||
* Deeply clones the given value. | ||
* | ||
* @param value - The value to clone | ||
* @returns Deep clone of the given value | ||
* | ||
* @public | ||
*/ | ||
export default function cloneDeep<ValueType extends unknown>(value: ValueType): ValueType; |
'use strict' | ||
exports['default'] = cloneDeep | ||
exports.default = cloneDeep | ||
function cloneDeep(input) { | ||
if (!input || !(typeof input === 'object')) return input | ||
var typeStr = Object.prototype.toString.call(input) | ||
var newObj = Object.assign(typeStr === '[object Array]' ? [] : {}, input) | ||
Object.keys(newObj).forEach(function (key) { | ||
if (newObj[key] && typeof newObj[key] === 'object') { | ||
newObj[key] = cloneDeep(newObj[key]) | ||
/** | ||
* Deeply clones the given value. | ||
* | ||
* @param value - The value to clone | ||
* @returns Deep clone of the given value | ||
* | ||
* @public | ||
*/ | ||
function cloneDeep(value) { | ||
if (!value || !(typeof value === 'object')) return value | ||
var typeStr = Object.prototype.toString.call(value) | ||
var newObj = typeStr === '[object Array]' ? [] : {} | ||
var valueObj = value | ||
Object.keys(valueObj).forEach(function (key) { | ||
if (valueObj[key] && typeof valueObj[key] === 'object') { | ||
newObj[key] = cloneDeep(valueObj[key]) | ||
} else { | ||
newObj[key] = valueObj[key] | ||
} | ||
@@ -13,0 +24,0 @@ }) |
@@ -1,3 +0,12 @@ | ||
declare type Debounced<Fn extends (...args: any[]) => any> = Fn extends ((...args: infer Args) => any) ? ((...args: Args) => void) : never; | ||
export default function debounce<Fn extends (...args: any[]) => any>(fn: Fn, wait: number): Debounced<Fn>; | ||
declare type DebouncedFunction<Fn extends (...args: any[]) => any> = Fn extends ((...args: infer Args) => any) ? ((...args: Args) => void) : never; | ||
/** | ||
* Creates a function that will execute after the given timeout after the last call. | ||
* | ||
* @param fn - The function to execute | ||
* @param wait - The timeout | ||
* @returns A function based on the provided function that will execute after the given timeout after the last call | ||
* | ||
* @public | ||
*/ | ||
export default function debounce<InputFunction extends (...args: any[]) => any>(fn: InputFunction, wait: number): DebouncedFunction<InputFunction>; | ||
export {}; |
'use strict' | ||
exports['default'] = debounce | ||
exports.default = debounce | ||
/** | ||
* Creates a function that will execute after the given timeout after the last call. | ||
* | ||
* @param fn - The function to execute | ||
* @param wait - The timeout | ||
* @returns A function based on the provided function that will execute after the given timeout after the last call | ||
* | ||
* @public | ||
*/ | ||
function debounce(fn, wait) { | ||
@@ -6,0 +15,0 @@ var timeout |
@@ -1,1 +0,10 @@ | ||
export default function difference<T>(array1: Array<T>, array2: Array<T>): Array<T>; | ||
/** | ||
* Creates a new array without elements from the second argument. | ||
* | ||
* @param inputArray - The array to remove elements from | ||
* @param arrayToSubstract - The array of elements to remove | ||
* @returns An array basing of the first one without element from the second | ||
* | ||
* @public | ||
*/ | ||
export default function difference<ElementType>(inputArray: Array<ElementType>, arrayToSubtract: Array<ElementType>): Array<ElementType>; |
'use strict' | ||
exports['default'] = difference | ||
exports.default = difference | ||
function difference(array1, array2) { | ||
return array1.filter(function (item) { | ||
return array2.indexOf(item) === -1 | ||
/** | ||
* Creates a new array without elements from the second argument. | ||
* | ||
* @param inputArray - The array to remove elements from | ||
* @param arrayToSubstract - The array of elements to remove | ||
* @returns An array basing of the first one without element from the second | ||
* | ||
* @public | ||
*/ | ||
function difference(inputArray, arrayToSubtract) { | ||
return inputArray.filter(function (item) { | ||
return arrayToSubtract.indexOf(item) === -1 | ||
}) | ||
} |
@@ -1,1 +0,10 @@ | ||
export default function drop<T>(array: Array<T>, n: number): Array<T>; | ||
/** | ||
* Removes the given number of elements from the beginning. | ||
* | ||
* @param array - The array to remove elements from | ||
* @param howMany - The number of elements to remove | ||
* @returns A clone of the array with the given number of elements removed from the beginning | ||
* | ||
* @public | ||
*/ | ||
export default function drop<ElementType>(array: Array<ElementType>, howMany?: number): Array<ElementType>; |
'use strict' | ||
exports['default'] = drop | ||
exports.default = drop | ||
function drop(array, n) { | ||
if (n < 1) { | ||
/** | ||
* Removes the given number of elements from the beginning. | ||
* | ||
* @param array - The array to remove elements from | ||
* @param howMany - The number of elements to remove | ||
* @returns A clone of the array with the given number of elements removed from the beginning | ||
* | ||
* @public | ||
*/ | ||
function drop(array, howMany) { | ||
if (howMany === void 0) { | ||
howMany = 1 | ||
} | ||
if (howMany < 1) { | ||
return array | ||
} | ||
return array.slice(n) | ||
return array.slice(howMany) | ||
} |
@@ -1,1 +0,9 @@ | ||
export default function flatten<ItemType>(arr: Array<ItemType | ItemType[]>): ItemType[]; | ||
/** | ||
* Creates an array with elements "flatten" one-level deep. Meaning if the element is an array, the elements of the array will be added to the root-level array. | ||
* | ||
* @param array - The array to alter | ||
* @returns The copy of the array with elements "flatten" | ||
* | ||
* @public | ||
*/ | ||
export default function flatten<ElementType>(array: Array<ElementType | ElementType[]>): ElementType[]; |
'use strict' | ||
exports['default'] = flatten | ||
exports.default = flatten | ||
function flatten(arr) { | ||
return arr.reduce(function (acc, item) { | ||
/** | ||
* Creates an array with elements "flatten" one-level deep. Meaning if the element is an array, the elements of the array will be added to the root-level array. | ||
* | ||
* @param array - The array to alter | ||
* @returns The copy of the array with elements "flatten" | ||
* | ||
* @public | ||
*/ | ||
function flatten(array) { | ||
return array.reduce(function (acc, item) { | ||
return acc.concat(item) | ||
}, []) | ||
} |
@@ -1,4 +0,23 @@ | ||
export declare type Groups<ItemType> = { | ||
[key: string]: ItemType[]; | ||
export declare type GroupedElements<GroupIdType extends number | string, ElementType> = { | ||
[groupId in GroupIdType]: ElementType[]; | ||
}; | ||
export default function group<ItemType, GroupIdType extends string | number>(arr: ItemType[], getGroupId: (item: ItemType, index: number) => GroupIdType): Groups<ItemType>; | ||
/** | ||
* Creates an object where the key is the group id and the value is an array of elements grouped by this id. | ||
* | ||
* @param array - The array to group elements from | ||
* @param mapper - The function that returns the group id | ||
* @returns An object where the key is the group id and the value is an array of elements grouped by this id | ||
* | ||
* @public | ||
*/ | ||
export default function group<ElementType, GroupIdType extends string | number>(arr: ElementType[], mapper: (element: ElementType, index: number) => GroupIdType): GroupedElements<GroupIdType, ElementType>; | ||
/** | ||
* Creates an object where the key is the group id and the value is an array of elements grouped by this id. | ||
* | ||
* @param array - The array to group elements from | ||
* @param key - The name of the field to use as the id | ||
* @returns An object where the key is the group id and the value is an array of elements grouped by this id | ||
* | ||
* @public | ||
*/ | ||
export default function group<ElementType extends {}, Key extends keyof ElementType, GroupIdType extends ElementType[Key]>(arr: ElementType[], key: Key): GroupIdType extends number | string ? GroupedElements<GroupIdType, ElementType> : never; |
'use strict' | ||
exports['default'] = group | ||
exports.default = group | ||
function group(arr, getGroupId) { | ||
return arr.reduce(function (acc, item, index) { | ||
var groupId = getGroupId(item, index) | ||
/** | ||
* Creates an object where the key is the group id and the value is an array of elements grouped by this id. | ||
* | ||
* @param array - The array to group elements from | ||
* @param mapper - The function that returns the group id | ||
* @returns An object where the key is the group id and the value is an array of elements grouped by this id | ||
* | ||
* @public | ||
*/ | ||
/** | ||
* Creates an object where the key is the group id and the value is an array of elements grouped by this id. | ||
* | ||
* @param array - The array to group elements from | ||
* @param key - The name of the field to use as the id | ||
* @returns An object where the key is the group id and the value is an array of elements grouped by this id | ||
* | ||
* @public | ||
*/ | ||
/** | ||
* @internal | ||
*/ | ||
function group(array, mapper) { | ||
return array.reduce(function (acc, element, index) { | ||
var groupId = | ||
typeof mapper === 'function' ? mapper(element, index) : element[mapper] | ||
acc[groupId] = acc[groupId] || [] | ||
acc[groupId].push(item) | ||
acc[groupId].push(element) | ||
return acc | ||
}, {}) | ||
} |
export { default as chunk } from './chunk/index'; | ||
export { default as cloneDeep } from './cloneDeep/index'; | ||
export { default as compact } from './compact/index'; | ||
export { default as debounce } from './debounce/index'; | ||
@@ -11,2 +10,7 @@ export { default as difference } from './difference/index'; | ||
export { default as omit } from './omit/index'; | ||
export { default as pick } from './pick/index'; | ||
export { default as remove } from './remove/index'; | ||
export { default as sweep } from './sweep/index'; | ||
export { default as truthy } from './truthy/index'; | ||
export { default as uniq } from './uniq/index'; | ||
export { default as first } from './first/index'; |
80
index.js
@@ -6,3 +6,3 @@ 'use strict' | ||
get: function get() { | ||
return _index['default'] | ||
return _index.default | ||
}, | ||
@@ -13,15 +13,9 @@ }) | ||
get: function get() { | ||
return _index2['default'] | ||
return _index2.default | ||
}, | ||
}) | ||
Object.defineProperty(exports, 'compact', { | ||
enumerable: true, | ||
get: function get() { | ||
return _index3['default'] | ||
}, | ||
}) | ||
Object.defineProperty(exports, 'debounce', { | ||
enumerable: true, | ||
get: function get() { | ||
return _index4['default'] | ||
return _index3.default | ||
}, | ||
@@ -32,3 +26,3 @@ }) | ||
get: function get() { | ||
return _index5['default'] | ||
return _index4.default | ||
}, | ||
@@ -39,3 +33,3 @@ }) | ||
get: function get() { | ||
return _index6['default'] | ||
return _index5.default | ||
}, | ||
@@ -46,3 +40,3 @@ }) | ||
get: function get() { | ||
return _index7['default'] | ||
return _index6.default | ||
}, | ||
@@ -53,3 +47,3 @@ }) | ||
get: function get() { | ||
return _index8['default'] | ||
return _index7.default | ||
}, | ||
@@ -60,3 +54,3 @@ }) | ||
get: function get() { | ||
return _index9['default'] | ||
return _index8.default | ||
}, | ||
@@ -67,11 +61,41 @@ }) | ||
get: function get() { | ||
return _index10['default'] | ||
return _index9.default | ||
}, | ||
}) | ||
Object.defineProperty(exports, 'pick', { | ||
enumerable: true, | ||
get: function get() { | ||
return _index10.default | ||
}, | ||
}) | ||
Object.defineProperty(exports, 'remove', { | ||
enumerable: true, | ||
get: function get() { | ||
return _index11['default'] | ||
return _index11.default | ||
}, | ||
}) | ||
Object.defineProperty(exports, 'sweep', { | ||
enumerable: true, | ||
get: function get() { | ||
return _index12.default | ||
}, | ||
}) | ||
Object.defineProperty(exports, 'truthy', { | ||
enumerable: true, | ||
get: function get() { | ||
return _index13.default | ||
}, | ||
}) | ||
Object.defineProperty(exports, 'uniq', { | ||
enumerable: true, | ||
get: function get() { | ||
return _index14.default | ||
}, | ||
}) | ||
Object.defineProperty(exports, 'first', { | ||
enumerable: true, | ||
get: function get() { | ||
return _index15.default | ||
}, | ||
}) | ||
@@ -82,18 +106,26 @@ var _index = require('./chunk/index.js') | ||
var _index3 = require('./compact/index.js') | ||
var _index3 = require('./debounce/index.js') | ||
var _index4 = require('./debounce/index.js') | ||
var _index4 = require('./difference/index.js') | ||
var _index5 = require('./difference/index.js') | ||
var _index5 = require('./drop/index.js') | ||
var _index6 = require('./drop/index.js') | ||
var _index6 = require('./flatten/index.js') | ||
var _index7 = require('./flatten/index.js') | ||
var _index7 = require('./group/index.js') | ||
var _index8 = require('./group/index.js') | ||
var _index8 = require('./last/index.js') | ||
var _index9 = require('./last/index.js') | ||
var _index9 = require('./omit/index.js') | ||
var _index10 = require('./omit/index.js') | ||
var _index10 = require('./pick/index.js') | ||
var _index11 = require('./remove/index.js') | ||
var _index12 = require('./sweep/index.js') | ||
var _index13 = require('./truthy/index.js') | ||
var _index14 = require('./uniq/index.js') | ||
var _index15 = require('./first/index.js') |
@@ -1,1 +0,9 @@ | ||
export default function last<ItemType>(arr: ItemType[]): ItemType | undefined; | ||
/** | ||
* Returns the last element of the array. | ||
* | ||
* @param array - The array to return the last element from | ||
* @returns The last element of the array | ||
* | ||
* @public | ||
*/ | ||
export default function last<ElementType>(array: ElementType[]): ElementType | undefined; |
'use strict' | ||
exports['default'] = last | ||
exports.default = last | ||
function last(arr) { | ||
return arr[arr.length - 1] | ||
/** | ||
* Returns the last element of the array. | ||
* | ||
* @param array - The array to return the last element from | ||
* @returns The last element of the array | ||
* | ||
* @public | ||
*/ | ||
function last(array) { | ||
return array[array.length - 1] | ||
} |
@@ -1,1 +0,10 @@ | ||
export default function omit<ObjectType extends {}, Key extends keyof ObjectType>(object: ObjectType, keys: Key | Key[]): Omit<ObjectType, Key>; | ||
/** | ||
* Creates a copy of the object without given fields. | ||
* | ||
* @param object - The object to remove fields from | ||
* @param keys - The field names to remove | ||
* @returns The copy of the object without given fields | ||
* | ||
* @public | ||
*/ | ||
export default function omit<ObjectType extends {}, Key extends keyof ObjectType>(object: ObjectType, keys: Key | [Key, ...Key[]]): Omit<ObjectType, Key>; |
'use strict' | ||
exports['default'] = omit | ||
exports.default = omit | ||
@@ -22,2 +22,11 @@ function _extends() { | ||
/** | ||
* Creates a copy of the object without given fields. | ||
* | ||
* @param object - The object to remove fields from | ||
* @param keys - The field names to remove | ||
* @returns The copy of the object without given fields | ||
* | ||
* @public | ||
*/ | ||
function omit(object, keys) { | ||
@@ -24,0 +33,0 @@ var clone = _extends({}, object) |
{ | ||
"name": "js-fns", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "Modern JavaScript utility library focused on the build size", | ||
@@ -20,2 +20,3 @@ "main": "./index.js", | ||
"@babel/preset-typescript": "^7.9.0", | ||
"@microsoft/api-extractor": "^7.8.2", | ||
"@types/jest": "25", | ||
@@ -33,2 +34,3 @@ "@types/node": "^12.0.4", | ||
"karma-mocha": "^1.3.0", | ||
"karma-sauce-launcher": "^4.1.4", | ||
"karma-sourcemap-loader": "^0.3.7", | ||
@@ -35,0 +37,0 @@ "karma-webpack": "^4.0.2", |
@@ -1,1 +0,9 @@ | ||
export default function remove<ItemType>(arr: ItemType[], item: ItemType): ItemType[]; | ||
/** | ||
* Creates an array without the given element. | ||
* | ||
* @param array - The array to remove the element from | ||
* @param element - The element to remove | ||
* | ||
* @public | ||
*/ | ||
export default function remove<ElementType>(array: ElementType[], element: ElementType): ElementType[]; |
'use strict' | ||
exports['default'] = remove | ||
exports.default = remove | ||
function remove(arr, item) { | ||
return arr.filter(function (i) { | ||
return i !== item | ||
/** | ||
* Creates an array without the given element. | ||
* | ||
* @param array - The array to remove the element from | ||
* @param element - The element to remove | ||
* | ||
* @public | ||
*/ | ||
function remove(array, element) { | ||
return array.filter(function (i) { | ||
return i !== element | ||
}) | ||
} |
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
42550
72
1388
28
1