functype 0.9.2 → 0.9.3

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,2 @@
1
+ function e(n,r){return r}function t(n){return n}function d(n,r){return n!=null}function a(n){return r=>e(n,r)}var s=n=>r=>e(n,r),o=n=>r=>e(n,r),K=n=>r=>e(n,r);export{e as a,t as b,d as c,a as d,s as e,o as f,K as g};//# sourceMappingURL=chunk-ECL55NTP.mjs.map
2
+ //# sourceMappingURL=chunk-ECL55NTP.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/branded/Brand.ts"],"names":["Brand","_brand","value","unbrand","branded","hasBrand","createBrander","brand","BrandedString","BrandedNumber","BrandedBoolean"],"mappings":"AAqBO,SAASA,CAAAA,CAA2BC,CAAAA,CAAWC,CAAAA,CAAuB,CAG3E,OAAOA,CACT,CAOO,SAASC,CAAAA,CAA6BC,CAAAA,CAAyB,CAEpE,OAAOA,CACT,CAaO,SAASC,CAAAA,CAA8BH,CAAAA,CAAgBD,CAAAA,CAAiC,CAG7F,OAAOC,CAAAA,EAAU,IACnB,CAOO,SAASI,CAAAA,CAAmCC,CAAAA,CAAU,CAC3D,OAAQL,CAAAA,EAA0BF,CAAAA,CAAMO,CAAAA,CAAOL,CAAK,CACtD,KAQaM,CAAAA,CACQD,CAAAA,EAClBL,CAAAA,EACCF,CAAAA,CAAMO,CAAAA,CAAOL,CAAK,EAETO,CAAAA,CACQF,CAAAA,EAClBL,CAAAA,EACCF,CAAAA,CAAMO,CAAAA,CAAOL,CAAK,CAAA,CAETQ,CAAAA,CACQH,CAAAA,EAClBL,CAAAA,EACCF,CAAAA,CAAMO,CAAAA,CAAOL,CAAK","file":"chunk-ECL55NTP.mjs","sourcesContent":["// Phantom type brand - exists only at compile time\n// Must use type alias (not interface) because we need intersection with primitives\nexport type Brand<K extends string, T> = T & {\n readonly __brand: K\n}\n\n// Utility type to extract the underlying type from a branded type\nexport type Unbrand<T> = T extends Brand<string, infer U> ? U : T\n\n// Utility type to extract the brand from a branded type\nexport type ExtractBrand<T> = T extends Brand<infer K, unknown> ? K : never\n\n/**\n * Brand is a utility for creating nominal typing in TypeScript.\n * It creates phantom types that exist only at compile time.\n * At runtime, the branded value IS the primitive value.\n *\n * @param brand - The brand name (unused at runtime, only for type inference)\n * @param value - The value to brand\n * @returns The value with phantom type brand\n */\nexport function Brand<K extends string, T>(_brand: K, value: T): Brand<K, T> {\n // Just return the value with a type assertion\n // No runtime modification - the brand exists only in TypeScript\n return value as Brand<K, T>\n}\n\n/**\n * Helper to remove a brand from a value\n * @param branded - The branded value\n * @returns The original value without the brand\n */\nexport function unbrand<K extends string, T>(branded: Brand<K, T>): T {\n // Since branded values ARE their primitives, just return as-is\n return branded as unknown as T\n}\n\n/**\n * Type guard for checking if a value has a specific brand\n * @param value - The value to check\n * @param _brand - The brand to check for (unused at runtime)\n * @returns True if the value has the specified brand\n *\n * Note: Since brands are phantom types that exist only at compile time,\n * this function can only provide a runtime approximation. It always returns true\n * for non-null values, as we have no way to actually check the brand at runtime.\n * This function is primarily for API consistency and documentation purposes.\n */\nexport function hasBrand<K extends string, T>(value: unknown, _brand: K): value is Brand<K, T> {\n // In a phantom type system, we can't actually check the brand at runtime\n // We can only verify the value exists\n return value !== null && value !== undefined\n}\n\n/**\n * Create a branded type constructor for a specific brand\n * @param brand - The brand name\n * @returns A function that brands values with the specified brand\n */\nexport function createBrander<K extends string, T>(brand: K) {\n return (value: T): Brand<K, T> => Brand(brand, value)\n}\n\n// Common branded primitive types\nexport type BrandedString<K extends string> = Brand<K, string>\nexport type BrandedNumber<K extends string> = Brand<K, number>\nexport type BrandedBoolean<K extends string> = Brand<K, boolean>\n\n// Factory for common primitive branded types\nexport const BrandedString =\n <K extends string>(brand: K) =>\n (value: string): BrandedString<K> =>\n Brand(brand, value)\n\nexport const BrandedNumber =\n <K extends string>(brand: K) =>\n (value: number): BrandedNumber<K> =>\n Brand(brand, value)\n\nexport const BrandedBoolean =\n <K extends string>(brand: K) =>\n (value: boolean): BrandedBoolean<K> =>\n Brand(brand, value)\n"]}
@@ -1,2 +1,2 @@
1
- export{q as Either,j as Left,i as Right,o as TypeCheckLeft,n as TypeCheckRight,l as isLeft,k as isRight,m as tryCatch,p as tryCatchAsync}from'../chunk-55TOOU3K.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-R2TQJN3P.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{q as Either,j as Left,i as Right,o as TypeCheckLeft,n as TypeCheckRight,l as isLeft,k as isRight,m as tryCatch,p as tryCatchAsync}from'../chunk-4WBZOSQH.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-ECL55NTP.mjs';//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1,2 +1,2 @@
1
- export{K as FPromise,J as FPromiseCompanion}from'../chunk-55TOOU3K.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-R2TQJN3P.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{K as FPromise,J as FPromiseCompanion}from'../chunk-4WBZOSQH.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-ECL55NTP.mjs';//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
package/dist/index.d.ts CHANGED
@@ -11,15 +11,16 @@ export { TypeNames } from './try/index.js';
11
11
  export { Map, SafeTraversable } from './map/index.js';
