@augment-vir/core 31.41.0 → 31.43.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.
@@ -0,0 +1,42 @@
1
+ /**
2
+ * A symbol used for {@link Branded}.
3
+ *
4
+ * @category Internal
5
+ */
6
+ export declare const brandedTypeTag: unique symbol;
7
+ /**
8
+ * Brand any type so that it is no longer assignable to itself. For example, brand a database id
9
+ * `string` type so that standard strings cannot be assigned to it.
10
+ *
11
+ * Largely inspired by the `Tagged` type from the `type-fest` package at
12
+ * https://github.com/sindresorhus/type-fest/tree/687a89d94c4403d93ac5cb969ac7f492cee006cb/source
13
+ *
14
+ * @category Type
15
+ * @example
16
+ *
17
+ * ```ts
18
+ * import {Branded, createBrander} from '@augment-vir/common';
19
+ *
20
+ * type MyId = Branded<string, 'my-database-id-type'>;
21
+ * ```
22
+ */
23
+ export type Branded<OriginalType,
24
+ /** The key for this brand. Two branded types with the same key will be assignable to each other. */
25
+ BrandKey extends PropertyKey> = OriginalType & Readonly<{
26
+ [brandedTypeTag]: Record<BrandKey, never>;
27
+ }>;
28
+ /**
29
+ * Unwrap a type brand applied via {@link Branded}.
30
+ *
31
+ * Largely inspired by the `Tagged` type from the `type-fest` package at
32
+ * https://github.com/sindresorhus/type-fest/tree/687a89d94c4403d93ac5cb969ac7f492cee006cb/source
33
+ *
34
+ * @category Type
35
+ */
36
+ export type UnwrapBrand<BrandedType extends Branded<any, any>> = BrandedType extends Branded<infer OriginalType, any> ? OriginalType : BrandedType;
37
+ /**
38
+ * Wrap a value in a brand that matches its original type.
39
+ *
40
+ * @category Type
41
+ */
42
+ export declare function applyBrand<Brand extends Branded<any, any>>(value: UnwrapBrand<Brand>): Brand;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * A symbol used for {@link Branded}.
3
+ *
4
+ * @category Internal
5
+ */
6
+ export const brandedTypeTag = Symbol.for('augment-vir-core-branded-type-tag');
7
+ /**
8
+ * Wrap a value in a brand that matches its original type.
9
+ *
10
+ * @category Type
11
+ */
12
+ export function applyBrand(value) {
13
+ return value;
14
+ }
package/dist/index.d.ts CHANGED
@@ -33,3 +33,4 @@ export * from './augments/string/match.js';
33
33
  export * from './augments/string/punctuation.js';
34
34
  export * from './augments/string/remove-duplicate-characters.js';
35
35
  export * from './augments/string/uuid.js';
36
+ export * from './augments/type/branded-type.js';
package/dist/index.js CHANGED
@@ -33,3 +33,4 @@ export * from './augments/string/match.js';
33
33
  export * from './augments/string/punctuation.js';
34
34
  export * from './augments/string/remove-duplicate-characters.js';
35
35
  export * from './augments/string/uuid.js';
36
+ export * from './augments/type/branded-type.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/core",
3
- "version": "31.41.0",
3
+ "version": "31.43.0",
4
4
  "description": "Core augment-vir augments. Use @augment-vir/common instead.",
5
5
  "homepage": "https://github.com/electrovir/augment-vir",
6
6
  "bugs": {
@@ -28,14 +28,14 @@
28
28
  "test:update": "npm test update"
29
29
  },
30
30
  "dependencies": {
31
- "@date-vir/duration": "^7.4.3",
31
+ "@date-vir/duration": "^8.0.0",
32
32
  "browser-or-node": "^3.0.0",
33
33
  "diff": "^8.0.2",
34
34
  "json5": "^2.2.3",
35
35
  "type-fest": "^5.1.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@types/node": "^24.7.2",
38
+ "@types/node": "^24.9.1",
39
39
  "c8": "^10.1.3",
40
40
  "istanbul-smart-text-reporter": "^1.1.5",
41
41
  "typescript": "^5.9.3"