Skip to content

Commit

Permalink
pick object and array include
Browse files Browse the repository at this point in the history
  • Loading branch information
ogroppo committed Jan 22, 2024
1 parent 4a2ad7c commit 5ecdc80
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# deverything

## 0.41.0

### Minor Changes

- pick object and array include

## 0.40.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deverything",
"version": "0.40.0",
"version": "0.41.0",
"description": "Everything you need for Dev",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export * from "./normalizeNumber";
export * from "./objectDiff";
export * from "./omit";
export * from "./parseDate";
export * from "./pickObjectKeys";
export * from "./pickObjectValues";
export * from "./pretty";
export * from "./promiseWithTimeout";
export * from "./scrambleText";
Expand Down
13 changes: 13 additions & 0 deletions src/helpers/pickObjectKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ObjectKeys } from "../types";
import { PlainObject } from "../types/PlainObject";

export const pickObjectKeys = <T extends PlainObject>(
obj: T,
keys: ObjectKeys<T>
): Partial<T> => {
const ret: Partial<T> = {};
for (const key in obj) {
if (keys.includes(key)) ret[key] = obj[key];
}
return ret;
};
13 changes: 13 additions & 0 deletions src/helpers/pickObjectValues.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ObjectValues } from "../types/Object";
import { PlainObject } from "../types/PlainObject";

export const pickObjectValues = <T extends PlainObject>(
obj: T,
values: ObjectValues<T>
): Partial<T> => {
const ret: Partial<T> = {};
for (const key in obj) {
if (values.includes(obj[key])) ret[key] = obj[key];
}
return ret;
};
3 changes: 2 additions & 1 deletion src/validators/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./isArray";
export * from "./isArrayIncluded";
export * from "./isBoolean";
export * from "./isBrowser";
export * from "./isClient";
Expand All @@ -9,13 +10,13 @@ export * from "./isFutureDate";
export * from "./isJsDate";
export * from "./isKey";
export * from "./isLastIndex";
export * from "./isNotEmptyString";
export * from "./isNumber";
export * from "./isNumeric";
export * from "./isNumericId";
export * from "./isObject";
export * from "./isPastDate";
export * from "./isPromise";
export * from "./isNotEmptyString";
export * from "./isPWA";
export * from "./isReactElement";
export * from "./isRegExp";
Expand Down
3 changes: 3 additions & 0 deletions src/validators/isArrayIncluded.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const isArrayIncluded = <T>(arr1: T[], arr2: T[]): boolean => {
return arr1.every((value) => arr2.includes(value));
};

0 comments on commit 5ecdc80

Please sign in to comment.