moderndash
Advanced tools
Comparing version 0.0.9 to 0.0.10
@@ -21,3 +21,3 @@ /** | ||
type RecordKey = string | number | symbol; | ||
type Collection<T> = T[] | Record<RecordKey, T>; | ||
type ArrayOrRecord<T> = T[] | Record<RecordKey, T>; | ||
type NoUnion<T, U = T> = T extends U ? [U] extends [T] ? T : never : never; | ||
@@ -419,3 +419,3 @@ | ||
* @param iteratee - The iteratee to transform keys. | ||
* @param collection - The array or object to iterate over. | ||
* @param collection - The array or record to iterate over. | ||
* @returns Returns the composed aggregate object. | ||
@@ -429,6 +429,6 @@ * @example | ||
* | ||
* countBy(value => value.active, users); | ||
* countBy(users, value => value.active); | ||
* // => { 'true': 2, 'false': 1 } | ||
*/ | ||
declare function countBy<TInput, TKey extends RecordKey>(iteratee: (value: TInput) => TKey, collection: Collection<TInput>): Record<TKey, number>; | ||
declare function countBy<TInput, TKey extends RecordKey>(collection: ArrayOrRecord<TInput>, iteratee: (value: TInput) => TKey): Record<TKey, number>; | ||
@@ -443,11 +443,10 @@ /** | ||
* @category Collection | ||
* @param collection The array or object to iterate over. | ||
* @param iteratee The iteratee to transform keys. | ||
* @param collection - The array or object to iterate over. | ||
* @param iteratee - The iteratee to transform keys. | ||
* @returns Returns the composed aggregate object. | ||
* @example | ||
* | ||
* groupBy(Math.floor, [6.1, 4.2, 6.3]) | ||
* groupBy([6.1, 4.2, 6.3], Math.floor) | ||
* // => { '4': [4.2], '6': [6.1, 6.3] } | ||
*/ | ||
declare function groupBy<T, U extends RecordKey>(iteratee: (value: T) => U, collection: Collection<T>): Record<U, T[]>; | ||
declare function groupBy<T, U extends RecordKey>(collection: ArrayOrRecord<T>, iteratee: (value: T) => U): Record<U, T[]>; | ||
@@ -590,2 +589,2 @@ declare function sortBy<T, U>(iteratee: (item: T) => NoUnion<number | bigint | Date | string, U>, array: T[]): T[]; | ||
export { Collection, IterateeFunction, MinimumTwoArrays, NoUnion, PropertyShorthand, RecordKey, after, before, camelCase, capitalize, chunk, countBy, debounce, deburr, difference, differenceBy, differenceWith, dropRightWhile, dropWhile, escape, escapeRegExp, groupBy, intersection, intersectionBy, intersectionWith, isEmpty, isEqual, isEqualWith, isPlainObject, kebabCase, memoize, once, pascalCase, pick, sample, sampleSize, shuffle, snakeCase, sortBy, startCase, stripSpecialChars, takeRightWhile, takeWhile, throttle, unescapeHTML, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, zip, zipWith }; | ||
export { ArrayOrRecord, IterateeFunction, MinimumTwoArrays, NoUnion, PropertyShorthand, RecordKey, after, before, camelCase, capitalize, chunk, countBy, debounce, deburr, difference, differenceBy, differenceWith, dropRightWhile, dropWhile, escape, escapeRegExp, groupBy, intersection, intersectionBy, intersectionWith, isEmpty, isEqual, isEqualWith, isPlainObject, kebabCase, memoize, once, pascalCase, pick, sample, sampleSize, shuffle, snakeCase, sortBy, startCase, stripSpecialChars, takeRightWhile, takeWhile, throttle, unescapeHTML, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, zip, zipWith }; |
@@ -280,3 +280,3 @@ // src/array/chunk.ts | ||
// src/collection/countBy.ts | ||
function countBy(iteratee, collection) { | ||
function countBy(collection, iteratee) { | ||
const result = {}; | ||
@@ -296,3 +296,3 @@ const values = getValuesFromCollection(collection); | ||
// src/collection/groupBy.ts | ||
function groupBy(iteratee, collection) { | ||
function groupBy(collection, iteratee) { | ||
const result = {}; | ||
@@ -299,0 +299,0 @@ const values = getValuesFromCollection(collection); |
{ | ||
"name": "moderndash", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"type": "module", | ||
@@ -9,3 +9,3 @@ "description": "A lodash inspired utility framework for ESM/Typescript/ES2020", | ||
"prepublishOnly": "npm run build && @powershell cp '../README.md' './README.md' && @powershell cp '../LICENSE' './LICENSE'", | ||
"postpublish": "@powershell rm './README.md && @powershell rm './LICENSE'", | ||
"postpublish": "@powershell rm './README.md' && @powershell rm './LICENSE'", | ||
"test": "vitest", | ||
@@ -34,3 +34,8 @@ "test-ui": "vitest --ui" | ||
"types": "./dist/index.d.ts", | ||
"main": "./dist/index.js", | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs" | ||
} | ||
}, | ||
"files": [ | ||
@@ -37,0 +42,0 @@ "dist", |
@@ -1,2 +0,2 @@ | ||
import type { Collection, RecordKey } from '../types'; | ||
import type { ArrayOrRecord, RecordKey } from '../types'; | ||
@@ -12,3 +12,3 @@ import { getValuesFromCollection } from '@helpers/collections'; | ||
* @param iteratee - The iteratee to transform keys. | ||
* @param collection - The array or object to iterate over. | ||
* @param collection - The array or record to iterate over. | ||
* @returns Returns the composed aggregate object. | ||
@@ -22,7 +22,7 @@ * @example | ||
* | ||
* countBy(value => value.active, users); | ||
* countBy(users, value => value.active); | ||
* // => { 'true': 2, 'false': 1 } | ||
*/ | ||
export function countBy<TInput, TKey extends RecordKey>(iteratee: (value: TInput) => TKey, collection: Collection<TInput>): Record<TKey, number> { | ||
export function countBy<TInput, TKey extends RecordKey>(collection: ArrayOrRecord<TInput>, iteratee: (value: TInput) => TKey): Record<TKey, number> { | ||
const result = {} as Record<TKey, number>; | ||
@@ -29,0 +29,0 @@ const values = getValuesFromCollection(collection); |
@@ -1,2 +0,2 @@ | ||
import type { RecordKey, Collection } from '../types'; | ||
import type { RecordKey, ArrayOrRecord } from '../types'; | ||
@@ -14,12 +14,11 @@ import { getValuesFromCollection } from '@helpers/collections'; | ||
* @category Collection | ||
* @param collection The array or object to iterate over. | ||
* @param iteratee The iteratee to transform keys. | ||
* @param collection - The array or object to iterate over. | ||
* @param iteratee - The iteratee to transform keys. | ||
* @returns Returns the composed aggregate object. | ||
* @example | ||
* | ||
* groupBy(Math.floor, [6.1, 4.2, 6.3]) | ||
* groupBy([6.1, 4.2, 6.3], Math.floor) | ||
* // => { '4': [4.2], '6': [6.1, 6.3] } | ||
*/ | ||
export function groupBy<T, U extends RecordKey>(iteratee: (value: T) => U, collection: Collection<T>): Record<U, T[]> { | ||
export function groupBy<T, U extends RecordKey>(collection: ArrayOrRecord<T>, iteratee: (value: T) => U): Record<U, T[]> { | ||
const result = {} as Record<U, T[]>; | ||
@@ -26,0 +25,0 @@ const values = getValuesFromCollection(collection); |
@@ -1,5 +0,5 @@ | ||
import type { Collection } from '../types'; | ||
import type { ArrayOrRecord } from '../types'; | ||
export function getValuesFromCollection<T>(collection: Collection<T>): T[] { | ||
export function getValuesFromCollection<T>(collection: ArrayOrRecord<T>): T[] { | ||
return Array.isArray(collection) ? collection : Object.values(collection); | ||
} |
@@ -8,3 +8,3 @@ export type MinimumTwoArrays<T> = [T[], T[], ...T[][]]; | ||
export type Collection<T> = T[] | Record<RecordKey, T>; | ||
export type NoUnion<T, U = T> = T extends U ? [U] extends [T] ? T : never : never; | ||
export type ArrayOrRecord<T> = T[] | Record<RecordKey, T>; | ||
export type NoUnion<T, U = T> = T extends U ? [U] extends [T] ? T : never : never; |
Sorry, the diff of this file is not supported yet
211053
69
2958