@augment-vir/core 31.42.0 → 31.43.1

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,40 @@
1
+ /**
2
+ * Property key used to mark {@link Branded}.
3
+ *
4
+ * @category Internal
5
+ */
6
+ export type BrandedTypeTag = '$_brand_$';
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<Record<BrandedTypeTag, Record<BrandKey, never>>>;
26
+ /**
27
+ * Unwrap a type brand applied via {@link Branded}.
28
+ *
29
+ * Largely inspired by the `Tagged` type from the `type-fest` package at
30
+ * https://github.com/sindresorhus/type-fest/tree/687a89d94c4403d93ac5cb969ac7f492cee006cb/source
31
+ *
32
+ * @category Type
33
+ */
34
+ export type UnwrapBrand<BrandedType extends Branded<any, any>> = BrandedType extends Branded<infer OriginalType, any> ? OriginalType : BrandedType;
35
+ /**
36
+ * Wrap a value in a brand that matches its original type.
37
+ *
38
+ * @category Type
39
+ */
40
+ export declare function applyBrand<Brand extends Branded<any, any>>(value: UnwrapBrand<Brand>): Brand;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Wrap a value in a brand that matches its original type.
3
+ *
4
+ * @category Type
5
+ */
6
+ export function applyBrand(value) {
7
+ return value;
8
+ }
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.42.0",
3
+ "version": "31.43.1",
4
4
  "description": "Core augment-vir augments. Use @augment-vir/common instead.",
5
5
  "homepage": "https://github.com/electrovir/augment-vir",
6
6
  "bugs": {