Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bedrock-ui/utils

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bedrock-ui/utils - npm Package Compare versions

Comparing version 0.4.2 to 0.4.3

6

lib/cjs/utils/countBy/countBy.d.ts
import type { TypeofArray } from '../../types/array';
export declare function countBy<T extends TypeofArray<T>[], P extends keyof TypeofArray<T>>(array: T, property: P): Map<TypeofArray<T>[P], number>;
type FnParam<T extends TypeofArray<T>[]> = (element: TypeofArray<T>) => unknown;
type ArrayParam<T> = keyof TypeofArray<T>;
declare function countBy<T extends TypeofArray<T>[], P extends FnParam<T>>(array: T, property: P): Map<ReturnType<P>, number>;
declare function countBy<T extends TypeofArray<T>[], P extends ArrayParam<T>>(array: T, property: P): Map<TypeofArray<T>[P], number>;
export { countBy };

@@ -7,3 +7,10 @@ "use strict";

array.forEach((element) => {
map.set(element[property], (map.get(element[property]) || 0) + 1);
if (typeof property === 'function') {
const value = property(element);
map.set(value, (map.get(value) || 0) + 1);
}
else {
const value = property;
map.set(element[value], (map.get(element[value]) || 0) + 1);
}
});

@@ -10,0 +17,0 @@ return map;

import type { TypeofArray } from '../../types/array.js';
export declare function countBy<T extends TypeofArray<T>[], P extends keyof TypeofArray<T>>(array: T, property: P): Map<TypeofArray<T>[P], number>;
type FnParam<T extends TypeofArray<T>[]> = (element: TypeofArray<T>) => unknown;
type ArrayParam<T> = keyof TypeofArray<T>;
declare function countBy<T extends TypeofArray<T>[], P extends FnParam<T>>(array: T, property: P): Map<ReturnType<P>, number>;
declare function countBy<T extends TypeofArray<T>[], P extends ArrayParam<T>>(array: T, property: P): Map<TypeofArray<T>[P], number>;
export { countBy };

@@ -1,7 +0,15 @@

export function countBy(array, property) {
function countBy(array, property) {
const map = new Map();
array.forEach((element) => {
map.set(element[property], (map.get(element[property]) || 0) + 1);
if (typeof property === 'function') {
const value = property(element);
map.set(value, (map.get(value) || 0) + 1);
}
else {
const value = property;
map.set(element[value], (map.get(element[value]) || 0) + 1);
}
});
return map;
}
export { countBy };

2

package.json
{
"name": "@bedrock-ui/utils",
"version": "0.4.2",
"version": "0.4.3",
"description": "Bedrock UI Utils",

@@ -5,0 +5,0 @@ "author": "Matthew Wolfe",

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