@dr.pogodin/js-utils 0.1.4 → 0.1.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
@@ -46,6 +46,12 @@ and used in the same way):
46
46
  — One year expressed in milliseconds.
47
47
 
48
48
  ### Types
49
+ - `Extends<Base, T extends Base>` &mdash; Validates compile-time the type **T**
50
+ extends (is assignable to) the type **Base**; returns **T** if successful.
51
+ - `Implements<Base, T extends Base & ...>` &mdash; Validates compile-time
52
+ the type **T** extends (is assignable to) the type **Base**, and also has
53
+ all (if any) optional fields defined in the **Base**; returns **T** if
54
+ the validation passes.
49
55
  - `ObjectKey` &mdash; **string** | **number** | **symbol** &mdash;
50
56
  The most generic valid type of an object key in TypeScript.
51
57
 
@@ -12,4 +12,18 @@ exports.assertEmptyObject = assertEmptyObject;
12
12
  function assertEmptyObject(object) {
13
13
  if (Object.keys(object).length) throw Error('The object is not empty');
14
14
  }
15
+
16
+ /**
17
+ * Validates compile-time that the type T extends Base, and returns T.
18
+ *
19
+ * BEWARE: In the case Base has some optional fields missing in T, T still
20
+ * extends Base (as "extends" means T is assignable to Base)! The Implements
21
+ * util below also checks that T has all optional fields defined in Base.
22
+ */
23
+
24
+ /**
25
+ * Validates compile-time that the type T extends (is assignable to) the type
26
+ * Base, and also that it has defined all (if any) optional fields defined in
27
+ * the Base. Returns T if the validation passes.
28
+ */
15
29
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":["assertEmptyObject","object","Object","keys","length","Error"],"sources":["../../src/types.ts"],"sourcesContent":["// Misc TypeScript-specific utilities.\n\n/** The most permissive object key type. */\nexport type ObjectKey = string | number | symbol;\n\n/** Asserts given object is empty, both compile- and run-time. */\nexport function assertEmptyObject(object: Record<ObjectKey, never>): void {\n if (Object.keys(object).length) throw Error('The object is not empty');\n}\n"],"mappings":";;;;;;AAAA;;AAEA;;AAGA;AACO,SAASA,iBAAiBA,CAACC,MAAgC,EAAQ;EACxE,IAAIC,MAAM,CAACC,IAAI,CAACF,MAAM,CAAC,CAACG,MAAM,EAAE,MAAMC,KAAK,CAAC,yBAAyB,CAAC;AACxE","ignoreList":[]}
1
+ {"version":3,"file":"types.js","names":["assertEmptyObject","object","Object","keys","length","Error"],"sources":["../../src/types.ts"],"sourcesContent":["// Misc TypeScript-specific utilities.\n\n/** The most permissive object key type. */\nexport type ObjectKey = string | number | symbol;\n\n/** Asserts given object is empty, both compile- and run-time. */\nexport function assertEmptyObject(object: Record<ObjectKey, never>): void {\n if (Object.keys(object).length) throw Error('The object is not empty');\n}\n\n/**\n * Validates compile-time that the type T extends Base, and returns T.\n *\n * BEWARE: In the case Base has some optional fields missing in T, T still\n * extends Base (as \"extends\" means T is assignable to Base)! The Implements\n * util below also checks that T has all optional fields defined in Base.\n */\nexport type Extends<Base, T extends Base> = T;\n\n/**\n * Validates compile-time that the type T extends (is assignable to) the type\n * Base, and also that it has defined all (if any) optional fields defined in\n * the Base. Returns T if the validation passes.\n */\nexport type Implements<\n Base,\n T extends Required<T> extends Required<Base> ? Base : Required<Base>,\n> = T;\n"],"mappings":";;;;;;AAAA;;AAEA;;AAGA;AACO,SAASA,iBAAiBA,CAACC,MAAgC,EAAQ;EACxE,IAAIC,MAAM,CAACC,IAAI,CAACF,MAAM,CAAC,CAACG,MAAM,EAAE,MAAMC,KAAK,CAAC,yBAAyB,CAAC;AACxE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -6,4 +6,18 @@
6
6
  export function assertEmptyObject(object) {
7
7
  if (Object.keys(object).length) throw Error('The object is not empty');
8
8
  }
9
+
10
+ /**
11
+ * Validates compile-time that the type T extends Base, and returns T.
12
+ *
13
+ * BEWARE: In the case Base has some optional fields missing in T, T still
14
+ * extends Base (as "extends" means T is assignable to Base)! The Implements
15
+ * util below also checks that T has all optional fields defined in Base.
16
+ */
17
+
18
+ /**
19
+ * Validates compile-time that the type T extends (is assignable to) the type
20
+ * Base, and also that it has defined all (if any) optional fields defined in
21
+ * the Base. Returns T if the validation passes.
22
+ */
9
23
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":["assertEmptyObject","object","Object","keys","length","Error"],"sources":["../../src/types.ts"],"sourcesContent":["// Misc TypeScript-specific utilities.\n\n/** The most permissive object key type. */\nexport type ObjectKey = string | number | symbol;\n\n/** Asserts given object is empty, both compile- and run-time. */\nexport function assertEmptyObject(object: Record<ObjectKey, never>): void {\n if (Object.keys(object).length) throw Error('The object is not empty');\n}\n"],"mappings":"AAAA;;AAEA;;AAGA;AACA,OAAO,SAASA,iBAAiBA,CAACC,MAAgC,EAAQ;EACxE,IAAIC,MAAM,CAACC,IAAI,CAACF,MAAM,CAAC,CAACG,MAAM,EAAE,MAAMC,KAAK,CAAC,yBAAyB,CAAC;AACxE","ignoreList":[]}
1
+ {"version":3,"file":"types.js","names":["assertEmptyObject","object","Object","keys","length","Error"],"sources":["../../src/types.ts"],"sourcesContent":["// Misc TypeScript-specific utilities.\n\n/** The most permissive object key type. */\nexport type ObjectKey = string | number | symbol;\n\n/** Asserts given object is empty, both compile- and run-time. */\nexport function assertEmptyObject(object: Record<ObjectKey, never>): void {\n if (Object.keys(object).length) throw Error('The object is not empty');\n}\n\n/**\n * Validates compile-time that the type T extends Base, and returns T.\n *\n * BEWARE: In the case Base has some optional fields missing in T, T still\n * extends Base (as \"extends\" means T is assignable to Base)! The Implements\n * util below also checks that T has all optional fields defined in Base.\n */\nexport type Extends<Base, T extends Base> = T;\n\n/**\n * Validates compile-time that the type T extends (is assignable to) the type\n * Base, and also that it has defined all (if any) optional fields defined in\n * the Base. Returns T if the validation passes.\n */\nexport type Implements<\n Base,\n T extends Required<T> extends Required<Base> ? Base : Required<Base>,\n> = T;\n"],"mappings":"AAAA;;AAEA;;AAGA;AACA,OAAO,SAASA,iBAAiBA,CAACC,MAAgC,EAAQ;EACxE,IAAIC,MAAM,CAACC,IAAI,CAACF,MAAM,CAAC,CAACG,MAAM,EAAE,MAAMC,KAAK,CAAC,yBAAyB,CAAC;AACxE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -2,3 +2,17 @@
2
2
  export type ObjectKey = string | number | symbol;
3
3
  /** Asserts given object is empty, both compile- and run-time. */
4
4
  export declare function assertEmptyObject(object: Record<ObjectKey, never>): void;
5
+ /**
6
+ * Validates compile-time that the type T extends Base, and returns T.
7
+ *
8
+ * BEWARE: In the case Base has some optional fields missing in T, T still
9
+ * extends Base (as "extends" means T is assignable to Base)! The Implements
10
+ * util below also checks that T has all optional fields defined in Base.
11
+ */
12
+ export type Extends<Base, T extends Base> = T;
13
+ /**
14
+ * Validates compile-time that the type T extends (is assignable to) the type
15
+ * Base, and also that it has defined all (if any) optional fields defined in
16
+ * the Base. Returns T if the validation passes.
17
+ */
18
+ export type Implements<Base, T extends Required<T> extends Required<Base> ? Base : Required<Base>> = T;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@dr.pogodin/js-utils",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Collection of JavaScript (TypeScript) utilities.",
5
5
  "main": "./build/module/index.js",
6
6
  "module": "./build/module/index.js",
7
7
  "types": "./build/types/index.d.ts",
8
8
  "exports": {
9
- "require": "./build/common/index.js",
10
9
  "types": "./build/types/index.d.ts",
10
+ "require": "./build/common/index.js",
11
11
  "default": "./build/module/index.js"
12
12
  },
13
13
  "scripts": {
@@ -43,15 +43,15 @@
43
43
  "@babel/plugin-transform-runtime": "^7.28.5",
44
44
  "@babel/preset-env": "^7.28.5",
45
45
  "@babel/preset-typescript": "^7.28.5",
46
- "@dr.pogodin/eslint-configs": "^0.1.1",
47
- "@tsconfig/recommended": "^1.0.10",
46
+ "@dr.pogodin/eslint-configs": "^0.1.2",
47
+ "@tsconfig/recommended": "^1.0.13",
48
48
  "@types/jest": "^30.0.0",
49
49
  "babel-jest": "^30.2.0",
50
50
  "babel-plugin-add-import-extension": "^1.6.0",
51
51
  "jest": "^30.2.0",
52
52
  "mockdate": "^3.0.5",
53
- "rimraf": "^6.0.1",
54
- "tstyche": "^5.0.0",
53
+ "rimraf": "^6.1.2",
54
+ "tstyche": "^5.0.1",
55
55
  "typescript": "^5.9.3"
56
56
  },
57
57
  "dependencies": {