12
12
  export { Tuple } from './tuple/index.js';
13
13
 
14
- type ValidatedBrand<K extends string, T> = {
14
+ interface ValidatedBrand<K extends string, T> {
15
15
  readonly brand: K;
16
16
  readonly validate: (value: T) => boolean;
17
17
  readonly of: (value: T) => Option<Brand<K, T>>;
18
18
  readonly from: (value: T) => Either<string, Brand<K, T>>;
19
19
  readonly unsafeOf: (value: T) => Brand<K, T>;
20
20
  readonly is: (value: unknown) => value is Brand<K, T>;
21
+ readonly unwrap: (branded: Brand<K, T>) => T;
21
22
  readonly refine: <K2 extends string>(brand: K2, validate: (value: Brand<K, T>) => boolean) => ValidatedBrand<K2, Brand<K, T>>;
22
- };
23
+ }
23
24
  /**
24
25
  * Create a validated brand with runtime validation
25
26
  * @example
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export{G as Base,B as BoundedNumber,C as BoundedString,E as Cond,ca as ESMap,q as Either,x as EmailAddress,K as FPromise,J as FPromiseCompanion,Z as FoldableUtils,$ as HKT,A as ISO8601Date,aa as Identity,u as IntegerNumber,ba as Lazy,W as LazyList,j as Left,h as List,da as Map,F as Match,ea as MatchableUtils,H as NAME,w as NonEmptyString,t as NonNegativeNumber,b as None,d as Option,c as OptionConstructor,U as ParseError,D as PatternString,v as PositiveInteger,s as PositiveNumber,fa as Ref,i as Right,e as Set,a as Some,ha as Stack,P as Task,M as TaskException,N as TaskResult,I as Throwable,_ as Try,o as TypeCheckLeft,n as TypeCheckRight,f as Typeable,V as TypedError,z as UUID,y as UrlString,r as ValidatedBrand,X as Validation,ga as Valuable,O as createCancellationTokenSource,T as createErrorSerializer,S as formatError,R as formatStackTrace,Y as isExtractable,l as isLeft,k as isRight,L as isTaggedThrowable,g as isTypeable,Q as safeStringify,m as tryCatch,p as tryCatchAsync}from'./chunk-55TOOU3K.mjs';export{a as Companion,b as Tuple}from'./chunk-BQJB6CCW.mjs';export{a as Brand,g as BrandedBoolean,f as BrandedNumber,e as BrandedString,d as createBrander,c as hasBrand,b as unbrand}from'./chunk-R2TQJN3P.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{G as Base,B as BoundedNumber,C as BoundedString,E as Cond,ca as ESMap,q as Either,x as EmailAddress,K as FPromise,J as FPromiseCompanion,Z as FoldableUtils,$ as HKT,A as ISO8601Date,aa as Identity,u as IntegerNumber,ba as Lazy,W as LazyList,j as Left,h as List,da as Map,F as Match,ea as MatchableUtils,H as NAME,w as NonEmptyString,t as NonNegativeNumber,b as None,d as Option,c as OptionConstructor,U as ParseError,D as PatternString,v as PositiveInteger,s as PositiveNumber,fa as Ref,i as Right,e as Set,a as Some,ha as Stack,P as Task,M as TaskException,N as TaskResult,I as Throwable,_ as Try,o as TypeCheckLeft,n as TypeCheckRight,f as Typeable,V as TypedError,z as UUID,y as UrlString,r as ValidatedBrand,X as Validation,ga as Valuable,O as createCancellationTokenSource,T as createErrorSerializer,S as formatError,R as formatStackTrace,Y as isExtractable,l as isLeft,k as isRight,L as isTaggedThrowable,g as isTypeable,Q as safeStringify,m as tryCatch,p as tryCatchAsync}from'./chunk-4WBZOSQH.mjs';export{a as Companion,b as Tuple}from'./chunk-BQJB6CCW.mjs';export{a as Brand,g as BrandedBoolean,f as BrandedNumber,e as BrandedString,d as createBrander,c as hasBrand,b as unbrand}from'./chunk-ECL55NTP.mjs';//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1,2 +1,2 @@
1
- export{h as List}from'../chunk-55TOOU3K.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-R2TQJN3P.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{h as List}from'../chunk-4WBZOSQH.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-ECL55NTP.mjs';//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1,2 +1,2 @@
1
- export{da as Map}from'../chunk-55TOOU3K.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-R2TQJN3P.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{da as Map}from'../chunk-4WBZOSQH.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-ECL55NTP.mjs';//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1,2 +1,2 @@
1
- export{b as None,d as Option,c as OptionConstructor,a as Some}from'../chunk-55TOOU3K.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-R2TQJN3P.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{b as None,d as Option,c as OptionConstructor,a as Some}from'../chunk-4WBZOSQH.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-ECL55NTP.mjs';//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1,2 +1,2 @@
1
- export{e as Set}from'../chunk-55TOOU3K.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-R2TQJN3P.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{e as Set}from'../chunk-4WBZOSQH.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-ECL55NTP.mjs';//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1,2 +1,2 @@
1
- export{_ as Try}from'../chunk-55TOOU3K.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-R2TQJN3P.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{_ as Try}from'../chunk-4WBZOSQH.mjs';import'../chunk-BQJB6CCW.mjs';import'../chunk-ECL55NTP.mjs';//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functype",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "type": "module",
5
5
  "description": "A smallish functional library for TypeScript",
6
6
  "author": "jordan.burke@gmail.com",