nalloc 0.0.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.
Files changed (58) hide show
  1. package/README.md +282 -0
  2. package/build/devtools.cjs +79 -0
  3. package/build/devtools.cjs.map +1 -0
  4. package/build/devtools.d.ts +82 -0
  5. package/build/devtools.js +43 -0
  6. package/build/devtools.js.map +1 -0
  7. package/build/index.cjs +76 -0
  8. package/build/index.cjs.map +1 -0
  9. package/build/index.d.ts +4 -0
  10. package/build/index.js +5 -0
  11. package/build/index.js.map +1 -0
  12. package/build/option.cjs +279 -0
  13. package/build/option.cjs.map +1 -0
  14. package/build/option.d.ts +356 -0
  15. package/build/option.js +157 -0
  16. package/build/option.js.map +1 -0
  17. package/build/result.cjs +381 -0
  18. package/build/result.cjs.map +1 -0
  19. package/build/result.d.ts +442 -0
  20. package/build/result.js +229 -0
  21. package/build/result.js.map +1 -0
  22. package/build/safe.cjs +88 -0
  23. package/build/safe.cjs.map +1 -0
  24. package/build/safe.d.ts +29 -0
  25. package/build/safe.js +18 -0
  26. package/build/safe.js.map +1 -0
  27. package/build/testing.cjs +111 -0
  28. package/build/testing.cjs.map +1 -0
  29. package/build/testing.d.ts +85 -0
  30. package/build/testing.js +81 -0
  31. package/build/testing.js.map +1 -0
  32. package/build/types.cjs +78 -0
  33. package/build/types.cjs.map +1 -0
  34. package/build/types.d.ts +137 -0
  35. package/build/types.js +36 -0
  36. package/build/types.js.map +1 -0
  37. package/build/unsafe.cjs +82 -0
  38. package/build/unsafe.cjs.map +1 -0
  39. package/build/unsafe.d.ts +27 -0
  40. package/build/unsafe.js +11 -0
  41. package/build/unsafe.js.map +1 -0
  42. package/package.json +93 -0
  43. package/src/__tests__/index.ts +13 -0
  44. package/src/__tests__/option.ts +610 -0
  45. package/src/__tests__/option.types.ts +120 -0
  46. package/src/__tests__/result.ts +721 -0
  47. package/src/__tests__/result.types.ts +249 -0
  48. package/src/__tests__/safe.ts +24 -0
  49. package/src/__tests__/tooling.ts +86 -0
  50. package/src/__tests__/unsafe.ts +24 -0
  51. package/src/devtools.ts +97 -0
  52. package/src/index.ts +18 -0
  53. package/src/option.ts +510 -0
  54. package/src/result.ts +676 -0
  55. package/src/safe.ts +58 -0
  56. package/src/testing.ts +159 -0
  57. package/src/types.ts +201 -0
  58. package/src/unsafe.ts +47 -0
