getorset-anything 0.0.3 → 0.0.5

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/README.md CHANGED
@@ -40,7 +40,7 @@ import { mapGetOrSet } from 'getorset-anything'
40
40
 
41
41
  const map = new Map<string, number[]>()
42
42
 
43
- const arr = mapGetOrSet(map, 'abc', () => [])
43
+ const arr = mapGetOrSet(map, 'abc', (): number[] => [])
44
44
 
45
45
  arr.push(100) // OK!
46
46
  ```
@@ -52,7 +52,7 @@ import { objGetOrSet } from 'getorset-anything'
52
52
 
53
53
  const obj: Record<string, number[]> = {}
54
54
 
55
- const arr = objGetOrSet(obj, 'abc', () => [])
55
+ const arr = objGetOrSet(obj, 'abc', (): number[] => [])
56
56
 
57
57
  arr.push(100) // OK!
58
58
  ```
@@ -73,12 +73,17 @@ arr.push(100) // OK!
73
73
  arr.push('100') // NG! ⛔️
74
74
  ```
75
75
 
76
- ## Meet the family
76
+ ## Meet the family (more tiny utils with TS support)
77
77
 
78
+ - [is-what 🙉](https://github.com/mesqueeb/is-what)
79
+ - [is-where 🙈](https://github.com/mesqueeb/is-where)
78
80
  - [merge-anything 🥡](https://github.com/mesqueeb/merge-anything)
81
+ - [check-anything 👁](https://github.com/mesqueeb/check-anything)
82
+ - [remove-anything ✂️](https://github.com/mesqueeb/remove-anything)
83
+ - [getorset-anything 🐊](https://github.com/mesqueeb/getorset-anything)
84
+ - [map-anything 🗺](https://github.com/mesqueeb/map-anything)
79
85
  - [filter-anything ⚔️](https://github.com/mesqueeb/filter-anything)
80
- - [find-and-replace-anything 🎣](https://github.com/mesqueeb/find-and-replace-anything)
81
- - [compare-anything 🛰](https://github.com/mesqueeb/compare-anything)
82
86
  - [copy-anything 🎭](https://github.com/mesqueeb/copy-anything)
87
+ - [case-anything 🐫](https://github.com/mesqueeb/case-anything)
83
88
  - [flatten-anything 🏏](https://github.com/mesqueeb/flatten-anything)
84
- - [is-what 🙉](https://github.com/mesqueeb/is-what)
89
+ - [nestify-anything 🧅](https://github.com/mesqueeb/nestify-anything)
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ function mapGetOrSet(map, key, initialValue) {
4
+ let val = map.get(key);
5
+ if (val === void 0) {
6
+ val = initialValue();
7
+ map.set(key, val);
8
+ }
9
+ return val;
10
+ }
11
+ function objGetOrSet(obj, key, initialValue) {
12
+ let val = obj[key];
13
+ if (val === void 0) {
14
+ val = initialValue();
15
+ obj[key] = val;
16
+ }
17
+ return val;
18
+ }
19
+
20
+ exports.mapGetOrSet = mapGetOrSet;
21
+ exports.objGetOrSet = objGetOrSet;
@@ -1,42 +1,30 @@
1
- /**
2
- * Retrieve the value in a map, or if it wasn't found, set an initial value and return that.
3
- *
4
- * @example
5
- * ```js
6
- * const map = new Map<string, number[]>()
7
- *
8
- * const arr = mapGetOrSet(map, '123', () => [])
9
- *
10
- * arr.push('xyz')
11
- * ```
12
- */
13
- function mapGetOrSet(map, key, initialValue) {
14
- let val = map.get(key);
15
- if (val === undefined) {
16
- val = initialValue();
17
- map.set(key, val);
18
- }
19
- return val;
20
- }
21
- /**
22
- * Retrieve the value in an object, or if it wasn't found, set an initial value and return that.
23
- *
24
- * @example
25
- * ```js
26
- * const obj: Record<string, number[]> = {}
27
- *
28
- * const arr = objGetOrSet(obj, '123', () => [])
29
- *
30
- * arr.push('xyz')
31
- * ```
32
- */
33
- function objGetOrSet(obj, key, initialValue) {
34
- let val = obj[key];
35
- if (val === undefined) {
36
- val = initialValue();
37
- obj[key] = val;
38
- }
39
- return val;
40
- }
1
+ type KeyOfMap<M extends Map<unknown, unknown>> = M extends Map<infer K, unknown> ? K : never;
2
+ type ValueOfMap<M extends Map<unknown, unknown>> = M extends Map<unknown, infer V> ? V : never;
3
+ /**
4
+ * Retrieve the value in a map, or if it wasn't found, set an initial value and return that.
5
+ *
6
+ * @example
7
+ * ```js
8
+ * const map = new Map<string, number[]>()
9
+ *
10
+ * const arr = mapGetOrSet(map, '123', () => [])
11
+ *
12
+ * arr.push('xyz')
13
+ * ```
14
+ */
15
+ declare function mapGetOrSet<M extends Map<unknown, unknown>, T extends () => ValueOfMap<M>>(map: M, key: KeyOfMap<M>, initialValue: T): ReturnType<T>;
16
+ /**
17
+ * Retrieve the value in an object, or if it wasn't found, set an initial value and return that.
18
+ *
19
+ * @example
20
+ * ```js
21
+ * const obj: Record<string, number[]> = {}
22
+ *
23
+ * const arr = objGetOrSet(obj, '123', () => [])
24
+ *
25
+ * arr.push('xyz')
26
+ * ```
27
+ */
28
+ declare function objGetOrSet<O extends Record<string | number | symbol, unknown>, T extends () => O[keyof O]>(obj: O, key: keyof O, initialValue: T): ReturnType<T>;
41
29
 
42
30
  export { mapGetOrSet, objGetOrSet };
@@ -0,0 +1,30 @@
1
+ type KeyOfMap<M extends Map<unknown, unknown>> = M extends Map<infer K, unknown> ? K : never;
2
+ type ValueOfMap<M extends Map<unknown, unknown>> = M extends Map<unknown, infer V> ? V : never;
3
+ /**
4
+ * Retrieve the value in a map, or if it wasn't found, set an initial value and return that.
5
+ *
6
+ * @example
7
+ * ```js
8
+ * const map = new Map<string, number[]>()
9
+ *
10
+ * const arr = mapGetOrSet(map, '123', () => [])
11
+ *
12
+ * arr.push('xyz')
13
+ * ```
14
+ */
15
+ declare function mapGetOrSet<M extends Map<unknown, unknown>, T extends () => ValueOfMap<M>>(map: M, key: KeyOfMap<M>, initialValue: T): ReturnType<T>;
16
+ /**
17
+ * Retrieve the value in an object, or if it wasn't found, set an initial value and return that.
18
+ *
19
+ * @example
20
+ * ```js
21
+ * const obj: Record<string, number[]> = {}
22
+ *
23
+ * const arr = objGetOrSet(obj, '123', () => [])
24
+ *
25
+ * arr.push('xyz')
26
+ * ```
27
+ */
28
+ declare function objGetOrSet<O extends Record<string | number | symbol, unknown>, T extends () => O[keyof O]>(obj: O, key: keyof O, initialValue: T): ReturnType<T>;
29
+
30
+ export { mapGetOrSet, objGetOrSet };
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ function mapGetOrSet(map, key, initialValue) {
2
+ let val = map.get(key);
3
+ if (val === void 0) {
4
+ val = initialValue();
5
+ map.set(key, val);
6
+ }
7
+ return val;
8
+ }
9
+ function objGetOrSet(obj, key, initialValue) {
10
+ let val = obj[key];
11
+ if (val === void 0) {
12
+ val = initialValue();
13
+ obj[key] = val;
14
+ }
15
+ return val;
16
+ }
17
+
18
+ export { mapGetOrSet, objGetOrSet };
package/package.json CHANGED
@@ -1,17 +1,22 @@
1
1
  {
2
2
  "name": "getorset-anything",
3
- "version": "0.0.3",
4
- "sideEffects": false,
5
- "type": "module",
3
+ "version": "0.0.5",
6
4
  "description": "Gets a value from a Map/Obj or sets an initial value when not found and returns that. TypeScript supported.",
7
- "module": "./dist/index.es.js",
8
- "main": "./dist/index.cjs",
9
- "types": "./dist/types/index.d.ts",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "types": "./dist/index.d.ts",
8
+ "module": "./dist/index.js",
9
+ "main": "./dist/index.js",
10
10
  "exports": {
11
11
  ".": {
12
- "import": "./dist/index.es.js",
13
- "require": "./dist/index.cjs",
14
- "types": "./dist/types/index.d.ts"
12
+ "require": {
13
+ "types": "./dist/cjs/index.d.cts",
14
+ "default": "./dist/cjs/index.cjs"
15
+ },
16
+ "import": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ }
15
20
  }
16
21
  },
17
22
  "files": [
@@ -21,10 +26,9 @@
21
26
  "node": ">=12.13"
22
27
  },
23
28
  "scripts": {
24
- "clean": "del ./dist",
25
29
  "lint": "tsc --noEmit && eslint ./src --ext .ts",
26
30
  "test": "vitest run",
27
- "build": "npm run clean && rollup -c ./scripts/build.js",
31
+ "build": "rollup -c ./rollup.config.js",
28
32
  "release": "npm run lint && del dist && npm run build && np"
29
33
  },
30
34
  "repository": {
@@ -58,20 +62,20 @@
58
62
  "url": "https://github.com/mesqueeb/getorset-anything/issues"
59
63
  },
60
64
  "homepage": "https://github.com/mesqueeb/getorset-anything#readme",
61
- "dependencies": {},
62
65
  "devDependencies": {
63
- "@typescript-eslint/eslint-plugin": "^5.10.1",
64
- "@typescript-eslint/parser": "^5.10.1",
65
- "del-cli": "^4.0.1",
66
- "eslint": "^8.7.0",
67
- "eslint-config-prettier": "^8.3.0",
66
+ "@typescript-eslint/eslint-plugin": "^5.59.2",
67
+ "@typescript-eslint/parser": "^5.59.2",
68
+ "del-cli": "^5.0.0",
69
+ "eslint": "^8.40.0",
70
+ "eslint-config-prettier": "^8.8.0",
68
71
  "eslint-plugin-tree-shaking": "^1.10.0",
69
- "np": "^7.6.0",
70
- "prettier": "^2.5.1",
71
- "rollup": "^2.66.1",
72
- "rollup-plugin-typescript2": "^0.31.1",
73
- "typescript": "^4.5.5",
74
- "vitest": "^0.2.3"
72
+ "np": "^7.7.0",
73
+ "prettier": "^2.8.8",
74
+ "rollup": "^3.23.0",
75
+ "rollup-plugin-dts": "^5.3.0",
76
+ "rollup-plugin-esbuild": "^5.0.0",
77
+ "typescript": "^4.9.5",
78
+ "vitest": "^0.31.0"
75
79
  },
76
80
  "np": {
77
81
  "yarn": false,
package/dist/index.cjs DELETED
@@ -1,47 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- /**
6
- * Retrieve the value in a map, or if it wasn't found, set an initial value and return that.
7
- *
8
- * @example
9
- * ```js
10
- * const map = new Map<string, number[]>()
11
- *
12
- * const arr = mapGetOrSet(map, '123', () => [])
13
- *
14
- * arr.push('xyz')
15
- * ```
16
- */
17
- function mapGetOrSet(map, key, initialValue) {
18
- let val = map.get(key);
19
- if (val === undefined) {
20
- val = initialValue();
21
- map.set(key, val);
22
- }
23
- return val;
24
- }
25
- /**
26
- * Retrieve the value in an object, or if it wasn't found, set an initial value and return that.
27
- *
28
- * @example
29
- * ```js
30
- * const obj: Record<string, number[]> = {}
31
- *
32
- * const arr = objGetOrSet(obj, '123', () => [])
33
- *
34
- * arr.push('xyz')
35
- * ```
36
- */
37
- function objGetOrSet(obj, key, initialValue) {
38
- let val = obj[key];
39
- if (val === undefined) {
40
- val = initialValue();
41
- obj[key] = val;
42
- }
43
- return val;
44
- }
45
-
46
- exports.mapGetOrSet = mapGetOrSet;
47
- exports.objGetOrSet = objGetOrSet;
@@ -1,29 +0,0 @@
1
- declare type KeyOfMap<M extends Map<unknown, unknown>> = M extends Map<infer K, unknown> ? K : never;
2
- declare type ValueOfMap<M extends Map<unknown, unknown>> = M extends Map<unknown, infer V> ? V : never;
3
- /**
4
- * Retrieve the value in a map, or if it wasn't found, set an initial value and return that.
5
- *
6
- * @example
7
- * ```js
8
- * const map = new Map<string, number[]>()
9
- *
10
- * const arr = mapGetOrSet(map, '123', () => [])
11
- *
12
- * arr.push('xyz')
13
- * ```
14
- */
15
- export declare function mapGetOrSet<M extends Map<unknown, unknown>, T extends () => ValueOfMap<M>>(map: M, key: KeyOfMap<M>, initialValue: T): ReturnType<T>;
16
- /**
17
- * Retrieve the value in an object, or if it wasn't found, set an initial value and return that.
18
- *
19
- * @example
20
- * ```js
21
- * const obj: Record<string, number[]> = {}
22
- *
23
- * const arr = objGetOrSet(obj, '123', () => [])
24
- *
25
- * arr.push('xyz')
26
- * ```
27
- */
28
- export declare function objGetOrSet<O extends Record<string | number | symbol, unknown>, T extends () => O[keyof O]>(obj: O, key: keyof O, initialValue: T): ReturnType<T>;
29
- export {};