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

@dhmk/utils

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dhmk/utils - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

5

esm/data-adapter.d.ts

@@ -5,3 +5,3 @@ declare const defaultEntitiesKey = "byId";

declare type DefaultIdsKey = typeof defaultIdsKey;
export declare type NormalizedData<T, EntitiesKey extends string = DefaultEntitiesKey, IdsKey extends string = DefaultIdsKey> = Record<EntitiesKey, Record<string, T>> & Record<IdsKey, string[]>;
export declare type NormalizedData<T, EntitiesKey extends string = DefaultEntitiesKey, IdsKey extends string = DefaultIdsKey> = Record<EntitiesKey, Record<string, T>> & Record<IdsKey, ReadonlyArray<string>>;
declare type WithId = {

@@ -12,3 +12,5 @@ [p: string]: any;

declare type DataAdapter<T, E extends string, I extends string> = {
getId(item: T): string;
from(data: ReadonlyArray<T>): NormalizedData<T, E, I>;
from(ids: ReadonlyArray<string>, byId: Record<string, T>): NormalizedData<T, E, I>;
flatMap(context: NormalizedData<T, E, I>, fn: (item: T, index: number, id: string) => ReadonlyArray<T>): NormalizedData<T, E, I>;

@@ -27,4 +29,5 @@ insert(context: NormalizedData<T, E, I>, index: number, ...items: ReadonlyArray<T>): NormalizedData<T, E, I>;

export declare const byId: ById;
export declare const fromIds: <T>(ids: ReadonlyArray<string>, byId: Record<string, T>) => T[];
export declare function dataAdapter<T extends WithId>(): DataAdapter<T, DefaultEntitiesKey, DefaultIdsKey>;
export declare function dataAdapter<T, EntitiesKey extends string = DefaultEntitiesKey, IdsKey extends string = DefaultIdsKey>(getId: (item: T) => string, entitiesKey?: EntitiesKey, idsKey?: IdsKey): DataAdapter<T, EntitiesKey, IdsKey>;
export {};

13

esm/data-adapter.js

@@ -18,2 +18,3 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {

};
export var fromIds = function (ids, byId) { return ids.map(function (id) { return byId[id]; }); };
export function dataAdapter(getId, entitiesKey, idsKey) {

@@ -23,7 +24,9 @@ if (getId === void 0) { getId = defaultId; }

if (idsKey === void 0) { idsKey = defaultIdsKey; }
function from(data) {
function from(dataOrIds, byId) {
var _a;
var data = byId ? fromIds(dataOrIds, byId) : dataOrIds;
var ids = byId ? dataOrIds : data.map(getId);
return _a = {},
_a[entitiesKey] = byId(data, getId),
_a[idsKey] = data.map(getId),
_a[idsKey] = ids,
_a;

@@ -41,3 +44,6 @@ }

}
var atEnd = index === context[idsKey].length;
var length = context[idsKey].length;
if (!length)
return from(items);
var atEnd = index === length;
if (atEnd)

@@ -91,2 +97,3 @@ index--;

return {
getId: getId,
from: from,

@@ -93,0 +100,0 @@ flatMap: flatMap,

@@ -5,3 +5,3 @@ declare const defaultEntitiesKey = "byId";

declare type DefaultIdsKey = typeof defaultIdsKey;
export declare type NormalizedData<T, EntitiesKey extends string = DefaultEntitiesKey, IdsKey extends string = DefaultIdsKey> = Record<EntitiesKey, Record<string, T>> & Record<IdsKey, string[]>;
export declare type NormalizedData<T, EntitiesKey extends string = DefaultEntitiesKey, IdsKey extends string = DefaultIdsKey> = Record<EntitiesKey, Record<string, T>> & Record<IdsKey, ReadonlyArray<string>>;
declare type WithId = {

@@ -12,3 +12,5 @@ [p: string]: any;

declare type DataAdapter<T, E extends string, I extends string> = {
getId(item: T): string;
from(data: ReadonlyArray<T>): NormalizedData<T, E, I>;
from(ids: ReadonlyArray<string>, byId: Record<string, T>): NormalizedData<T, E, I>;
flatMap(context: NormalizedData<T, E, I>, fn: (item: T, index: number, id: string) => ReadonlyArray<T>): NormalizedData<T, E, I>;

@@ -27,4 +29,5 @@ insert(context: NormalizedData<T, E, I>, index: number, ...items: ReadonlyArray<T>): NormalizedData<T, E, I>;

export declare const byId: ById;
export declare const fromIds: <T>(ids: ReadonlyArray<string>, byId: Record<string, T>) => T[];
export declare function dataAdapter<T extends WithId>(): DataAdapter<T, DefaultEntitiesKey, DefaultIdsKey>;
export declare function dataAdapter<T, EntitiesKey extends string = DefaultEntitiesKey, IdsKey extends string = DefaultIdsKey>(getId: (item: T) => string, entitiesKey?: EntitiesKey, idsKey?: IdsKey): DataAdapter<T, EntitiesKey, IdsKey>;
export {};

@@ -12,3 +12,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.dataAdapter = exports.byId = void 0;
exports.dataAdapter = exports.fromIds = exports.byId = void 0;
var std_1 = require("./std");

@@ -23,2 +23,4 @@ var defaultEntitiesKey = "byId";

exports.byId = byId;
var fromIds = function (ids, byId) { return ids.map(function (id) { return byId[id]; }); };
exports.fromIds = fromIds;
function dataAdapter(getId, entitiesKey, idsKey) {

@@ -28,7 +30,9 @@ if (getId === void 0) { getId = defaultId; }

if (idsKey === void 0) { idsKey = defaultIdsKey; }
function from(data) {
function from(dataOrIds, byId) {
var _a;
var data = byId ? (0, exports.fromIds)(dataOrIds, byId) : dataOrIds;
var ids = byId ? dataOrIds : data.map(getId);
return _a = {},
_a[entitiesKey] = (0, exports.byId)(data, getId),
_a[idsKey] = data.map(getId),
_a[entitiesKey] = byId(data, getId),
_a[idsKey] = ids,
_a;

@@ -46,3 +50,6 @@ }

}
var atEnd = index === context[idsKey].length;
var length = context[idsKey].length;
if (!length)
return from(items);
var atEnd = index === length;
if (atEnd)

@@ -96,2 +103,3 @@ index--;

return {
getId: getId,
from: from,

@@ -98,0 +106,0 @@ flatMap: flatMap,

{
"name": "@dhmk/utils",
"version": "3.0.0",
"version": "3.1.0",
"description": "A collection of frequently used functions and primitives",

@@ -5,0 +5,0 @@ "keywords": [

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