Comparing version 0.1.3 to 0.1.4
/// <reference types="node" resolution-mode="require"/> | ||
import type * as FS from 'fs'; | ||
export declare function filterObject<T extends object, K extends keyof T>(object: T, ...keys: K[]): Pick<T, K>; | ||
export declare function filterObject<O extends object, R extends object>(object: O, predicate: (key: keyof O, value: O[keyof O]) => boolean): R; | ||
export declare function pick<T extends object, K extends keyof T>(object: T, ...keys: K[] | K[][]): Pick<T, K>; | ||
export declare function omit<T extends object, K extends keyof T>(object: T, ...keys: K[] | K[][]): Omit<T, K>; | ||
export declare function isJSON(str: string): boolean; | ||
@@ -5,0 +7,0 @@ export declare abstract class FileMap<V> implements Map<string, V> { |
@@ -1,5 +0,11 @@ | ||
export function filterObject(object, ...keys) { | ||
export function filterObject(object, predicate) { | ||
const entries = Object.entries(object); | ||
return Object.fromEntries(entries.filter(([key]) => keys.includes(key))); | ||
return Object.fromEntries(entries.filter(([key, value]) => predicate(key, value))); | ||
} | ||
export function pick(object, ...keys) { | ||
return filterObject(object, (key) => keys.flat().includes(key)); | ||
} | ||
export function omit(object, ...keys) { | ||
return filterObject(object, (key) => !keys.flat().includes(key)); | ||
} | ||
export function isJSON(str) { | ||
@@ -6,0 +12,0 @@ try { |
{ | ||
"name": "utilium", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Typescript utilies", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
import type * as FS from 'fs'; | ||
export function filterObject<T extends object, K extends keyof T>(object: T, ...keys: K[]): Pick<T, K> { | ||
const entries = <[K, T[K]][]>Object.entries(object); | ||
return <Pick<T, K>>Object.fromEntries(entries.filter(([key]) => keys.includes(key))); | ||
export function filterObject<O extends object, R extends object>(object: O, predicate: (key: keyof O, value: O[keyof O]) => boolean): R { | ||
const entries = <[keyof O, O[keyof O]][]>Object.entries(object); | ||
return <R>Object.fromEntries(entries.filter(([key, value]) => predicate(key, value))); | ||
} | ||
export function pick<T extends object, K extends keyof T>(object: T, ...keys: K[] | K[][]): Pick<T, K> { | ||
return filterObject<T, Pick<T, K>>(object, (key: K) => keys.flat().includes(key)); | ||
} | ||
export function omit<T extends object, K extends keyof T>(object: T, ...keys: K[] | K[][]): Omit<T, K> { | ||
return filterObject<T, Omit<T, K>>(object, (key: K) => !keys.flat().includes(key)); | ||
} | ||
export function isJSON(str: string) { | ||
@@ -9,0 +17,0 @@ try { |
24321
764