@weser/object 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022-present Robin Weser
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @weser/object
2
+
3
+ [Documentation](https://stack.weser.io/object)
package/dist/each.d.ts ADDED
@@ -0,0 +1 @@
1
+ export default function each<T extends Record<PropertyKey, any>>(obj: T, iterator: (value: T[keyof T], key: keyof T, obj: T) => void): void;
package/dist/each.js ADDED
@@ -0,0 +1,5 @@
1
+ export default function each(obj, iterator) {
2
+ for (const key in obj) {
3
+ iterator(obj[key], key, obj);
4
+ }
5
+ }
@@ -0,0 +1 @@
1
+ export default function entries<T extends Record<string, any>>(object: T): Array<[keyof T, T[keyof T]]>;
@@ -0,0 +1,3 @@
1
+ export default function entries(object) {
2
+ return Object.entries(object);
3
+ }
@@ -0,0 +1 @@
1
+ export default function filter<T extends Record<PropertyKey, any>>(obj: T, filter: (value: T[keyof T], key: keyof T, obj: T) => boolean): {};
package/dist/filter.js ADDED
@@ -0,0 +1,11 @@
1
+ export default function filter(obj, filter) {
2
+ const filteredObj = {};
3
+ for (const key in obj) {
4
+ const value = obj[key];
5
+ if (filter(value, key, obj)) {
6
+ // @ts-ignore
7
+ filteredObj[key] = value;
8
+ }
9
+ }
10
+ return filteredObj;
11
+ }
package/dist/find.d.ts ADDED
@@ -0,0 +1 @@
1
+ export default function find<T extends Record<PropertyKey, any>>(obj: T, query: (value: T[keyof T], key: keyof T, obj: T) => boolean): Extract<keyof T, string> | undefined;
package/dist/find.js ADDED
@@ -0,0 +1,7 @@
1
+ export default function find(obj, query) {
2
+ for (const key in obj) {
3
+ if (query(obj[key], key, obj)) {
4
+ return key;
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,11 @@
1
+ export { default as each } from './each.js';
2
+ export { default as entries } from './entries.js';
3
+ export { default as filter } from './filter.js';
4
+ export { default as find } from './find.js';
5
+ export { default as keys } from './keys.js';
6
+ export { default as map } from './map.js';
7
+ export { default as mergeDeep } from './mergeDeep.js';
8
+ export { default as omit } from './omit.js';
9
+ export { default as pick } from './pick.js';
10
+ export { default as reduce } from './reduce.js';
11
+ export { default as values } from './values.js';
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ export { default as each } from './each.js';
2
+ export { default as entries } from './entries.js';
3
+ export { default as filter } from './filter.js';
4
+ export { default as find } from './find.js';
5
+ export { default as keys } from './keys.js';
6
+ export { default as map } from './map.js';
7
+ export { default as mergeDeep } from './mergeDeep.js';
8
+ export { default as omit } from './omit.js';
9
+ export { default as pick } from './pick.js';
10
+ export { default as reduce } from './reduce.js';
11
+ export { default as values } from './values.js';
package/dist/keys.d.ts ADDED
@@ -0,0 +1 @@
1
+ export default function keys<T extends Record<string, any>>(object: T): Array<keyof T>;
package/dist/keys.js ADDED
@@ -0,0 +1,3 @@
1
+ export default function keys(object) {
2
+ return Object.keys(object);
3
+ }
package/dist/map.d.ts ADDED
@@ -0,0 +1 @@
1
+ export default function map<T extends Record<PropertyKey, any>, R>(obj: T, mapper: <K extends keyof T>(value: T[K], key: K, obj: T) => R): Record<keyof T, R>;
package/dist/map.js ADDED
@@ -0,0 +1,8 @@
1
+ export default function map(obj, mapper) {
2
+ const mappedObj = {};
3
+ for (const key in obj) {
4
+ // @ts-ignore
5
+ mappedObj[key] = mapper(obj[key], key, obj);
6
+ }
7
+ return mappedObj;
8
+ }
@@ -0,0 +1 @@
1
+ export default function mergeDeep<T extends Record<PropertyKey, any>>(base: T, ...objs: Array<T>): T;
@@ -0,0 +1,20 @@
1
+ export default function mergeDeep(base, ...objs) {
2
+ for (let i = 0, len = objs.length; i < len; ++i) {
3
+ const obj = objs[i];
4
+ for (const key in obj) {
5
+ // see https://github.com/robinweser/fast-loops/issues/18
6
+ if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
7
+ continue;
8
+ }
9
+ const value = obj[key];
10
+ if (typeof value === 'object' &&
11
+ !Array.isArray(value) &&
12
+ value !== null) {
13
+ base[key] = mergeDeep(base[key], value);
14
+ continue;
15
+ }
16
+ base[key] = value;
17
+ }
18
+ }
19
+ return base;
20
+ }
package/dist/omit.d.ts ADDED
@@ -0,0 +1 @@
1
+ export default function omit<T extends Record<PropertyKey, any>, K extends keyof T>(obj: T, keys: Array<K>): Omit<T, K>;
package/dist/omit.js ADDED
@@ -0,0 +1,10 @@
1
+ export default function omit(obj, keys) {
2
+ const omittedObj = {};
3
+ for (const key in obj) {
4
+ if (!keys.includes(key)) {
5
+ // @ts-ignore
6
+ omittedObj[key] = obj[key];
7
+ }
8
+ }
9
+ return omittedObj;
10
+ }
package/dist/pick.d.ts ADDED
@@ -0,0 +1 @@
1
+ export default function pick<T extends Record<PropertyKey, any>, K extends keyof T>(obj: T, keys: Array<K>): Pick<T, K>;
package/dist/pick.js ADDED
@@ -0,0 +1,11 @@
1
+ export default function pick(obj, keys) {
2
+ const pickedObj = {};
3
+ for (let i = 0, len = keys.length; i < len; ++i) {
4
+ const key = keys[i];
5
+ if (key in obj) {
6
+ // @ts-ignore
7
+ pickedObj[key] = obj[key];
8
+ }
9
+ }
10
+ return pickedObj;
11
+ }
@@ -0,0 +1 @@
1
+ export default function reduce<T extends Record<PropertyKey, any>, B>(obj: T, reducer: (accumulator: B, value: T[keyof T], key: keyof T, obj: T) => B, initialValue: B): B;
package/dist/reduce.js ADDED
@@ -0,0 +1,6 @@
1
+ export default function reduce(obj, reducer, initialValue) {
2
+ for (const key in obj) {
3
+ initialValue = reducer(initialValue, obj[key], key, obj);
4
+ }
5
+ return initialValue;
6
+ }
@@ -0,0 +1 @@
1
+ {"root":["../src/each.ts","../src/entries.ts","../src/filter.ts","../src/find.ts","../src/index.ts","../src/keys.ts","../src/map.ts","../src/mergedeep.ts","../src/omit.ts","../src/pick.ts","../src/reduce.ts","../src/values.ts"],"version":"5.9.3"}
@@ -0,0 +1 @@
1
+ export default function values<T extends Record<string, any>>(object: T): Array<T[keyof T]>;
package/dist/values.js ADDED
@@ -0,0 +1,3 @@
1
+ export default function values(object) {
2
+ return Object.values(object);
3
+ }
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@weser/object",
3
+ "version": "1.0.0",
4
+ "description": "Type-safe, performant & immutable object iteration utilities",
5
+ "author": "Robin Weser <robin@weser.io>",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/robinweser/weser.git",
8
+ "repository": "https://github.com/robinweser/weser.git",
9
+ "type": "module",
10
+ "main": "dist/index.js",
11
+ "module": "dist/index.js",
12
+ "types": "dist/index.d.ts",
13
+ "sideEffects": false,
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "files": [
18
+ "LICENSE",
19
+ "README.md",
20
+ "dist/**"
21
+ ],
22
+ "browserslist": [
23
+ "IE >= 11",
24
+ "Firefox >= 60",
25
+ "Safari >= 11.1",
26
+ "Chrome >= 66",
27
+ "ChromeAndroid >= 66",
28
+ "iOS >= 11.3",
29
+ "Edge >= 15"
30
+ ],
31
+ "scripts": {
32
+ "setup": "pnpm build",
33
+ "clean": "rimraf dist",
34
+ "build": "tsc -b",
35
+ "dev": "pnpm build -w",
36
+ "test": "echo 1"
37
+ },
38
+ "keywords": [
39
+ "object",
40
+ "iteration",
41
+ "map",
42
+ "filter",
43
+ "reduce",
44
+ "utils"
45
+ ],
46
+ "devDependencies": {
47
+ "ava": "^6.1.3",
48
+ "rimraf": "^3.0.2",
49
+ "typescript": "^5.4.5"
50
+ },
51
+ "gitHead": "490b5b37e8da7f0cac2880543874914c6f6be5d6"
52
+ }