@@ -0,0 +1,137 @@
1
+ /** Values that represent None (absence of a value). */
2
+ export type NoneValueType = null | undefined | void;
3
+ /** Widens literal types to their base types for better type inference. */
4
+ export type Widen<T> = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T extends bigint ? bigint : T extends symbol ? symbol : T;
5
+ /** Widens never to unknown, otherwise preserves the type. */
6
+ export type WidenNever<T> = [T] extends [never] ? unknown : T;
7
+ /** Excludes None values from a type, leaving only valid Some values. */
8
+ export type ValueType<T> = Exclude<T, NoneValueType>;
9
+ export declare const SOME_BRAND: unique symbol;
10
+ /** Represents a value that is present. The value itself is the Some - no wrapper object. */
11
+ export type Some<T> = ValueType<T> & {
12
+ readonly [SOME_BRAND]: true;
13
+ };
14
+ /** Represents the absence of a value (null or undefined). */
15
+ export type None = NoneValueType & {
16
+ readonly [SOME_BRAND]: false;
17
+ };
18
+ /** Constant representing None. Use this instead of null/undefined for clarity. */
19
+ export declare const NONE: None;
20
+ /** A value that may or may not be present. Some(T) is the value itself; None is null/undefined. */
21
+ export type Option<T> = Some<ValueType<T>> | None;
22
+ /** Extracts the value type from an Option type. */
23
+ export type OptionValue<TOption> = TOption extends Option<infer TValue> ? TValue : never;
24
+ /** Type predicate: true if T is an Option type. */
25
+ export type IsOption<T> = T extends Option<any> ? true : false;
26
+ /** Infers the Some type from a value, preserving the inner type. */
27
+ export type InferSome<T> = T extends Some<infer TValue> ? Some<ValueType<TValue>> : never;
28
+ /**
29
+ * Checks if an Option contains a value (is Some).
30
+ * @param opt - The Option to check
31
+ * @returns true if the Option is Some, false if None
32
+ * @example
33
+ * isSome(42) // true
34
+ * isSome(null) // false
35
+ * isSome(undefined) // false
36
+ */
37
+ export declare function isSome<T>(opt: Some<T>): true;
38
+ export declare function isSome(opt: None): false;
39
+ export declare function isSome<T>(opt: unknown): opt is Some<T>;
40
+ /**
41
+ * Checks if an Option is None (absent).
42
+ * @param opt - The Option to check
43
+ * @returns true if the Option is None, false if Some
44
+ * @example
45
+ * isNone(null) // true
46
+ * isNone(undefined) // true
47
+ * isNone(42) // false
48
+ */
49
+ export declare function isNone<T>(opt: Some<T>): false;
50
+ export declare function isNone(opt: None): true;
51
+ export declare function isNone(opt: unknown): opt is None;
52
+ /**
53
+ * Creates an Option from a nullable value. Returns None for null/undefined, Some otherwise.
54
+ * @param value - The value to wrap
55
+ * @returns Some(value) if value is non-null, None otherwise
56
+ * @example
57
+ * optionOf(42) // Some(42)
58
+ * optionOf(null) // None
59
+ * optionOf(undefined) // None
60
+ */
61
+ export declare function optionOf(value: null): None;
62
+ export declare function optionOf(value: undefined): None;
63
+ export declare function optionOf<T>(value: T): T extends NoneValueType ? None : Some<T>;
64
+ /**
65
+ * Creates a Some value. Does not validate - use safe.some() for validation.
66
+ * @param value - The value to wrap (must be non-null)
67
+ * @returns The value typed as Some
68
+ * @example
69
+ * some(42) // Some(42)
70
+ */
71
+ export declare function some<T>(value: ValueType<T>): Some<ValueType<T>>;
72
+ /** Constant representing None. Alias for NONE. */
73
+ export declare const none: None;
74
+ declare const OK_BRAND: unique symbol;
75
+ /** Represents a successful Result value. The value itself is the Ok - no wrapper object. */
76
+ export type Ok<T> = T & {
77
+ readonly [OK_BRAND]: true;
78
+ };
79
+ declare const ERR_BRAND: unique symbol;
80
+ interface ResultErrorShape<E> {
81
+ readonly error: E;
82
+ readonly [ERR_BRAND]: true;
83
+ }
84
+ /** The error wrapper type used internally. */
85
+ export type ResultError<E> = ResultErrorShape<E>;
86
+ /** Represents a failed Result containing an error. */
87
+ export type Err<E> = ResultError<E>;
88
+ /** A value that is either successful (Ok) or failed (Err). Ok is the value itself; Err wraps the error. */
89
+ export type Result<T, E> = Ok<T> | Err<E>;
90
+ /** Extracts the success value type from a Result type. */
91
+ export type ResultValue<TResult> = TResult extends Result<infer TValue, any> ? TValue : never;
92
+ /** Extracts the error type from a Result type. */
93
+ export type ResultErrorType<TResult> = TResult extends Result<any, infer TError> ? TError : never;
94
+ /** Type predicate: true if T is a Result type. */
95
+ export type IsResult<T> = T extends Result<any, any> ? true : false;
96
+ /** Infers the Err type from a value, preserving the error type. */
97
+ export type InferErr<T> = T extends Err<infer TError> ? Err<TError> : never;
98
+ /**
99
+ * Checks if a Result is Ok (successful).
100
+ * @param result - The Result to check
101
+ * @returns true if the Result is Ok, false if Err
102
+ * @example
103
+ * isOk(42) // true (Ok value)
104
+ * isOk(err('fail')) // false
105
+ */
106
+ export declare function isOk<T>(result: Ok<T>): true;
107
+ export declare function isOk<E>(result: Err<E>): false;
108
+ export declare function isOk<T, E>(result: Result<T, E>): result is Ok<T>;
109
+ /**
110
+ * Checks if a Result is Err (failed).
111
+ * @param result - The Result to check
112
+ * @returns true if the Result is Err, false if Ok
113
+ * @example
114
+ * isErr(err('fail')) // true
115
+ * isErr(42) // false (Ok value)
116
+ */
117
+ export declare function isErr<E>(result: Err<E>): true;
118
+ export declare function isErr(result: Ok<any>): false;
119
+ export declare function isErr<T, E>(result: Result<T, E>): result is Err<E>;
120
+ /**
121
+ * Creates an Ok value. Does not validate - use safe.ok() for validation.
122
+ * @param value - The success value
123
+ * @returns The value typed as Ok
124
+ * @example
125
+ * ok(42) // Ok(42)
126
+ */
127
+ export declare function ok<T>(value: T): Ok<T>;
128
+ /**
129
+ * Creates an Err value wrapping an error.
130
+ * @param error - The error value
131
+ * @returns An Err containing the error
132
+ * @example
133
+ * err('something went wrong') // Err('something went wrong')
134
+ * err(new Error('failed')) // Err(Error)
135
+ */
136
+ export declare function err<E>(error: E): Err<E>;
137
+ export {};
package/build/types.js ADDED
@@ -0,0 +1,36 @@
1
+ export const NONE = undefined;
2
+ export function isSome(opt) {
3
+ return opt !== null && opt !== undefined;
4
+ }
5
+ export function isNone(opt) {
6
+ return opt === null || opt === undefined;
7
+ }
8
+ export function optionOf(value) {
9
+ return isNone(value) ? NONE : value;
10
+ }
11
+ export function some(value) {
12
+ return value;
13
+ }
14
+ export const none = NONE;
15
+ const ERR_BRAND = Symbol.for('nalloc.ResultError');
16
+ function ResultErrorCtor(error) {
17
+ this.error = error;
18
+ }
19
+ ResultErrorCtor.prototype[ERR_BRAND] = true;
20
+ function hasErrBrand(value) {
21
+ return value?.[ERR_BRAND] === true;
22
+ }
23
+ export function isOk(result) {
24
+ return !hasErrBrand(result);
25
+ }
26
+ export function isErr(result) {
27
+ return hasErrBrand(result);
28
+ }
29
+ export function ok(value) {
30
+ return value;
31
+ }
32
+ export function err(error) {
33
+ return new ResultErrorCtor(error);
34
+ }
35
+
36
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["/** Values that represent None (absence of a value). */\nexport type NoneValueType = null | undefined | void;\n\n/** Widens literal types to their base types for better type inference. */\nexport type Widen<T> = T extends string\n ? string\n : T extends number\n ? number\n : T extends boolean\n ? boolean\n : T extends bigint\n ? bigint\n : T extends symbol\n ? symbol\n : T;\n\n/** Widens never to unknown, otherwise preserves the type. */\nexport type WidenNever<T> = [T] extends [never] ? unknown : T;\n\n/** Excludes None values from a type, leaving only valid Some values. */\nexport type ValueType<T> = Exclude<T, NoneValueType>;\n\nexport declare const SOME_BRAND: unique symbol;\n\n/** Represents a value that is present. The value itself is the Some - no wrapper object. */\nexport type Some<T> = ValueType<T> & { readonly [SOME_BRAND]: true };\n\n/** Represents the absence of a value (null or undefined). */\nexport type None = NoneValueType & { readonly [SOME_BRAND]: false };\n\n/** Constant representing None. Use this instead of null/undefined for clarity. */\nexport const NONE = undefined as None;\n\n/** A value that may or may not be present. Some(T) is the value itself; None is null/undefined. */\nexport type Option<T> = Some<ValueType<T>> | None;\n\n/** Extracts the value type from an Option type. */\nexport type OptionValue<TOption> = TOption extends Option<infer TValue> ? TValue : never;\n\n/** Type predicate: true if T is an Option type. */\nexport type IsOption<T> = T extends Option<any> ? true : false;\n\n/** Infers the Some type from a value, preserving the inner type. */\nexport type InferSome<T> = T extends Some<infer TValue> ? Some<ValueType<TValue>> : never;\n\n/**\n * Checks if an Option contains a value (is Some).\n * @param opt - The Option to check\n * @returns true if the Option is Some, false if None\n * @example\n * isSome(42) // true\n * isSome(null) // false\n * isSome(undefined) // false\n */\nexport function isSome<T>(opt: Some<T>): true;\nexport function isSome(opt: None): false;\nexport function isSome<T>(opt: unknown): opt is Some<T>;\nexport function isSome(opt: unknown): boolean {\n return opt !== null && opt !== undefined;\n}\n\n/**\n * Checks if an Option is None (absent).\n * @param opt - The Option to check\n * @returns true if the Option is None, false if Some\n * @example\n * isNone(null) // true\n * isNone(undefined) // true\n * isNone(42) // false\n */\nexport function isNone<T>(opt: Some<T>): false;\nexport function isNone(opt: None): true;\nexport function isNone(opt: unknown): opt is None;\nexport function isNone(opt: unknown): boolean {\n return opt === null || opt === undefined;\n}\n\n/**\n * Creates an Option from a nullable value. Returns None for null/undefined, Some otherwise.\n * @param value - The value to wrap\n * @returns Some(value) if value is non-null, None otherwise\n * @example\n * optionOf(42) // Some(42)\n * optionOf(null) // None\n * optionOf(undefined) // None\n */\nexport function optionOf(value: null): None;\nexport function optionOf(value: undefined): None;\nexport function optionOf<T>(value: T): T extends NoneValueType ? None : Some<T>;\nexport function optionOf<T>(value: T): Option<T> {\n return isNone(value as Option<T>) ? NONE : (value as Some<T>);\n}\n\n/**\n * Creates a Some value. Does not validate - use safe.some() for validation.\n * @param value - The value to wrap (must be non-null)\n * @returns The value typed as Some\n * @example\n * some(42) // Some(42)\n */\nexport function some<T>(value: ValueType<T>): Some<ValueType<T>> {\n return value as Some<ValueType<T>>;\n}\n\n/** Constant representing None. Alias for NONE. */\nexport const none: None = NONE;\n\ndeclare const OK_BRAND: unique symbol;\n\n/** Represents a successful Result value. The value itself is the Ok - no wrapper object. */\nexport type Ok<T> = T & { readonly [OK_BRAND]: true };\n\nconst ERR_BRAND = Symbol.for('nalloc.ResultError');\n\ninterface ResultErrorShape<E> {\n readonly error: E;\n readonly [ERR_BRAND]: true;\n}\n\nfunction ResultErrorCtor<E>(this: ResultErrorShape<E>, error: E): void {\n (this as { error: E }).error = error;\n}\n(ResultErrorCtor.prototype as { [ERR_BRAND]: true })[ERR_BRAND] = true;\n\n/** The error wrapper type used internally. */\nexport type ResultError<E> = ResultErrorShape<E>;\n\nfunction hasErrBrand(value: unknown): value is ResultError<unknown> {\n return (value as Record<symbol, unknown>)?.[ERR_BRAND] === true;\n}\n\n/** Represents a failed Result containing an error. */\nexport type Err<E> = ResultError<E>;\n\n/** A value that is either successful (Ok) or failed (Err). Ok is the value itself; Err wraps the error. */\nexport type Result<T, E> = Ok<T> | Err<E>;\n\n/** Extracts the success value type from a Result type. */\nexport type ResultValue<TResult> = TResult extends Result<infer TValue, any> ? TValue : never;\n\n/** Extracts the error type from a Result type. */\nexport type ResultErrorType<TResult> = TResult extends Result<any, infer TError> ? TError : never;\n\n/** Type predicate: true if T is a Result type. */\nexport type IsResult<T> = T extends Result<any, any> ? true : false;\n\n/** Infers the Err type from a value, preserving the error type. */\nexport type InferErr<T> = T extends Err<infer TError> ? Err<TError> : never;\n\n/**\n * Checks if a Result is Ok (successful).\n * @param result - The Result to check\n * @returns true if the Result is Ok, false if Err\n * @example\n * isOk(42) // true (Ok value)\n * isOk(err('fail')) // false\n */\nexport function isOk<T>(result: Ok<T>): true;\nexport function isOk<E>(result: Err<E>): false;\nexport function isOk<T, E>(result: Result<T, E>): result is Ok<T>;\nexport function isOk<T, E>(result: Result<T, E>): boolean {\n return !hasErrBrand(result);\n}\n\n/**\n * Checks if a Result is Err (failed).\n * @param result - The Result to check\n * @returns true if the Result is Err, false if Ok\n * @example\n * isErr(err('fail')) // true\n * isErr(42) // false (Ok value)\n */\nexport function isErr<E>(result: Err<E>): true;\nexport function isErr(result: Ok<any>): false;\nexport function isErr<T, E>(result: Result<T, E>): result is Err<E>;\nexport function isErr<T, E>(result: Result<T, E>): boolean {\n return hasErrBrand(result);\n}\n\n/**\n * Creates an Ok value. Does not validate - use safe.ok() for validation.\n * @param value - The success value\n * @returns The value typed as Ok\n * @example\n * ok(42) // Ok(42)\n */\nexport function ok<T>(value: T): Ok<T> {\n return value as Ok<T>;\n}\n\n/**\n * Creates an Err value wrapping an error.\n * @param error - The error value\n * @returns An Err containing the error\n * @example\n * err('something went wrong') // Err('something went wrong')\n * err(new Error('failed')) // Err(Error)\n */\nexport function err<E>(error: E): Err<E> {\n return new (ResultErrorCtor as unknown as new (error: E) => Err<E>)(error);\n}\n"],"names":["NONE","undefined","isSome","opt","isNone","optionOf","value","some","none","ERR_BRAND","Symbol","for","ResultErrorCtor","error","prototype","hasErrBrand","isOk","result","isErr","ok","err"],"mappings":"AA+BA,OAAO,MAAMA,OAAOC,UAAkB;AA0BtC,OAAO,SAASC,OAAOC,GAAY;IACjC,OAAOA,QAAQ,QAAQA,QAAQF;AACjC;AAcA,OAAO,SAASG,OAAOD,GAAY;IACjC,OAAOA,QAAQ,QAAQA,QAAQF;AACjC;AAcA,OAAO,SAASI,SAAYC,KAAQ;IAClC,OAAOF,OAAOE,SAAsBN,OAAQM;AAC9C;AASA,OAAO,SAASC,KAAQD,KAAmB;IACzC,OAAOA;AACT;AAGA,OAAO,MAAME,OAAaR,KAAK;AAO/B,MAAMS,YAAYC,OAAOC,GAAG,CAAC;AAO7B,SAASC,gBAA8CC,KAAQ;IAC7D,AAAC,IAAI,CAAkBA,KAAK,GAAGA;AACjC;AACCD,gBAAgBE,SAAS,AAA0B,CAACL,UAAU,GAAG;AAKlE,SAASM,YAAYT,KAAc;IACjC,OAAO,AAACA,OAAmC,CAACG,UAAU,KAAK;AAC7D;AA+BA,OAAO,SAASO,KAAWC,MAAoB;IAC7C,OAAO,CAACF,YAAYE;AACtB;AAaA,OAAO,SAASC,MAAYD,MAAoB;IAC9C,OAAOF,YAAYE;AACrB;AASA,OAAO,SAASE,GAAMb,KAAQ;IAC5B,OAAOA;AACT;AAUA,OAAO,SAASc,IAAOP,KAAQ;IAC7B,OAAO,IAAKD,gBAAwDC;AACtE"}
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get Option () {
13
+ return _optioncjs;
14
+ },
15
+ get Result () {
16
+ return _resultcjs;
17
+ },
18
+ get err () {
19
+ return _typescjs.err;
20
+ },
21
+ get none () {
22
+ return _typescjs.none;
23
+ },
24
+ get ok () {
25
+ return ok;
26
+ },
27
+ get some () {
28
+ return some;
29
+ }
30
+ });
31
+ const _typescjs = require("./types.cjs");
32
+ const _optioncjs = /*#__PURE__*/ _interop_require_wildcard(require("./option.cjs"));
33
+ const _resultcjs = /*#__PURE__*/ _interop_require_wildcard(require("./result.cjs"));
34
+ function _getRequireWildcardCache(nodeInterop) {
35
+ if (typeof WeakMap !== "function") return null;
36
+ var cacheBabelInterop = new WeakMap();
37
+ var cacheNodeInterop = new WeakMap();
38
+ return (_getRequireWildcardCache = function(nodeInterop) {
39
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
40
+ })(nodeInterop);
41
+ }
42
+ function _interop_require_wildcard(obj, nodeInterop) {
43
+ if (!nodeInterop && obj && obj.__esModule) {
44
+ return obj;
45
+ }
46
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
47
+ return {
48
+ default: obj
49
+ };
50
+ }
51
+ var cache = _getRequireWildcardCache(nodeInterop);
52
+ if (cache && cache.has(obj)) {
53
+ return cache.get(obj);
54
+ }
55
+ var newObj = {
56
+ __proto__: null
57
+ };
58
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
59
+ for(var key in obj){
60
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
61
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
62
+ if (desc && (desc.get || desc.set)) {
63
+ Object.defineProperty(newObj, key, desc);
64
+ } else {
65
+ newObj[key] = obj[key];
66
+ }
67
+ }
68
+ }
69
+ newObj.default = obj;
70
+ if (cache) {
71
+ cache.set(obj, newObj);
72
+ }
73
+ return newObj;
74
+ }
75
+ function some(value) {
76
+ return value;
77
+ }
78
+ function ok(value) {
79
+ return value;
80
+ }
81
+
82
+ //# sourceMappingURL=unsafe.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/unsafe.ts"],"sourcesContent":["import type { Some, Ok } from './types.js';\nexport { none, err } from './types.js';\nexport type {\n Some,\n None,\n Ok,\n Err,\n Option as OptionType,\n OptionValue,\n IsOption,\n InferSome,\n Result as ResultType,\n ResultValue,\n ResultErrorType,\n IsResult,\n InferErr,\n} from './types.js';\nexport * as Option from './option.js';\nexport * as Result from './result.js';\n\n/**\n * Creates a Some value without runtime validation.\n * Use when you are certain the value is non-nullable.\n * For validated creation, use safe.some() instead.\n * @param value - The value to wrap (assumed non-nullable)\n * @returns The value typed as Some\n * @example\n * some(42) // Some(42)\n * some(null) // Some(null) - no validation, may cause issues\n */\nexport function some<T>(value: T): Some<T> {\n return value as unknown as Some<T>;\n}\n\n/**\n * Creates an Ok value without runtime validation.\n * Use when you are certain the value is not an Err.\n * For validated creation, use safe.ok() instead.\n * @param value - The success value (assumed not an Err)\n * @returns The value typed as Ok\n * @example\n * ok(42) // Ok(42)\n * ok(err('fail')) // Ok(Err) - no validation, may cause issues\n */\nexport function ok<T>(value: T): Ok<T> {\n return value as Ok<T>;\n}\n"],"names":["Option","Result","err","none","ok","some","value"],"mappings":";;;;;;;;;;;QAiBYA;;;QACAC;;;QAjBGC;eAAAA,aAAG;;QAATC;eAAAA,cAAI;;QA2CGC;eAAAA;;QAdAC;eAAAA;;;0BA7BU;mEAgBF;mEACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYjB,SAASA,KAAQC,KAAQ;IAC9B,OAAOA;AACT;AAYO,SAASF,GAAME,KAAQ;IAC5B,OAAOA;AACT"}
@@ -0,0 +1,27 @@
1
+ import type { Some, Ok } from './types.js';
2
+ export { none, err } from './types.js';
3
+ export type { Some, None, Ok, Err, Option as OptionType, OptionValue, IsOption, InferSome, Result as ResultType, ResultValue, ResultErrorType, IsResult, InferErr, } from './types.js';
4
+ export * as Option from './option.js';
5
+ export * as Result from './result.js';
6
+ /**
7
+ * Creates a Some value without runtime validation.
8
+ * Use when you are certain the value is non-nullable.
9
+ * For validated creation, use safe.some() instead.
10
+ * @param value - The value to wrap (assumed non-nullable)
11
+ * @returns The value typed as Some
12
+ * @example
13
+ * some(42) // Some(42)
14
+ * some(null) // Some(null) - no validation, may cause issues
15
+ */
16
+ export declare function some<T>(value: T): Some<T>;
17
+ /**
18
+ * Creates an Ok value without runtime validation.
19
+ * Use when you are certain the value is not an Err.
20
+ * For validated creation, use safe.ok() instead.
21
+ * @param value - The success value (assumed not an Err)
22
+ * @returns The value typed as Ok
23
+ * @example
24
+ * ok(42) // Ok(42)
25
+ * ok(err('fail')) // Ok(Err) - no validation, may cause issues
26
+ */
27
+ export declare function ok<T>(value: T): Ok<T>;
@@ -0,0 +1,11 @@
1
+ export { none, err } from "./types.js";
2
+ export * as Option from "./option.js";
3
+ export * as Result from "./result.js";
4
+ export function some(value) {
5
+ return value;
6
+ }
7
+ export function ok(value) {
8
+ return value;
9
+ }
10
+
11
+ //# sourceMappingURL=unsafe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/unsafe.ts"],"sourcesContent":["import type { Some, Ok } from './types.js';\nexport { none, err } from './types.js';\nexport type {\n Some,\n None,\n Ok,\n Err,\n Option as OptionType,\n OptionValue,\n IsOption,\n InferSome,\n Result as ResultType,\n ResultValue,\n ResultErrorType,\n IsResult,\n InferErr,\n} from './types.js';\nexport * as Option from './option.js';\nexport * as Result from './result.js';\n\n/**\n * Creates a Some value without runtime validation.\n * Use when you are certain the value is non-nullable.\n * For validated creation, use safe.some() instead.\n * @param value - The value to wrap (assumed non-nullable)\n * @returns The value typed as Some\n * @example\n * some(42) // Some(42)\n * some(null) // Some(null) - no validation, may cause issues\n */\nexport function some<T>(value: T): Some<T> {\n return value as unknown as Some<T>;\n}\n\n/**\n * Creates an Ok value without runtime validation.\n * Use when you are certain the value is not an Err.\n * For validated creation, use safe.ok() instead.\n * @param value - The success value (assumed not an Err)\n * @returns The value typed as Ok\n * @example\n * ok(42) // Ok(42)\n * ok(err('fail')) // Ok(Err) - no validation, may cause issues\n */\nexport function ok<T>(value: T): Ok<T> {\n return value as Ok<T>;\n}\n"],"names":["none","err","Option","Result","some","value","ok"],"mappings":"AACA,SAASA,IAAI,EAAEC,GAAG,QAAQ,aAAa;AAgBvC,OAAO,KAAKC,MAAM,MAAM,cAAc;AACtC,OAAO,KAAKC,MAAM,MAAM,cAAc;AAYtC,OAAO,SAASC,KAAQC,KAAQ;IAC9B,OAAOA;AACT;AAYA,OAAO,SAASC,GAAMD,KAAQ;IAC5B,OAAOA;AACT"}
package/package.json ADDED
@@ -0,0 +1,93 @@
1
+ {
2
+ "name": "nalloc",
3
+ "description": "Rust-like Option and Result for TypeScript with near-zero allocations for extreme performance",
4
+ "version": "0.0.1",
5
+ "type": "module",
6
+ "types": "build/index.d.ts",
7
+ "main": "build/index.cjs",
8
+ "module": "build/index.js",
9
+ "exports": {
10
+ ".": {
11
+ "require": "./build/index.cjs",
12
+ "import": "./build/index.js"
13
+ },
14
+ "./types": {
15
+ "require": "./build/types.cjs",
16
+ "import": "./build/types.js"
17
+ },
18
+ "./option": {
19
+ "require": "./build/option.cjs",
20
+ "import": "./build/option.js"
21
+ },
22
+ "./result": {
23
+ "require": "./build/result.cjs",
24
+ "import": "./build/result.js"
25
+ },
26
+ "./safe": {
27
+ "require": "./build/safe.cjs",
28
+ "import": "./build/safe.js"
29
+ },
30
+ "./unsafe": {
31
+ "require": "./build/unsafe.cjs",
32
+ "import": "./build/unsafe.js"
33
+ },
34
+ "./testing": {
35
+ "require": "./build/testing.cjs",
36
+ "import": "./build/testing.js"
37
+ },
38
+ "./devtools": {
39
+ "require": "./build/devtools.cjs",
40
+ "import": "./build/devtools.js"
41
+ },
42
+ "./package.json": "./package.json"
43
+ },
44
+ "files": [
45
+ "build",
46
+ "src"
47
+ ],
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/3axap4eHko/nalloc.git"
51
+ },
52
+ "keywords": [
53
+ "option",
54
+ "result",
55
+ "maybe",
56
+ "either",
57
+ "rust",
58
+ "typescript",
59
+ "type-safe",
60
+ "monad",
61
+ "functional",
62
+ "error-handling",
63
+ "pattern-matching",
64
+ "zero-allocation",
65
+ "performance"
66
+ ],
67
+ "author": "Ivan Zakharchanka",
68
+ "license": "MIT",
69
+ "bugs": {
70
+ "url": "https://github.com/3axap4eHko/nalloc/issues"
71
+ },
72
+ "homepage": "https://github.com/3axap4eHko/nalloc#readme",
73
+ "devDependencies": {
74
+ "@eslint/js": "^9.39.2",
75
+ "@vitest/coverage-v8": "^4.0.16",
76
+ "eslint": "^9.39.2",
77
+ "eslint-plugin-prettier": "^5.5.4",
78
+ "inop": "^0.8.10",
79
+ "prettier": "^3.7.4",
80
+ "tsafe": "^1.8.12",
81
+ "tslib": "^2.8.1",
82
+ "typescript": "^5.9.3",
83
+ "typescript-eslint": "^8.52.0",
84
+ "vitest": "^4.0.16"
85
+ },
86
+ "scripts": {
87
+ "check": "tsc src/__tests__/option.types.ts src/__tests__/result.types.ts --noEmit --lib esnext,dom --target esnext --module nodenext --moduleResolution nodenext",
88
+ "build": "rm -rf build && inop src build -i __tests__ -i *.tmp.ts && tsc --declaration --emitDeclarationOnly",
89
+ "lint": "eslint .",
90
+ "test": "vitest run",
91
+ "bench": "overtake benchmarks/*"
92
+ }
93
+ }
@@ -0,0 +1,13 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import * as index from '../index.js';
3
+
4
+ describe('index.ts exports', () => {
5
+ it('exports exist', () => {
6
+ expect(index.some).toBeDefined();
7
+ expect('none' in index).toBe(true);
8
+ expect(index.ok).toBeDefined();
9
+ expect(index.err).toBeDefined();
10
+ expect(index.Option).toBeDefined();
11
+ expect(index.Result).toBeDefined();
12
+ });
13
+ });