@consolidados/results 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/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/result/index.cjs +3 -0
- package/dist/result/index.cjs.map +1 -1
- package/dist/result/index.js +2 -0
- package/dist/result/index.js.map +1 -1
- package/dist/result/result.cjs +5 -0
- package/dist/result/result.cjs.map +1 -1
- package/dist/result/result.js +2 -0
- package/dist/result/result.js.map +1 -1
- package/package.json +72 -71
package/dist/index.cjs
CHANGED
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/helpers/match.ts","../src/option/__internal__/return-types/some.ts","../src/option/__internal__/return-types/none.ts","../src/option/option.ts","../src/result/__internal__/return-types/err.ts","../src/result/__internal__/return-types/ok.ts","../src/result/result.ts"],"names":["match","Some","None","Ok","Err"],"mappings":";;;AAiBO,SAASA,MAAAA,CACd,SACA,KAMG,EAAA;AACH,EAAA,IAAI,MAAU,IAAA,OAAA,IAAW,OAAQ,CAAA,IAAA,EAAQ,EAAA;AACvC,IAAA,IAAI,CAAC,KAAM,CAAA,EAAA,EAAU,MAAA,IAAI,MAAM,qBAAqB,CAAA;AACpD,IAAA,OAAO,KAAM,CAAA,EAAA,CAAG,OAAQ,CAAA,MAAA,EAAQ,CAAA;AAAA;AAGlC,EAAA,IAAI,OAAW,IAAA,OAAA,IAAW,OAAQ,CAAA,KAAA,EAAS,EAAA;AACzC,IAAA,IAAI,CAAC,KAAM,CAAA,GAAA,EAAW,MAAA,IAAI,MAAM,sBAAsB,CAAA;AACtD,IAAA,OAAO,KAAM,CAAA,GAAA,CAAI,OAAQ,CAAA,SAAA,EAAgB,CAAA;AAAA;AAG3C,EAAA,IAAI,QAAY,IAAA,OAAA,IAAW,OAAQ,CAAA,MAAA,EAAU,EAAA;AAC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A;AACT;AAAA;AAAA;AAAA;AAAA,EAMA,MAAY,GAAA;AACV,IAAA,OAAO,IAAK,CAAA,KAAA;AAAA;AACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IAAO,EAAiD,EAAA;AACtD,IAAA,OAAO,IAAI,GAAA,CAAG,EAAG,CAAA,IAAA,CAAK,KAAK,CAAC,CAAA;AAAA;AAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,QACE,EAC4B,EAAA;AAC5B,IAAO,OAAA,EAAA,CAAG,KAAK,KAAK,CAAA;AAAA;AACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAwB,GAAgD,EAAA;AACtE,IAAO,OAAA,IAAA;AAAA;AACT;AAAA;AAAA;AAAA;AAAA,EAMA,SAAmB,GAAA;AACjB,IAAM,MAAA,IAAI,MAAM,iCAAiC,CAAA;AAAA;AACnD;AAAA;AAAA;AAAA;AAAA,EAMA,EAAK,GAAA;AACH,IAAA,OAAO,MAAM,IAAM,EAAA;AAAA,MACjB,EAAI,EAAA,CAAC,CAAM,KAAA,IAAA,CAAK,CAAC,CAAA;AAAA,MACjB,GAAA,EAAK,CAAC,CAAA,KAAM,IAAK;AAAA,KAClB,CAAA;AAAA;AAEL,CAAA;;;ACzEA,SAASC,IAAM,KAAqB,EAAA;AAClC,EAAO,OAAA,IAAI,GAAO,KAAK,CAAA;AACzB;AAYA,SAASC,KAAqB,KAA+B,EAAA;AAC3D,EAAO,OAAA,IAAI,IAAQ,KAAK,CAAA;AAC1B;AAGC,MAAA,CAAe,EAAKD,GAAAA,GAAAA;AAEpB,MAAA,CAAe,GAAMC,GAAAA,IAAAA","file":"index.cjs","sourcesContent":["import type { Option } from \"../option\";\nimport type { Result } from \"../result\";\n\nexport function match<T, E extends Error, R>(\n matcher: Result<T, E>,\n cases: {\n Ok: (value: T) => R;\n Err: (error: E) => R;\n },\n): R;\nexport function match<T, R>(\n matcher: Option<T>,\n cases: {\n Some: (value: T) => R;\n None: () => R;\n },\n): R;\nexport function match<T, E extends Error, R>(\n matcher: Result<T, E> | Option<T>,\n cases: {\n Ok?: (value: T) => R;\n Err?: (error: E) => R;\n Some?: (value: T) => R;\n None?: () => R;\n },\n): R {\n if (\"isOk\" in matcher && matcher.isOk()) {\n if (!cases.Ok) throw new Error(\"Missing case for Ok\");\n return cases.Ok(matcher.unwrap());\n }\n\n if (\"isErr\" in matcher && matcher.isErr()) {\n if (!cases.Err) throw new Error(\"Missing case for Err\");\n return cases.Err(matcher.unwrapErr() as E);\n }\n\n if (\"isSome\" in matcher && matcher.isSome()) {\n if (!cases.Some) throw new Error(\"Missing case for Some\");\n return cases.Some(matcher.unwrap());\n }\n\n if (\"isNone\" in matcher && matcher.isNone()) {\n if (!cases.None) throw new Error(\"Missing case for None\");\n return cases.None();\n }\n\n throw new Error(\"Invalid matcher or missing case\");\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).match = match;\n","import type { None } from \"./none\";\nimport type { Option } from \"./option\";\n\n/**\n * Represents a `Some` option, which holds a value.\n * @template T The type of the value held by this `Some` instance.\n */\nexport class Some<T> {\n /**\n * Creates a new `Some` option with the given value.\n * @param value The value to be wrapped in the `Some` option.\n */\n constructor(private value: T) { }\n\n /**\n * Checks if this option is a `Some`.\n * @returns `true` if this option is a `Some`, otherwise `false`.\n */\n isSome(): this is Some<T> {\n return true;\n }\n\n /**\n * Checks if this option is a `None`.\n * @returns `false` because this is a `Some`.\n */\n isNone(): this is None {\n return false;\n }\n\n /**\n * Unwraps the value held by this `Some` option.\n * @returns The value held by this `Some` option.\n */\n unwrap(): T {\n return this.value;\n }\n\n /**\n * Applies a transformation function to the value held by this `Some` option and returns a new `Option` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Some` option containing the transformed value.\n */\n map<U>(fn: (value: T) => U): Option<U> {\n return new Some(fn(this.value));\n }\n\n /**\n * Applies a transformation function that returns an `Option` to the value held by this `Some` option.\n * @template U The type of the value in the resulting `Option`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U>(fn: (value: T) => Option<U>): Option<U> {\n return fn(this.value);\n }\n\n /**\n * Returns the value held by this `Some` option, ignoring the default value provided.\n * @param _ A default value (ignored in this implementation).\n * @returns The value held by this `Some` option.\n */\n unwrapOr(_: T): T {\n return this.value;\n }\n}\n","import type { Some } from \"./some\";\nimport type { Option } from \"./option\";\n\n/**\n * Represents a `None` option, which holds no value.\n */\nexport class None {\n /**\n * Checks if this option is a `Some`.\n * @returns `false` because this is a `None`.\n */\n isSome(): this is Some<never> {\n return false;\n }\n\n /**\n * Checks if this option is a `None`.\n * @returns `true` because this is a `None`.\n */\n isNone(): this is None {\n return true;\n }\n\n /**\n * Attempts to unwrap the value from this `None` option.\n * @throws An error because `None` has no value.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on a None value\");\n }\n\n /**\n * Applies a transformation function to the value (which does not exist) of this `None` option.\n * @template U The type of the value that would have been returned.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns A new `None` option.\n */\n map<U>(_fn: (value: never) => U): Option<U> {\n return new None();\n }\n\n /**\n * Applies a transformation function that returns an `Option` to the value (which does not exist) of this `None` option.\n * @template U The type of the value in the resulting `Option`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns A new `None` option.\n */\n flatMap<U>(_fn: (value: never) => Option<U>): Option<U> {\n return new None();\n }\n\n /**\n * Returns the default value provided, since `None` has no value.\n * @template T The type of the default value.\n * @param defaultValue The value to return.\n * @returns The default value provided.\n */\n unwrapOr<T>(defaultValue: T): T {\n return defaultValue;\n }\n}\n","import {\n\tSome as SomeType,\n\tNone as NoneType,\n\ttype Option,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Some` instance, representing an `Option` with a value.\n * @template T The type of the value contained in the `Some`.\n * @param value The value to wrap in the `Some` instance.\n * @returns A `Some` instance containing the given value.\n * @example\n * const option = Some(42);\n * console.log(option.isSome()); // true\n * console.log(option.unwrap()); // 42\n */\nfunction Some<T>(value: T): SomeType<T> {\n\treturn new SomeType(value);\n}\n\n/**\n * Creates a new `None` instance, representing an `Option` with no value.\n * @returns A `None` instance.\n * @example\n * const option = None();\n * console.log(option.isNone()); // true\n * console.log(option.unwrap()); // throws Error: \"Called unwrap on a None value\"\n */\nfunction None(): NoneType {\n\treturn new NoneType();\n}\n\n(global as any).Some = Some;\n(global as any).None = None;\n\nexport { None, Some, Option };\n","import type { Ok } from \"./ok\";\nimport type { ResultDefinition } from \"./result\";\n\n/**\n * Represents a failed result (`Err`) that contains an error value.\n * @template E The type of the error contained in this `Err`.\n */\nexport class Err<E extends Error>\n extends Error\n implements ResultDefinition<never, E>\n{\n private error: E;\n /**\n * Creates a new `Err` instance with the given error value.\n * @param error The error to wrap in the `Err` instance.\n */\n constructor(error: E | string) {\n super(typeof error === \"string\" ? error : error.message);\n this.error =\n typeof error === \"string\" ? (new Error(error) as E) : (error as E);\n Object.setPrototypeOf(this, Err.prototype);\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, Err);\n }\n }\n\n /**\n * Checks if this result is an `Ok`.\n * @returns `false` because this is an `Err`.\n */\n isOk(): this is Ok<never> {\n return false;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `true` because this is an `Err`.\n */\n isErr(): this is Err<E extends Error ? E : Error> {\n return true;\n }\n\n /**\n * Retrieves the value contained in this result. Since this is an `Err`, an error is thrown.\n * @throws An error because `unwrap` is called on an `Err`.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on an Err value\");\n }\n\n /**\n * Maps the value (if any). Since this is an `Err`, the mapping function is ignored, and the original `Err` is returned.\n * @template U The type of the value (ignored for `Err`).\n * @param _fn The mapping function for values (not used).\n * @returns The original `Err` instance.\n */\n map<U>(_fn: (value: never) => U): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Maps the error value using a transformation function and returns a new `Result` with the transformed error.\n * @template U The type of the transformed error.\n * @param fn The transformation function to apply to the error value.\n * @returns A new `Err` containing the transformed error.\n */\n mapErr<U extends Error>(fn: (err: E) => U): ResultDefinition<never, U> {\n return new Err<U>(fn(this.error)) as unknown as ResultDefinition<never, U>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value (which does not exist) of this `Err`.\n * @template U The type of the value in the resulting `Result`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns The original `Err` instance.\n */\n flatMap<U>(\n _fn: (value: never) => ResultDefinition<U, never>,\n ): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Retrieves the error value contained in this `Err`.\n * @returns The error value contained in this `Err`.\n */\n unwrapErr(): E {\n return this.error;\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return None();\n }\n}\n","import type { ResultDefinition } from \"./result\";\nimport type { Err } from \"./err\";\n\n/**\n * Represents a successful result (`Ok`) that contains a value.\n * @template T The type of the value contained in this `Ok`.\n */\nexport class Ok<T> implements ResultDefinition<T, never> {\n /**\n * Creates a new `Ok` instance with the given value.\n * @param value The value to wrap in the `Ok` instance.\n */\n constructor(private value: T) {}\n /**\n * Checks if this result is an `Ok`.\n * @returns `true` because this is an `Ok`.\n */\n isOk(): this is Ok<T> {\n return true;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `false` because this is an `Ok`.\n */\n isErr(): this is Err<never> {\n return false;\n }\n\n /**\n * Retrieves the value contained in this `Ok`.\n * @returns The value contained in this `Ok`.\n */\n unwrap(): T {\n return this.value;\n }\n\n /**\n * Applies a transformation function to the value contained in this `Ok` and returns a new `Result` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Ok` containing the transformed value.\n */\n map<U>(fn: (value: T) => U): ResultDefinition<U, never> {\n return new Ok(fn(this.value)) as ResultDefinition<U, never>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value contained in this `Ok`.\n * @template U The type of the value in the resulting `Result`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U>(\n fn: (value: T) => ResultDefinition<U, never>,\n ): ResultDefinition<U, never> {\n return fn(this.value);\n }\n\n /**\n * Maps the error value (if any). Since this is an `Ok`, the error mapping function is ignored, and the original `Ok` is returned.\n * @template U The type of the error (ignored for `Ok`).\n * @param _fn The mapping function for errors (not used).\n * @returns The original `Ok` instance.\n */\n // mapErr<U extends Error | string>(fn: (err: U) => U): Result<T, never> {\n // \treturn this;\n mapErr<U extends Error>(_fn: (err: never) => U): ResultDefinition<T, U> {\n return this as unknown as ResultDefinition<T, U>;\n }\n\n /**\n * Retrieves the error contained in this result. Since this is an `Ok`, an error is thrown.\n * @throws An error because `unwrapErr` is called on an `Ok`.\n */\n unwrapErr(): never {\n throw new Error(\"Called unwrapErr on an Ok value\");\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return match(this, {\n Ok: (v) => Some(v),\n Err: (_) => None(),\n });\n }\n}\n","import {\n Err as ErrType,\n Ok as OkType,\n type Result,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Ok` instance, representing a successful result.\n * @template T The type of the value contained in the `Ok`.\n * @param value The value to wrap in the `Ok` instance.\n * @returns An `Ok` instance containing the given value.\n * @example\n * const result = Ok(42);\n * console.log(result.isOk()); // true\n * console.log(result.unwrap()); // 42\n */\nfunction Ok<T>(value: T): OkType<T> {\n return new OkType(value);\n}\n\n/**\n * Creates a new `Err` instance, representing a failed result.\n * @template E The type of the error contained in the `Err`.\n * @param error The error to wrap in the `Err` instance.\n * @returns An `Err` instance containing the given error.\n * @example\n * const result = Err(\"Something went wrong\");\n * console.log(result.isErr()); // true\n * console.log(result.unwrapErr()); // \"Something went wrong\"\n */\nfunction Err<E extends Error>(error: E | string): ErrType<E> {\n return new ErrType(error);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Ok = Ok;\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Err = Err;\n\nexport type { Err, Ok, Result, ErrType, OkType };\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/helpers/match.ts","../src/option/__internal__/return-types/some.ts","../src/option/__internal__/return-types/none.ts","../src/option/option.ts","../src/result/__internal__/return-types/err.ts","../src/result/__internal__/return-types/ok.ts","../src/result/result.ts"],"names":["match","Some","None","Ok","Err"],"mappings":";;;AAiBO,SAASA,MAAAA,CACd,SACA,KAMG,EAAA;AACH,EAAA,IAAI,MAAU,IAAA,OAAA,IAAW,OAAQ,CAAA,IAAA,EAAQ,EAAA;AACvC,IAAA,IAAI,CAAC,KAAM,CAAA,EAAA,EAAU,MAAA,IAAI,MAAM,qBAAqB,CAAA;AACpD,IAAA,OAAO,KAAM,CAAA,EAAA,CAAG,OAAQ,CAAA,MAAA,EAAQ,CAAA;AAAA;AAGlC,EAAA,IAAI,OAAW,IAAA,OAAA,IAAW,OAAQ,CAAA,KAAA,EAAS,EAAA;AACzC,IAAA,IAAI,CAAC,KAAM,CAAA,GAAA,EAAW,MAAA,IAAI,MAAM,sBAAsB,CAAA;AACtD,IAAA,OAAO,KAAM,CAAA,GAAA,CAAI,OAAQ,CAAA,SAAA,EAAgB,CAAA;AAAA;AAG3C,EAAA,IAAI,QAAY,IAAA,OAAA,IAAW,OAAQ,CAAA,MAAA,EAAU,EAAA;AAC3C,IAAA,IAAI,CAAC,KAAM,CAAA,IAAA,EAAY,MAAA,IAAI,MAAM,uBAAuB,CAAA;AACxD,IAAA,OAAO,KAAM,CAAA,IAAA,CAAK,OAAQ,CAAA,MAAA,EAAQ,CAAA;AAAA;AAGpC,EAAA,IAAI,QAAY,IAAA,OAAA,IAAW,OAAQ,CAAA,MAAA,EAAU,EAAA;AAC3C,IAAA,IAAI,CAAC,KAAM,CAAA,IAAA,EAAY,MAAA,IAAI,MAAM,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,EAAA;AAC5B,IAAO,OAAA,EAAA,CAAG,KAAK,KAAK,CAAA;AAAA;AACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAwB,GAAgD,EAAA;AACtE,IAAO,OAAA,IAAA;AAAA;AACT;AAAA;AAAA;AAAA;AAAA,EAMA,SAAmB,GAAA;AACjB,IAAM,MAAA,IAAI,MAAM,iCAAiC,CAAA;AAAA;AACnD;AAAA;AAAA;AAAA;AAAA,EAMA,EAAK,GAAA;AACH,IAAA,OAAO,MAAM,IAAM,EAAA;AAAA,MACjB,EAAI,EAAA,CAAC,CAAM,KAAA,IAAA,CAAK,CAAC,CAAA;AAAA,MACjB,GAAA,EAAK,CAAC,CAAA,KAAM,IAAK;AAAA,KAClB,CAAA;AAAA;AAEL,CAAA;;;ACzEA,SAASC,IAAM,KAAqB,EAAA;AAClC,EAAO,OAAA,IAAI,GAAO,KAAK,CAAA;AACzB;AAYA,SAASC,KAAqB,KAA+B,EAAA;AAC3D,EAAO,OAAA,IAAI,IAAQ,KAAK,CAAA;AAC1B;AAGC,MAAA,CAAe,EAAKD,GAAAA,GAAAA;AAEpB,MAAA,CAAe,GAAMC,GAAAA,IAAAA","file":"index.cjs","sourcesContent":["import type { Option } from \"../option\";\nimport type { Result } from \"../result\";\n\nexport function match<T, E extends Error, R>(\n matcher: Result<T, E>,\n cases: {\n Ok: (value: T) => R;\n Err: (error: E) => R;\n },\n): R;\nexport function match<T, R>(\n matcher: Option<T>,\n cases: {\n Some: (value: T) => R;\n None: () => R;\n },\n): R;\nexport function match<T, E extends Error, R>(\n matcher: Result<T, E> | Option<T>,\n cases: {\n Ok?: (value: T) => R;\n Err?: (error: E) => R;\n Some?: (value: T) => R;\n None?: () => R;\n },\n): R {\n if (\"isOk\" in matcher && matcher.isOk()) {\n if (!cases.Ok) throw new Error(\"Missing case for Ok\");\n return cases.Ok(matcher.unwrap());\n }\n\n if (\"isErr\" in matcher && matcher.isErr()) {\n if (!cases.Err) throw new Error(\"Missing case for Err\");\n return cases.Err(matcher.unwrapErr() as E);\n }\n\n if (\"isSome\" in matcher && matcher.isSome()) {\n if (!cases.Some) throw new Error(\"Missing case for Some\");\n return cases.Some(matcher.unwrap());\n }\n\n if (\"isNone\" in matcher && matcher.isNone()) {\n if (!cases.None) throw new Error(\"Missing case for None\");\n return cases.None();\n }\n\n throw new Error(\"Invalid matcher or missing case\");\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).match = match;\n","import type { None } from \"./none\";\nimport type { Option } from \"./option\";\n\n/**\n * Represents a `Some` option, which holds a value.\n * @template T The type of the value held by this `Some` instance.\n */\nexport class Some<T> {\n /**\n * Creates a new `Some` option with the given value.\n * @param value The value to be wrapped in the `Some` option.\n */\n constructor(private value: T) { }\n\n /**\n * Checks if this option is a `Some`.\n * @returns `true` if this option is a `Some`, otherwise `false`.\n */\n isSome(): this is Some<T> {\n return true;\n }\n\n /**\n * Checks if this option is a `None`.\n * @returns `false` because this is a `Some`.\n */\n isNone(): this is None {\n return false;\n }\n\n /**\n * Unwraps the value held by this `Some` option.\n * @returns The value held by this `Some` option.\n */\n unwrap(): T {\n return this.value;\n }\n\n /**\n * Applies a transformation function to the value held by this `Some` option and returns a new `Option` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Some` option containing the transformed value.\n */\n map<U>(fn: (value: T) => U): Option<U> {\n return new Some(fn(this.value));\n }\n\n /**\n * Applies a transformation function that returns an `Option` to the value held by this `Some` option.\n * @template U The type of the value in the resulting `Option`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U>(fn: (value: T) => Option<U>): Option<U> {\n return fn(this.value);\n }\n\n /**\n * Returns the value held by this `Some` option, ignoring the default value provided.\n * @param _ A default value (ignored in this implementation).\n * @returns The value held by this `Some` option.\n */\n unwrapOr(_: T): T {\n return this.value;\n }\n}\n","import type { Some } from \"./some\";\nimport type { Option } from \"./option\";\n\n/**\n * Represents a `None` option, which holds no value.\n */\nexport class None {\n /**\n * Checks if this option is a `Some`.\n * @returns `false` because this is a `None`.\n */\n isSome(): this is Some<never> {\n return false;\n }\n\n /**\n * Checks if this option is a `None`.\n * @returns `true` because this is a `None`.\n */\n isNone(): this is None {\n return true;\n }\n\n /**\n * Attempts to unwrap the value from this `None` option.\n * @throws An error because `None` has no value.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on a None value\");\n }\n\n /**\n * Applies a transformation function to the value (which does not exist) of this `None` option.\n * @template U The type of the value that would have been returned.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns A new `None` option.\n */\n map<U>(_fn: (value: never) => U): Option<U> {\n return new None();\n }\n\n /**\n * Applies a transformation function that returns an `Option` to the value (which does not exist) of this `None` option.\n * @template U The type of the value in the resulting `Option`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns A new `None` option.\n */\n flatMap<U>(_fn: (value: never) => Option<U>): Option<U> {\n return new None();\n }\n\n /**\n * Returns the default value provided, since `None` has no value.\n * @template T The type of the default value.\n * @param defaultValue The value to return.\n * @returns The default value provided.\n */\n unwrapOr<T>(defaultValue: T): T {\n return defaultValue;\n }\n}\n","import {\n\tSome as SomeType,\n\tNone as NoneType,\n\ttype Option,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Some` instance, representing an `Option` with a value.\n * @template T The type of the value contained in the `Some`.\n * @param value The value to wrap in the `Some` instance.\n * @returns A `Some` instance containing the given value.\n * @example\n * const option = Some(42);\n * console.log(option.isSome()); // true\n * console.log(option.unwrap()); // 42\n */\nfunction Some<T>(value: T): SomeType<T> {\n\treturn new SomeType(value);\n}\n\n/**\n * Creates a new `None` instance, representing an `Option` with no value.\n * @returns A `None` instance.\n * @example\n * const option = None();\n * console.log(option.isNone()); // true\n * console.log(option.unwrap()); // throws Error: \"Called unwrap on a None value\"\n */\nfunction None(): NoneType {\n\treturn new NoneType();\n}\n\n(global as any).Some = Some;\n(global as any).None = None;\n\nexport { None, Some, Option };\n","import type { Ok } from \"./ok\";\nimport type { ResultDefinition } from \"./result\";\n\n/**\n * Represents a failed result (`Err`) that contains an error value.\n * @template E The type of the error contained in this `Err`.\n */\nexport class Err<E extends Error>\n extends Error\n implements ResultDefinition<never, E>\n{\n private error: E;\n /**\n * Creates a new `Err` instance with the given error value.\n * @param error The error to wrap in the `Err` instance.\n */\n constructor(error: E | string) {\n super(typeof error === \"string\" ? error : error.message);\n this.error =\n typeof error === \"string\" ? (new Error(error) as E) : (error as E);\n Object.setPrototypeOf(this, Err.prototype);\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, Err);\n }\n }\n\n /**\n * Checks if this result is an `Ok`.\n * @returns `false` because this is an `Err`.\n */\n isOk(): this is Ok<never> {\n return false;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `true` because this is an `Err`.\n */\n isErr(): this is Err<E extends Error ? E : Error> {\n return true;\n }\n\n /**\n * Retrieves the value contained in this result. Since this is an `Err`, an error is thrown.\n * @throws An error because `unwrap` is called on an `Err`.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on an Err value\");\n }\n\n /**\n * Maps the value (if any). Since this is an `Err`, the mapping function is ignored, and the original `Err` is returned.\n * @template U The type of the value (ignored for `Err`).\n * @param _fn The mapping function for values (not used).\n * @returns The original `Err` instance.\n */\n map<U>(_fn: (value: never) => U): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Maps the error value using a transformation function and returns a new `Result` with the transformed error.\n * @template U The type of the transformed error.\n * @param fn The transformation function to apply to the error value.\n * @returns A new `Err` containing the transformed error.\n */\n mapErr<U extends Error>(fn: (err: E) => U): ResultDefinition<never, U> {\n return new Err<U>(fn(this.error)) as unknown as ResultDefinition<never, U>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value (which does not exist) of this `Err`.\n * @template U The type of the value in the resulting `Result`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns The original `Err` instance.\n */\n flatMap<U>(\n _fn: (value: never) => ResultDefinition<U, never>,\n ): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Retrieves the error value contained in this `Err`.\n * @returns The error value contained in this `Err`.\n */\n unwrapErr(): E {\n return this.error;\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return None();\n }\n}\n","import type { ResultDefinition } from \"./result\";\nimport type { Err } from \"./err\";\n\n/**\n * Represents a successful result (`Ok`) that contains a value.\n * @template T The type of the value contained in this `Ok`.\n */\nexport class Ok<T> implements ResultDefinition<T, never> {\n /**\n * Creates a new `Ok` instance with the given value.\n * @param value The value to wrap in the `Ok` instance.\n */\n constructor(private value: T) {}\n /**\n * Checks if this result is an `Ok`.\n * @returns `true` because this is an `Ok`.\n */\n isOk(): this is Ok<T> {\n return true;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `false` because this is an `Ok`.\n */\n isErr(): this is Err<never> {\n return false;\n }\n\n /**\n * Retrieves the value contained in this `Ok`.\n * @returns The value contained in this `Ok`.\n */\n unwrap(): T {\n return this.value;\n }\n\n /**\n * Applies a transformation function to the value contained in this `Ok` and returns a new `Result` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Ok` containing the transformed value.\n */\n map<U>(fn: (value: T) => U): ResultDefinition<U, never> {\n return new Ok(fn(this.value)) as ResultDefinition<U, never>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value contained in this `Ok`.\n * @template U The type of the value in the resulting `Result`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U>(\n fn: (value: T) => ResultDefinition<U, never>,\n ): ResultDefinition<U, never> {\n return fn(this.value);\n }\n\n /**\n * Maps the error value (if any). Since this is an `Ok`, the error mapping function is ignored, and the original `Ok` is returned.\n * @template U The type of the error (ignored for `Ok`).\n * @param _fn The mapping function for errors (not used).\n * @returns The original `Ok` instance.\n */\n // mapErr<U extends Error | string>(fn: (err: U) => U): Result<T, never> {\n // \treturn this;\n mapErr<U extends Error>(_fn: (err: never) => U): ResultDefinition<T, U> {\n return this as unknown as ResultDefinition<T, U>;\n }\n\n /**\n * Retrieves the error contained in this result. Since this is an `Ok`, an error is thrown.\n * @throws An error because `unwrapErr` is called on an `Ok`.\n */\n unwrapErr(): never {\n throw new Error(\"Called unwrapErr on an Ok value\");\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return match(this, {\n Ok: (v) => Some(v),\n Err: (_) => None(),\n });\n }\n}\n","import {\n Err as ErrType,\n Ok as OkType,\n type Result,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Ok` instance, representing a successful result.\n * @template T The type of the value contained in the `Ok`.\n * @param value The value to wrap in the `Ok` instance.\n * @returns An `Ok` instance containing the given value.\n * @example\n * const result = Ok(42);\n * console.log(result.isOk()); // true\n * console.log(result.unwrap()); // 42\n */\nfunction Ok<T>(value: T): OkType<T> {\n return new OkType(value);\n}\n\n/**\n * Creates a new `Err` instance, representing a failed result.\n * @template E The type of the error contained in the `Err`.\n * @param error The error to wrap in the `Err` instance.\n * @returns An `Err` instance containing the given error.\n * @example\n * const result = Err(\"Something went wrong\");\n * console.log(result.isErr()); // true\n * console.log(result.unwrapErr()); // \"Something went wrong\"\n */\nfunction Err<E extends Error>(error: E | string): ErrType<E> {\n return new ErrType(error);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Ok = Ok;\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Err = Err;\n\nexport { Err, Ok, Result, ErrType, OkType };\n"]}
|
package/dist/index.js
CHANGED
|
@@ -307,6 +307,6 @@ function Err2(error) {
|
|
|
307
307
|
global.Ok = Ok2;
|
|
308
308
|
global.Err = Err2;
|
|
309
309
|
|
|
310
|
-
export { None3 as None, Some3 as Some, match2 as match };
|
|
310
|
+
export { Err2 as Err, None3 as None, Ok2 as Ok, Some3 as Some, match2 as match };
|
|
311
311
|
//# sourceMappingURL=index.js.map
|
|
312
312
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/helpers/match.ts","../src/option/__internal__/return-types/some.ts","../src/option/__internal__/return-types/none.ts","../src/option/option.ts","../src/result/__internal__/return-types/err.ts","../src/result/__internal__/return-types/ok.ts","../src/result/result.ts"],"names":["match","Some","None","Ok","Err"],"mappings":";AAiBO,SAASA,MAAAA,CACd,SACA,KAMG,EAAA;AACH,EAAA,IAAI,MAAU,IAAA,OAAA,IAAW,OAAQ,CAAA,IAAA,EAAQ,EAAA;AACvC,IAAA,IAAI,CAAC,KAAM,CAAA,EAAA,EAAU,MAAA,IAAI,MAAM,qBAAqB,CAAA;AACpD,IAAA,OAAO,KAAM,CAAA,EAAA,CAAG,OAAQ,CAAA,MAAA,EAAQ,CAAA;AAAA;AAGlC,EAAA,IAAI,OAAW,IAAA,OAAA,IAAW,OAAQ,CAAA,KAAA,EAAS,EAAA;AACzC,IAAA,IAAI,CAAC,KAAM,CAAA,GAAA,EAAW,MAAA,IAAI,MAAM,sBAAsB,CAAA;AACtD,IAAA,OAAO,KAAM,CAAA,GAAA,CAAI,OAAQ,CAAA,SAAA,EAAgB,CAAA;AAAA;AAG3C,EAAA,IAAI,QAAY,IAAA,OAAA,IAAW,OAAQ,CAAA,MAAA,EAAU,EAAA;AAC3C,IAAA,IAAI,CAAC,KAAM,CAAA,IAAA,EAAY,MAAA,IAAI,MAAM,uBAAuB,CAAA;AACxD,IAAA,OAAO,KAAM,CAAA,IAAA,CAAK,OAAQ,CAAA,MAAA,EAAQ,CAAA;AAAA;AAGpC,EAAA,IAAI,QAAY,IAAA,OAAA,IAAW,OAAQ,CAAA,MAAA,EAAU,EAAA;AAC3C,IAAA,IAAI,CAAC,KAAM,CAAA,IAAA,EA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AAA,EAQA,QACE,EAC4B,EAAA;AAC5B,IAAO,OAAA,EAAA,CAAG,KAAK,KAAK,CAAA;AAAA;AACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAwB,GAAgD,EAAA;AACtE,IAAO,OAAA,IAAA;AAAA;AACT;AAAA;AAAA;AAAA;AAAA,EAMA,SAAmB,GAAA;AACjB,IAAM,MAAA,IAAI,MAAM,iCAAiC,CAAA;AAAA;AACnD;AAAA;AAAA;AAAA;AAAA,EAMA,EAAK,GAAA;AACH,IAAA,OAAO,MAAM,IAAM,EAAA;AAAA,MACjB,EAAI,EAAA,CAAC,CAAM,KAAA,IAAA,CAAK,CAAC,CAAA;AAAA,MACjB,GAAA,EAAK,CAAC,CAAA,KAAM,IAAK;AAAA,KAClB,CAAA;AAAA;AAEL,CAAA;;;ACzEA,SAASC,IAAM,KAAqB,EAAA;AAClC,EAAO,OAAA,IAAI,GAAO,KAAK,CAAA;AACzB;AAYA,SAASC,KAAqB,KAA+B,EAAA;AAC3D,EAAO,OAAA,IAAI,IAAQ,KAAK,CAAA;AAC1B;AAGC,MAAA,CAAe,EAAKD,GAAAA,GAAAA;AAEpB,MAAA,CAAe,GAAMC,GAAAA,IAAAA","file":"index.js","sourcesContent":["import type { Option } from \"../option\";\nimport type { Result } from \"../result\";\n\nexport function match<T, E extends Error, R>(\n matcher: Result<T, E>,\n cases: {\n Ok: (value: T) => R;\n Err: (error: E) => R;\n },\n): R;\nexport function match<T, R>(\n matcher: Option<T>,\n cases: {\n Some: (value: T) => R;\n None: () => R;\n },\n): R;\nexport function match<T, E extends Error, R>(\n matcher: Result<T, E> | Option<T>,\n cases: {\n Ok?: (value: T) => R;\n Err?: (error: E) => R;\n Some?: (value: T) => R;\n None?: () => R;\n },\n): R {\n if (\"isOk\" in matcher && matcher.isOk()) {\n if (!cases.Ok) throw new Error(\"Missing case for Ok\");\n return cases.Ok(matcher.unwrap());\n }\n\n if (\"isErr\" in matcher && matcher.isErr()) {\n if (!cases.Err) throw new Error(\"Missing case for Err\");\n return cases.Err(matcher.unwrapErr() as E);\n }\n\n if (\"isSome\" in matcher && matcher.isSome()) {\n if (!cases.Some) throw new Error(\"Missing case for Some\");\n return cases.Some(matcher.unwrap());\n }\n\n if (\"isNone\" in matcher && matcher.isNone()) {\n if (!cases.None) throw new Error(\"Missing case for None\");\n return cases.None();\n }\n\n throw new Error(\"Invalid matcher or missing case\");\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).match = match;\n","import type { None } from \"./none\";\nimport type { Option } from \"./option\";\n\n/**\n * Represents a `Some` option, which holds a value.\n * @template T The type of the value held by this `Some` instance.\n */\nexport class Some<T> {\n /**\n * Creates a new `Some` option with the given value.\n * @param value The value to be wrapped in the `Some` option.\n */\n constructor(private value: T) { }\n\n /**\n * Checks if this option is a `Some`.\n * @returns `true` if this option is a `Some`, otherwise `false`.\n */\n isSome(): this is Some<T> {\n return true;\n }\n\n /**\n * Checks if this option is a `None`.\n * @returns `false` because this is a `Some`.\n */\n isNone(): this is None {\n return false;\n }\n\n /**\n * Unwraps the value held by this `Some` option.\n * @returns The value held by this `Some` option.\n */\n unwrap(): T {\n return this.value;\n }\n\n /**\n * Applies a transformation function to the value held by this `Some` option and returns a new `Option` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Some` option containing the transformed value.\n */\n map<U>(fn: (value: T) => U): Option<U> {\n return new Some(fn(this.value));\n }\n\n /**\n * Applies a transformation function that returns an `Option` to the value held by this `Some` option.\n * @template U The type of the value in the resulting `Option`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U>(fn: (value: T) => Option<U>): Option<U> {\n return fn(this.value);\n }\n\n /**\n * Returns the value held by this `Some` option, ignoring the default value provided.\n * @param _ A default value (ignored in this implementation).\n * @returns The value held by this `Some` option.\n */\n unwrapOr(_: T): T {\n return this.value;\n }\n}\n","import type { Some } from \"./some\";\nimport type { Option } from \"./option\";\n\n/**\n * Represents a `None` option, which holds no value.\n */\nexport class None {\n /**\n * Checks if this option is a `Some`.\n * @returns `false` because this is a `None`.\n */\n isSome(): this is Some<never> {\n return false;\n }\n\n /**\n * Checks if this option is a `None`.\n * @returns `true` because this is a `None`.\n */\n isNone(): this is None {\n return true;\n }\n\n /**\n * Attempts to unwrap the value from this `None` option.\n * @throws An error because `None` has no value.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on a None value\");\n }\n\n /**\n * Applies a transformation function to the value (which does not exist) of this `None` option.\n * @template U The type of the value that would have been returned.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns A new `None` option.\n */\n map<U>(_fn: (value: never) => U): Option<U> {\n return new None();\n }\n\n /**\n * Applies a transformation function that returns an `Option` to the value (which does not exist) of this `None` option.\n * @template U The type of the value in the resulting `Option`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns A new `None` option.\n */\n flatMap<U>(_fn: (value: never) => Option<U>): Option<U> {\n return new None();\n }\n\n /**\n * Returns the default value provided, since `None` has no value.\n * @template T The type of the default value.\n * @param defaultValue The value to return.\n * @returns The default value provided.\n */\n unwrapOr<T>(defaultValue: T): T {\n return defaultValue;\n }\n}\n","import {\n\tSome as SomeType,\n\tNone as NoneType,\n\ttype Option,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Some` instance, representing an `Option` with a value.\n * @template T The type of the value contained in the `Some`.\n * @param value The value to wrap in the `Some` instance.\n * @returns A `Some` instance containing the given value.\n * @example\n * const option = Some(42);\n * console.log(option.isSome()); // true\n * console.log(option.unwrap()); // 42\n */\nfunction Some<T>(value: T): SomeType<T> {\n\treturn new SomeType(value);\n}\n\n/**\n * Creates a new `None` instance, representing an `Option` with no value.\n * @returns A `None` instance.\n * @example\n * const option = None();\n * console.log(option.isNone()); // true\n * console.log(option.unwrap()); // throws Error: \"Called unwrap on a None value\"\n */\nfunction None(): NoneType {\n\treturn new NoneType();\n}\n\n(global as any).Some = Some;\n(global as any).None = None;\n\nexport { None, Some, Option };\n","import type { Ok } from \"./ok\";\nimport type { ResultDefinition } from \"./result\";\n\n/**\n * Represents a failed result (`Err`) that contains an error value.\n * @template E The type of the error contained in this `Err`.\n */\nexport class Err<E extends Error>\n extends Error\n implements ResultDefinition<never, E>\n{\n private error: E;\n /**\n * Creates a new `Err` instance with the given error value.\n * @param error The error to wrap in the `Err` instance.\n */\n constructor(error: E | string) {\n super(typeof error === \"string\" ? error : error.message);\n this.error =\n typeof error === \"string\" ? (new Error(error) as E) : (error as E);\n Object.setPrototypeOf(this, Err.prototype);\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, Err);\n }\n }\n\n /**\n * Checks if this result is an `Ok`.\n * @returns `false` because this is an `Err`.\n */\n isOk(): this is Ok<never> {\n return false;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `true` because this is an `Err`.\n */\n isErr(): this is Err<E extends Error ? E : Error> {\n return true;\n }\n\n /**\n * Retrieves the value contained in this result. Since this is an `Err`, an error is thrown.\n * @throws An error because `unwrap` is called on an `Err`.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on an Err value\");\n }\n\n /**\n * Maps the value (if any). Since this is an `Err`, the mapping function is ignored, and the original `Err` is returned.\n * @template U The type of the value (ignored for `Err`).\n * @param _fn The mapping function for values (not used).\n * @returns The original `Err` instance.\n */\n map<U>(_fn: (value: never) => U): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Maps the error value using a transformation function and returns a new `Result` with the transformed error.\n * @template U The type of the transformed error.\n * @param fn The transformation function to apply to the error value.\n * @returns A new `Err` containing the transformed error.\n */\n mapErr<U extends Error>(fn: (err: E) => U): ResultDefinition<never, U> {\n return new Err<U>(fn(this.error)) as unknown as ResultDefinition<never, U>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value (which does not exist) of this `Err`.\n * @template U The type of the value in the resulting `Result`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns The original `Err` instance.\n */\n flatMap<U>(\n _fn: (value: never) => ResultDefinition<U, never>,\n ): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Retrieves the error value contained in this `Err`.\n * @returns The error value contained in this `Err`.\n */\n unwrapErr(): E {\n return this.error;\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return None();\n }\n}\n","import type { ResultDefinition } from \"./result\";\nimport type { Err } from \"./err\";\n\n/**\n * Represents a successful result (`Ok`) that contains a value.\n * @template T The type of the value contained in this `Ok`.\n */\nexport class Ok<T> implements ResultDefinition<T, never> {\n /**\n * Creates a new `Ok` instance with the given value.\n * @param value The value to wrap in the `Ok` instance.\n */\n constructor(private value: T) {}\n /**\n * Checks if this result is an `Ok`.\n * @returns `true` because this is an `Ok`.\n */\n isOk(): this is Ok<T> {\n return true;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `false` because this is an `Ok`.\n */\n isErr(): this is Err<never> {\n return false;\n }\n\n /**\n * Retrieves the value contained in this `Ok`.\n * @returns The value contained in this `Ok`.\n */\n unwrap(): T {\n return this.value;\n }\n\n /**\n * Applies a transformation function to the value contained in this `Ok` and returns a new `Result` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Ok` containing the transformed value.\n */\n map<U>(fn: (value: T) => U): ResultDefinition<U, never> {\n return new Ok(fn(this.value)) as ResultDefinition<U, never>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value contained in this `Ok`.\n * @template U The type of the value in the resulting `Result`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U>(\n fn: (value: T) => ResultDefinition<U, never>,\n ): ResultDefinition<U, never> {\n return fn(this.value);\n }\n\n /**\n * Maps the error value (if any). Since this is an `Ok`, the error mapping function is ignored, and the original `Ok` is returned.\n * @template U The type of the error (ignored for `Ok`).\n * @param _fn The mapping function for errors (not used).\n * @returns The original `Ok` instance.\n */\n // mapErr<U extends Error | string>(fn: (err: U) => U): Result<T, never> {\n // \treturn this;\n mapErr<U extends Error>(_fn: (err: never) => U): ResultDefinition<T, U> {\n return this as unknown as ResultDefinition<T, U>;\n }\n\n /**\n * Retrieves the error contained in this result. Since this is an `Ok`, an error is thrown.\n * @throws An error because `unwrapErr` is called on an `Ok`.\n */\n unwrapErr(): never {\n throw new Error(\"Called unwrapErr on an Ok value\");\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return match(this, {\n Ok: (v) => Some(v),\n Err: (_) => None(),\n });\n }\n}\n","import {\n Err as ErrType,\n Ok as OkType,\n type Result,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Ok` instance, representing a successful result.\n * @template T The type of the value contained in the `Ok`.\n * @param value The value to wrap in the `Ok` instance.\n * @returns An `Ok` instance containing the given value.\n * @example\n * const result = Ok(42);\n * console.log(result.isOk()); // true\n * console.log(result.unwrap()); // 42\n */\nfunction Ok<T>(value: T): OkType<T> {\n return new OkType(value);\n}\n\n/**\n * Creates a new `Err` instance, representing a failed result.\n * @template E The type of the error contained in the `Err`.\n * @param error The error to wrap in the `Err` instance.\n * @returns An `Err` instance containing the given error.\n * @example\n * const result = Err(\"Something went wrong\");\n * console.log(result.isErr()); // true\n * console.log(result.unwrapErr()); // \"Something went wrong\"\n */\nfunction Err<E extends Error>(error: E | string): ErrType<E> {\n return new ErrType(error);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Ok = Ok;\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Err = Err;\n\nexport type { Err, Ok, Result, ErrType, OkType };\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/helpers/match.ts","../src/option/__internal__/return-types/some.ts","../src/option/__internal__/return-types/none.ts","../src/option/option.ts","../src/result/__internal__/return-types/err.ts","../src/result/__internal__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AAAA;AAAA;AAAA,EAMA,EAAK,GAAA;AACH,IAAA,OAAO,MAAM,IAAM,EAAA;AAAA,MACjB,EAAI,EAAA,CAAC,CAAM,KAAA,IAAA,CAAK,CAAC,CAAA;AAAA,MACjB,GAAA,EAAK,CAAC,CAAA,KAAM,IAAK;AAAA,KAClB,CAAA;AAAA;AAEL,CAAA;;;ACzEA,SAASC,IAAM,KAAqB,EAAA;AAClC,EAAO,OAAA,IAAI,GAAO,KAAK,CAAA;AACzB;AAYA,SAASC,KAAqB,KAA+B,EAAA;AAC3D,EAAO,OAAA,IAAI,IAAQ,KAAK,CAAA;AAC1B;AAGC,MAAA,CAAe,EAAKD,GAAAA,GAAAA;AAEpB,MAAA,CAAe,GAAMC,GAAAA,IAAAA","file":"index.js","sourcesContent":["import type { Option } from \"../option\";\nimport type { Result } from \"../result\";\n\nexport function match<T, E extends Error, R>(\n matcher: Result<T, E>,\n cases: {\n Ok: (value: T) => R;\n Err: (error: E) => R;\n },\n): R;\nexport function match<T, R>(\n matcher: Option<T>,\n cases: {\n Some: (value: T) => R;\n None: () => R;\n },\n): R;\nexport function match<T, E extends Error, R>(\n matcher: Result<T, E> | Option<T>,\n cases: {\n Ok?: (value: T) => R;\n Err?: (error: E) => R;\n Some?: (value: T) => R;\n None?: () => R;\n },\n): R {\n if (\"isOk\" in matcher && matcher.isOk()) {\n if (!cases.Ok) throw new Error(\"Missing case for Ok\");\n return cases.Ok(matcher.unwrap());\n }\n\n if (\"isErr\" in matcher && matcher.isErr()) {\n if (!cases.Err) throw new Error(\"Missing case for Err\");\n return cases.Err(matcher.unwrapErr() as E);\n }\n\n if (\"isSome\" in matcher && matcher.isSome()) {\n if (!cases.Some) throw new Error(\"Missing case for Some\");\n return cases.Some(matcher.unwrap());\n }\n\n if (\"isNone\" in matcher && matcher.isNone()) {\n if (!cases.None) throw new Error(\"Missing case for None\");\n return cases.None();\n }\n\n throw new Error(\"Invalid matcher or missing case\");\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).match = match;\n","import type { None } from \"./none\";\nimport type { Option } from \"./option\";\n\n/**\n * Represents a `Some` option, which holds a value.\n * @template T The type of the value held by this `Some` instance.\n */\nexport class Some<T> {\n /**\n * Creates a new `Some` option with the given value.\n * @param value The value to be wrapped in the `Some` option.\n */\n constructor(private value: T) { }\n\n /**\n * Checks if this option is a `Some`.\n * @returns `true` if this option is a `Some`, otherwise `false`.\n */\n isSome(): this is Some<T> {\n return true;\n }\n\n /**\n * Checks if this option is a `None`.\n * @returns `false` because this is a `Some`.\n */\n isNone(): this is None {\n return false;\n }\n\n /**\n * Unwraps the value held by this `Some` option.\n * @returns The value held by this `Some` option.\n */\n unwrap(): T {\n return this.value;\n }\n\n /**\n * Applies a transformation function to the value held by this `Some` option and returns a new `Option` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Some` option containing the transformed value.\n */\n map<U>(fn: (value: T) => U): Option<U> {\n return new Some(fn(this.value));\n }\n\n /**\n * Applies a transformation function that returns an `Option` to the value held by this `Some` option.\n * @template U The type of the value in the resulting `Option`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U>(fn: (value: T) => Option<U>): Option<U> {\n return fn(this.value);\n }\n\n /**\n * Returns the value held by this `Some` option, ignoring the default value provided.\n * @param _ A default value (ignored in this implementation).\n * @returns The value held by this `Some` option.\n */\n unwrapOr(_: T): T {\n return this.value;\n }\n}\n","import type { Some } from \"./some\";\nimport type { Option } from \"./option\";\n\n/**\n * Represents a `None` option, which holds no value.\n */\nexport class None {\n /**\n * Checks if this option is a `Some`.\n * @returns `false` because this is a `None`.\n */\n isSome(): this is Some<never> {\n return false;\n }\n\n /**\n * Checks if this option is a `None`.\n * @returns `true` because this is a `None`.\n */\n isNone(): this is None {\n return true;\n }\n\n /**\n * Attempts to unwrap the value from this `None` option.\n * @throws An error because `None` has no value.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on a None value\");\n }\n\n /**\n * Applies a transformation function to the value (which does not exist) of this `None` option.\n * @template U The type of the value that would have been returned.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns A new `None` option.\n */\n map<U>(_fn: (value: never) => U): Option<U> {\n return new None();\n }\n\n /**\n * Applies a transformation function that returns an `Option` to the value (which does not exist) of this `None` option.\n * @template U The type of the value in the resulting `Option`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns A new `None` option.\n */\n flatMap<U>(_fn: (value: never) => Option<U>): Option<U> {\n return new None();\n }\n\n /**\n * Returns the default value provided, since `None` has no value.\n * @template T The type of the default value.\n * @param defaultValue The value to return.\n * @returns The default value provided.\n */\n unwrapOr<T>(defaultValue: T): T {\n return defaultValue;\n }\n}\n","import {\n\tSome as SomeType,\n\tNone as NoneType,\n\ttype Option,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Some` instance, representing an `Option` with a value.\n * @template T The type of the value contained in the `Some`.\n * @param value The value to wrap in the `Some` instance.\n * @returns A `Some` instance containing the given value.\n * @example\n * const option = Some(42);\n * console.log(option.isSome()); // true\n * console.log(option.unwrap()); // 42\n */\nfunction Some<T>(value: T): SomeType<T> {\n\treturn new SomeType(value);\n}\n\n/**\n * Creates a new `None` instance, representing an `Option` with no value.\n * @returns A `None` instance.\n * @example\n * const option = None();\n * console.log(option.isNone()); // true\n * console.log(option.unwrap()); // throws Error: \"Called unwrap on a None value\"\n */\nfunction None(): NoneType {\n\treturn new NoneType();\n}\n\n(global as any).Some = Some;\n(global as any).None = None;\n\nexport { None, Some, Option };\n","import type { Ok } from \"./ok\";\nimport type { ResultDefinition } from \"./result\";\n\n/**\n * Represents a failed result (`Err`) that contains an error value.\n * @template E The type of the error contained in this `Err`.\n */\nexport class Err<E extends Error>\n extends Error\n implements ResultDefinition<never, E>\n{\n private error: E;\n /**\n * Creates a new `Err` instance with the given error value.\n * @param error The error to wrap in the `Err` instance.\n */\n constructor(error: E | string) {\n super(typeof error === \"string\" ? error : error.message);\n this.error =\n typeof error === \"string\" ? (new Error(error) as E) : (error as E);\n Object.setPrototypeOf(this, Err.prototype);\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, Err);\n }\n }\n\n /**\n * Checks if this result is an `Ok`.\n * @returns `false` because this is an `Err`.\n */\n isOk(): this is Ok<never> {\n return false;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `true` because this is an `Err`.\n */\n isErr(): this is Err<E extends Error ? E : Error> {\n return true;\n }\n\n /**\n * Retrieves the value contained in this result. Since this is an `Err`, an error is thrown.\n * @throws An error because `unwrap` is called on an `Err`.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on an Err value\");\n }\n\n /**\n * Maps the value (if any). Since this is an `Err`, the mapping function is ignored, and the original `Err` is returned.\n * @template U The type of the value (ignored for `Err`).\n * @param _fn The mapping function for values (not used).\n * @returns The original `Err` instance.\n */\n map<U>(_fn: (value: never) => U): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Maps the error value using a transformation function and returns a new `Result` with the transformed error.\n * @template U The type of the transformed error.\n * @param fn The transformation function to apply to the error value.\n * @returns A new `Err` containing the transformed error.\n */\n mapErr<U extends Error>(fn: (err: E) => U): ResultDefinition<never, U> {\n return new Err<U>(fn(this.error)) as unknown as ResultDefinition<never, U>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value (which does not exist) of this `Err`.\n * @template U The type of the value in the resulting `Result`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns The original `Err` instance.\n */\n flatMap<U>(\n _fn: (value: never) => ResultDefinition<U, never>,\n ): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Retrieves the error value contained in this `Err`.\n * @returns The error value contained in this `Err`.\n */\n unwrapErr(): E {\n return this.error;\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return None();\n }\n}\n","import type { ResultDefinition } from \"./result\";\nimport type { Err } from \"./err\";\n\n/**\n * Represents a successful result (`Ok`) that contains a value.\n * @template T The type of the value contained in this `Ok`.\n */\nexport class Ok<T> implements ResultDefinition<T, never> {\n /**\n * Creates a new `Ok` instance with the given value.\n * @param value The value to wrap in the `Ok` instance.\n */\n constructor(private value: T) {}\n /**\n * Checks if this result is an `Ok`.\n * @returns `true` because this is an `Ok`.\n */\n isOk(): this is Ok<T> {\n return true;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `false` because this is an `Ok`.\n */\n isErr(): this is Err<never> {\n return false;\n }\n\n /**\n * Retrieves the value contained in this `Ok`.\n * @returns The value contained in this `Ok`.\n */\n unwrap(): T {\n return this.value;\n }\n\n /**\n * Applies a transformation function to the value contained in this `Ok` and returns a new `Result` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Ok` containing the transformed value.\n */\n map<U>(fn: (value: T) => U): ResultDefinition<U, never> {\n return new Ok(fn(this.value)) as ResultDefinition<U, never>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value contained in this `Ok`.\n * @template U The type of the value in the resulting `Result`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U>(\n fn: (value: T) => ResultDefinition<U, never>,\n ): ResultDefinition<U, never> {\n return fn(this.value);\n }\n\n /**\n * Maps the error value (if any). Since this is an `Ok`, the error mapping function is ignored, and the original `Ok` is returned.\n * @template U The type of the error (ignored for `Ok`).\n * @param _fn The mapping function for errors (not used).\n * @returns The original `Ok` instance.\n */\n // mapErr<U extends Error | string>(fn: (err: U) => U): Result<T, never> {\n // \treturn this;\n mapErr<U extends Error>(_fn: (err: never) => U): ResultDefinition<T, U> {\n return this as unknown as ResultDefinition<T, U>;\n }\n\n /**\n * Retrieves the error contained in this result. Since this is an `Ok`, an error is thrown.\n * @throws An error because `unwrapErr` is called on an `Ok`.\n */\n unwrapErr(): never {\n throw new Error(\"Called unwrapErr on an Ok value\");\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return match(this, {\n Ok: (v) => Some(v),\n Err: (_) => None(),\n });\n }\n}\n","import {\n Err as ErrType,\n Ok as OkType,\n type Result,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Ok` instance, representing a successful result.\n * @template T The type of the value contained in the `Ok`.\n * @param value The value to wrap in the `Ok` instance.\n * @returns An `Ok` instance containing the given value.\n * @example\n * const result = Ok(42);\n * console.log(result.isOk()); // true\n * console.log(result.unwrap()); // 42\n */\nfunction Ok<T>(value: T): OkType<T> {\n return new OkType(value);\n}\n\n/**\n * Creates a new `Err` instance, representing a failed result.\n * @template E The type of the error contained in the `Err`.\n * @param error The error to wrap in the `Err` instance.\n * @returns An `Err` instance containing the given error.\n * @example\n * const result = Err(\"Something went wrong\");\n * console.log(result.isErr()); // true\n * console.log(result.unwrapErr()); // \"Something went wrong\"\n */\nfunction Err<E extends Error>(error: E | string): ErrType<E> {\n return new ErrType(error);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Ok = Ok;\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Err = Err;\n\nexport { Err, Ok, Result, ErrType, OkType };\n"]}
|
package/dist/result/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/result/__internal__/return-types/err.ts","../../src/result/__internal__/return-types/ok.ts","../../src/result/result.ts"],"names":["Ok","Err"],"mappings":";;;AAOO,IAAM,GAAA,GAAN,MAAM,IAAA,SACH,KAEV,CAAA;AAAA,EACU,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKR,YAAY,KAAmB,EAAA;AAC7B,IAAA,KAAA,CAAM,OAAO,KAAA,KAAU,QAAW,GAAA,KAAA,GAAQ,MAAM,OAAO,CAAA;AACvD,IAAA,IAAA,CAAK,QACH,OAAO,KAAA,KAAU,WAAY,IAAI,KAAA,CAA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AA;AAAA;AAAA;AAAA,EAMA,KAA4B,GAAA;AAC1B,IAAO,OAAA,KAAA;AAAA;AACT;AAAA;AAAA;AAAA;AAAA,EAMA,MAAY,GAAA;AACV,IAAA,OAAO,IAAK,CAAA,KAAA;AAAA;AACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IAAO,EAAiD,EAAA;AACtD,IAAA,OAAO,IAAI,GAAA,CAAG,EAAG,CAAA,IAAA,CAAK,KAAK,CAAC,CAAA;AAAA;AAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,QACE,EAC4B,EAAA;AAC5B,IAAO,OAAA,EAAA,CAAG,KAAK,KAAK,CAAA;AAAA;AACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAwB,GAAgD,EAAA;AACtE,IAAO,OAAA,IAAA;AAAA;AACT;AAAA;AAAA;AAAA;AAAA,EAMA,SAAmB,GAAA;AACjB,IAAM,MAAA,IAAI,MAAM,iCAAiC,CAAA;AAAA;AACnD;AAAA;AAAA;AAAA;AAAA,EAMA,EAAK,GAAA;AACH,IAAA,OAAO,MAAM,IAAM,EAAA;AAAA,MACjB,EAAI,EAAA,CAAC,CAAM,KAAA,IAAA,CAAK,CAAC,CAAA;AAAA,MACjB,GAAA,EAAK,CAAC,CAAA,KAAM,IAAK;AAAA,KAClB,CAAA;AAAA;AAEL,CAAA;;;ACzEA,SAASA,IAAM,KAAqB,EAAA;AAClC,EAAO,OAAA,IAAI,GAAO,KAAK,CAAA;AACzB;AAYA,SAASC,KAAqB,KAA+B,EAAA;AAC3D,EAAO,OAAA,IAAI,IAAQ,KAAK,CAAA;AAC1B;AAGC,MAAA,CAAe,EAAKD,GAAAA,GAAAA;AAEpB,MAAA,CAAe,GAAMC,GAAAA,IAAAA","file":"index.cjs","sourcesContent":["import type { Ok } from \"./ok\";\nimport type { ResultDefinition } from \"./result\";\n\n/**\n * Represents a failed result (`Err`) that contains an error value.\n * @template E The type of the error contained in this `Err`.\n */\nexport class Err<E extends Error>\n extends Error\n implements ResultDefinition<never, E>\n{\n private error: E;\n /**\n * Creates a new `Err` instance with the given error value.\n * @param error The error to wrap in the `Err` instance.\n */\n constructor(error: E | string) {\n super(typeof error === \"string\" ? error : error.message);\n this.error =\n typeof error === \"string\" ? (new Error(error) as E) : (error as E);\n Object.setPrototypeOf(this, Err.prototype);\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, Err);\n }\n }\n\n /**\n * Checks if this result is an `Ok`.\n * @returns `false` because this is an `Err`.\n */\n isOk(): this is Ok<never> {\n return false;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `true` because this is an `Err`.\n */\n isErr(): this is Err<E extends Error ? E : Error> {\n return true;\n }\n\n /**\n * Retrieves the value contained in this result. Since this is an `Err`, an error is thrown.\n * @throws An error because `unwrap` is called on an `Err`.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on an Err value\");\n }\n\n /**\n * Maps the value (if any). Since this is an `Err`, the mapping function is ignored, and the original `Err` is returned.\n * @template U The type of the value (ignored for `Err`).\n * @param _fn The mapping function for values (not used).\n * @returns The original `Err` instance.\n */\n map<U>(_fn: (value: never) => U): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Maps the error value using a transformation function and returns a new `Result` with the transformed error.\n * @template U The type of the transformed error.\n * @param fn The transformation function to apply to the error value.\n * @returns A new `Err` containing the transformed error.\n */\n mapErr<U extends Error>(fn: (err: E) => U): ResultDefinition<never, U> {\n return new Err<U>(fn(this.error)) as unknown as ResultDefinition<never, U>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value (which does not exist) of this `Err`.\n * @template U The type of the value in the resulting `Result`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns The original `Err` instance.\n */\n flatMap<U>(\n _fn: (value: never) => ResultDefinition<U, never>,\n ): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Retrieves the error value contained in this `Err`.\n * @returns The error value contained in this `Err`.\n */\n unwrapErr(): E {\n return this.error;\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return None();\n }\n}\n","import type { ResultDefinition } from \"./result\";\nimport type { Err } from \"./err\";\n\n/**\n * Represents a successful result (`Ok`) that contains a value.\n * @template T The type of the value contained in this `Ok`.\n */\nexport class Ok<T> implements ResultDefinition<T, never> {\n /**\n * Creates a new `Ok` instance with the given value.\n * @param value The value to wrap in the `Ok` instance.\n */\n constructor(private value: T) {}\n /**\n * Checks if this result is an `Ok`.\n * @returns `true` because this is an `Ok`.\n */\n isOk(): this is Ok<T> {\n return true;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `false` because this is an `Ok`.\n */\n isErr(): this is Err<never> {\n return false;\n }\n\n /**\n * Retrieves the value contained in this `Ok`.\n * @returns The value contained in this `Ok`.\n */\n unwrap(): T {\n return this.value;\n }\n\n /**\n * Applies a transformation function to the value contained in this `Ok` and returns a new `Result` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Ok` containing the transformed value.\n */\n map<U>(fn: (value: T) => U): ResultDefinition<U, never> {\n return new Ok(fn(this.value)) as ResultDefinition<U, never>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value contained in this `Ok`.\n * @template U The type of the value in the resulting `Result`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U>(\n fn: (value: T) => ResultDefinition<U, never>,\n ): ResultDefinition<U, never> {\n return fn(this.value);\n }\n\n /**\n * Maps the error value (if any). Since this is an `Ok`, the error mapping function is ignored, and the original `Ok` is returned.\n * @template U The type of the error (ignored for `Ok`).\n * @param _fn The mapping function for errors (not used).\n * @returns The original `Ok` instance.\n */\n // mapErr<U extends Error | string>(fn: (err: U) => U): Result<T, never> {\n // \treturn this;\n mapErr<U extends Error>(_fn: (err: never) => U): ResultDefinition<T, U> {\n return this as unknown as ResultDefinition<T, U>;\n }\n\n /**\n * Retrieves the error contained in this result. Since this is an `Ok`, an error is thrown.\n * @throws An error because `unwrapErr` is called on an `Ok`.\n */\n unwrapErr(): never {\n throw new Error(\"Called unwrapErr on an Ok value\");\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return match(this, {\n Ok: (v) => Some(v),\n Err: (_) => None(),\n });\n }\n}\n","import {\n Err as ErrType,\n Ok as OkType,\n type Result,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Ok` instance, representing a successful result.\n * @template T The type of the value contained in the `Ok`.\n * @param value The value to wrap in the `Ok` instance.\n * @returns An `Ok` instance containing the given value.\n * @example\n * const result = Ok(42);\n * console.log(result.isOk()); // true\n * console.log(result.unwrap()); // 42\n */\nfunction Ok<T>(value: T): OkType<T> {\n return new OkType(value);\n}\n\n/**\n * Creates a new `Err` instance, representing a failed result.\n * @template E The type of the error contained in the `Err`.\n * @param error The error to wrap in the `Err` instance.\n * @returns An `Err` instance containing the given error.\n * @example\n * const result = Err(\"Something went wrong\");\n * console.log(result.isErr()); // true\n * console.log(result.unwrapErr()); // \"Something went wrong\"\n */\nfunction Err<E extends Error>(error: E | string): ErrType<E> {\n return new ErrType(error);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Ok = Ok;\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Err = Err;\n\nexport
|
|
1
|
+
{"version":3,"sources":["../../src/result/__internal__/return-types/err.ts","../../src/result/__internal__/return-types/ok.ts","../../src/result/result.ts"],"names":["Ok","Err"],"mappings":";;;AAOO,IAAM,GAAA,GAAN,MAAM,IAAA,SACH,KAEV,CAAA;AAAA,EACU,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKR,YAAY,KAAmB,EAAA;AAC7B,IAAA,KAAA,CAAM,OAAO,KAAA,KAAU,QAAW,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"index.cjs","sourcesContent":["import type { Ok } from \"./ok\";\nimport type { ResultDefinition } from \"./result\";\n\n/**\n * Represents a failed result (`Err`) that contains an error value.\n * @template E The type of the error contained in this `Err`.\n */\nexport class Err<E extends Error>\n extends Error\n implements ResultDefinition<never, E>\n{\n private error: E;\n /**\n * Creates a new `Err` instance with the given error value.\n * @param error The error to wrap in the `Err` instance.\n */\n constructor(error: E | string) {\n super(typeof error === \"string\" ? error : error.message);\n this.error =\n typeof error === \"string\" ? (new Error(error) as E) : (error as E);\n Object.setPrototypeOf(this, Err.prototype);\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, Err);\n }\n }\n\n /**\n * Checks if this result is an `Ok`.\n * @returns `false` because this is an `Err`.\n */\n isOk(): this is Ok<never> {\n return false;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `true` because this is an `Err`.\n */\n isErr(): this is Err<E extends Error ? E : Error> {\n return true;\n }\n\n /**\n * Retrieves the value contained in this result. Since this is an `Err`, an error is thrown.\n * @throws An error because `unwrap` is called on an `Err`.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on an Err value\");\n }\n\n /**\n * Maps the value (if any). Since this is an `Err`, the mapping function is ignored, and the original `Err` is returned.\n * @template U The type of the value (ignored for `Err`).\n * @param _fn The mapping function for values (not used).\n * @returns The original `Err` instance.\n */\n map<U>(_fn: (value: never) => U): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Maps the error value using a transformation function and returns a new `Result` with the transformed error.\n * @template U The type of the transformed error.\n * @param fn The transformation function to apply to the error value.\n * @returns A new `Err` containing the transformed error.\n */\n mapErr<U extends Error>(fn: (err: E) => U): ResultDefinition<never, U> {\n return new Err<U>(fn(this.error)) as unknown as ResultDefinition<never, U>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value (which does not exist) of this `Err`.\n * @template U The type of the value in the resulting `Result`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns The original `Err` instance.\n */\n flatMap<U>(\n _fn: (value: never) => ResultDefinition<U, never>,\n ): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Retrieves the error value contained in this `Err`.\n * @returns The error value contained in this `Err`.\n */\n unwrapErr(): E {\n return this.error;\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return None();\n }\n}\n","import type { ResultDefinition } from \"./result\";\nimport type { Err } from \"./err\";\n\n/**\n * Represents a successful result (`Ok`) that contains a value.\n * @template T The type of the value contained in this `Ok`.\n */\nexport class Ok<T> implements ResultDefinition<T, never> {\n /**\n * Creates a new `Ok` instance with the given value.\n * @param value The value to wrap in the `Ok` instance.\n */\n constructor(private value: T) {}\n /**\n * Checks if this result is an `Ok`.\n * @returns `true` because this is an `Ok`.\n */\n isOk(): this is Ok<T> {\n return true;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `false` because this is an `Ok`.\n */\n isErr(): this is Err<never> {\n return false;\n }\n\n /**\n * Retrieves the value contained in this `Ok`.\n * @returns The value contained in this `Ok`.\n */\n unwrap(): T {\n return this.value;\n }\n\n /**\n * Applies a transformation function to the value contained in this `Ok` and returns a new `Result` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Ok` containing the transformed value.\n */\n map<U>(fn: (value: T) => U): ResultDefinition<U, never> {\n return new Ok(fn(this.value)) as ResultDefinition<U, never>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value contained in this `Ok`.\n * @template U The type of the value in the resulting `Result`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U>(\n fn: (value: T) => ResultDefinition<U, never>,\n ): ResultDefinition<U, never> {\n return fn(this.value);\n }\n\n /**\n * Maps the error value (if any). Since this is an `Ok`, the error mapping function is ignored, and the original `Ok` is returned.\n * @template U The type of the error (ignored for `Ok`).\n * @param _fn The mapping function for errors (not used).\n * @returns The original `Ok` instance.\n */\n // mapErr<U extends Error | string>(fn: (err: U) => U): Result<T, never> {\n // \treturn this;\n mapErr<U extends Error>(_fn: (err: never) => U): ResultDefinition<T, U> {\n return this as unknown as ResultDefinition<T, U>;\n }\n\n /**\n * Retrieves the error contained in this result. Since this is an `Ok`, an error is thrown.\n * @throws An error because `unwrapErr` is called on an `Ok`.\n */\n unwrapErr(): never {\n throw new Error(\"Called unwrapErr on an Ok value\");\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return match(this, {\n Ok: (v) => Some(v),\n Err: (_) => None(),\n });\n }\n}\n","import {\n Err as ErrType,\n Ok as OkType,\n type Result,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Ok` instance, representing a successful result.\n * @template T The type of the value contained in the `Ok`.\n * @param value The value to wrap in the `Ok` instance.\n * @returns An `Ok` instance containing the given value.\n * @example\n * const result = Ok(42);\n * console.log(result.isOk()); // true\n * console.log(result.unwrap()); // 42\n */\nfunction Ok<T>(value: T): OkType<T> {\n return new OkType(value);\n}\n\n/**\n * Creates a new `Err` instance, representing a failed result.\n * @template E The type of the error contained in the `Err`.\n * @param error The error to wrap in the `Err` instance.\n * @returns An `Err` instance containing the given error.\n * @example\n * const result = Err(\"Something went wrong\");\n * console.log(result.isErr()); // true\n * console.log(result.unwrapErr()); // \"Something went wrong\"\n */\nfunction Err<E extends Error>(error: E | string): ErrType<E> {\n return new ErrType(error);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Ok = Ok;\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Err = Err;\n\nexport { Err, Ok, Result, ErrType, OkType };\n"]}
|
package/dist/result/index.js
CHANGED
package/dist/result/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/result/__internal__/return-types/err.ts","../../src/result/__internal__/return-types/ok.ts","../../src/result/result.ts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,IAAI,GAAO,KAAK,CAAA;AACzB;AAYA,SAASC,KAAqB,KAA+B,EAAA;AAC3D,EAAO,OAAA,IAAI,IAAQ,KAAK,CAAA;AAC1B;AAGC,MAAA,CAAe,EAAKD,GAAAA,GAAAA;AAEpB,MAAA,CAAe,GAAMC,GAAAA,IAAAA","file":"index.js","sourcesContent":["import type { Ok } from \"./ok\";\nimport type { ResultDefinition } from \"./result\";\n\n/**\n * Represents a failed result (`Err`) that contains an error value.\n * @template E The type of the error contained in this `Err`.\n */\nexport class Err<E extends Error>\n extends Error\n implements ResultDefinition<never, E>\n{\n private error: E;\n /**\n * Creates a new `Err` instance with the given error value.\n * @param error The error to wrap in the `Err` instance.\n */\n constructor(error: E | string) {\n super(typeof error === \"string\" ? error : error.message);\n this.error =\n typeof error === \"string\" ? (new Error(error) as E) : (error as E);\n Object.setPrototypeOf(this, Err.prototype);\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, Err);\n }\n }\n\n /**\n * Checks if this result is an `Ok`.\n * @returns `false` because this is an `Err`.\n */\n isOk(): this is Ok<never> {\n return false;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `true` because this is an `Err`.\n */\n isErr(): this is Err<E extends Error ? E : Error> {\n return true;\n }\n\n /**\n * Retrieves the value contained in this result. Since this is an `Err`, an error is thrown.\n * @throws An error because `unwrap` is called on an `Err`.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on an Err value\");\n }\n\n /**\n * Maps the value (if any). Since this is an `Err`, the mapping function is ignored, and the original `Err` is returned.\n * @template U The type of the value (ignored for `Err`).\n * @param _fn The mapping function for values (not used).\n * @returns The original `Err` instance.\n */\n map<U>(_fn: (value: never) => U): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Maps the error value using a transformation function and returns a new `Result` with the transformed error.\n * @template U The type of the transformed error.\n * @param fn The transformation function to apply to the error value.\n * @returns A new `Err` containing the transformed error.\n */\n mapErr<U extends Error>(fn: (err: E) => U): ResultDefinition<never, U> {\n return new Err<U>(fn(this.error)) as unknown as ResultDefinition<never, U>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value (which does not exist) of this `Err`.\n * @template U The type of the value in the resulting `Result`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns The original `Err` instance.\n */\n flatMap<U>(\n _fn: (value: never) => ResultDefinition<U, never>,\n ): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Retrieves the error value contained in this `Err`.\n * @returns The error value contained in this `Err`.\n */\n unwrapErr(): E {\n return this.error;\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return None();\n }\n}\n","import type { ResultDefinition } from \"./result\";\nimport type { Err } from \"./err\";\n\n/**\n * Represents a successful result (`Ok`) that contains a value.\n * @template T The type of the value contained in this `Ok`.\n */\nexport class Ok<T> implements ResultDefinition<T, never> {\n /**\n * Creates a new `Ok` instance with the given value.\n * @param value The value to wrap in the `Ok` instance.\n */\n constructor(private value: T) {}\n /**\n * Checks if this result is an `Ok`.\n * @returns `true` because this is an `Ok`.\n */\n isOk(): this is Ok<T> {\n return true;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `false` because this is an `Ok`.\n */\n isErr(): this is Err<never> {\n return false;\n }\n\n /**\n * Retrieves the value contained in this `Ok`.\n * @returns The value contained in this `Ok`.\n */\n unwrap(): T {\n return this.value;\n }\n\n /**\n * Applies a transformation function to the value contained in this `Ok` and returns a new `Result` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Ok` containing the transformed value.\n */\n map<U>(fn: (value: T) => U): ResultDefinition<U, never> {\n return new Ok(fn(this.value)) as ResultDefinition<U, never>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value contained in this `Ok`.\n * @template U The type of the value in the resulting `Result`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U>(\n fn: (value: T) => ResultDefinition<U, never>,\n ): ResultDefinition<U, never> {\n return fn(this.value);\n }\n\n /**\n * Maps the error value (if any). Since this is an `Ok`, the error mapping function is ignored, and the original `Ok` is returned.\n * @template U The type of the error (ignored for `Ok`).\n * @param _fn The mapping function for errors (not used).\n * @returns The original `Ok` instance.\n */\n // mapErr<U extends Error | string>(fn: (err: U) => U): Result<T, never> {\n // \treturn this;\n mapErr<U extends Error>(_fn: (err: never) => U): ResultDefinition<T, U> {\n return this as unknown as ResultDefinition<T, U>;\n }\n\n /**\n * Retrieves the error contained in this result. Since this is an `Ok`, an error is thrown.\n * @throws An error because `unwrapErr` is called on an `Ok`.\n */\n unwrapErr(): never {\n throw new Error(\"Called unwrapErr on an Ok value\");\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return match(this, {\n Ok: (v) => Some(v),\n Err: (_) => None(),\n });\n }\n}\n","import {\n Err as ErrType,\n Ok as OkType,\n type Result,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Ok` instance, representing a successful result.\n * @template T The type of the value contained in the `Ok`.\n * @param value The value to wrap in the `Ok` instance.\n * @returns An `Ok` instance containing the given value.\n * @example\n * const result = Ok(42);\n * console.log(result.isOk()); // true\n * console.log(result.unwrap()); // 42\n */\nfunction Ok<T>(value: T): OkType<T> {\n return new OkType(value);\n}\n\n/**\n * Creates a new `Err` instance, representing a failed result.\n * @template E The type of the error contained in the `Err`.\n * @param error The error to wrap in the `Err` instance.\n * @returns An `Err` instance containing the given error.\n * @example\n * const result = Err(\"Something went wrong\");\n * console.log(result.isErr()); // true\n * console.log(result.unwrapErr()); // \"Something went wrong\"\n */\nfunction Err<E extends Error>(error: E | string): ErrType<E> {\n return new ErrType(error);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Ok = Ok;\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Err = Err;\n\nexport
|
|
1
|
+
{"version":3,"sources":["../../src/result/__internal__/return-types/err.ts","../../src/result/__internal__/return-types/ok.ts","../../src/result/result.ts"],"names":["Ok","Err"],"mappings":";AAOO,IAAM,GAAA,GAAN,MAAM,IAAA,SACH,KAEV,CAAA;AAAA,EACU,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKR,YAAY,KAAmB,EAAA;AAC7B,IAAA,KAAA,CAAM,OAAO,KAAA,KAAU,QAAW,GAAA,KAAA,GAAQ,MAAM,OAAO,CAAA;AACvD,IAAA,IAAA,CAAK,QACH,OAAO,KAAA,KAAU,WAAY,IAAI,KAAA,CAAM,KAAK,CAAW,GAAA,KAAA;AACzD,IAAO,MAAA,CAAA,cAAA,CAAe,IAAM,EAAA,IAAA,CAAI,SAAS,CAAA;AAEzC,IAAA,IAAI,MAAM,iBAAmB,EAAA;AAC3B,MAAM,KAAA,CAAA,iBAAA,CAAkB,MAAM,IAAG,CAAA;AAAA;AACnC;AACF;AAAA;AAAA;AAAA;AAAA,EAMA,IAA0B,GAAA;AACxB,IAAO,OAAA,KAAA;AAAA;AACT;AAAA;AAAA;AAAA;AAAA,EAMA,KAAkD,GAAA;AAChD,IAAO,OAAA,IAAA;AAAA;AACT;AAAA;AAAA;AAAA;AAAA,EAMA,MAAgB,GAAA;AACd,IAAM,MAAA,IAAI,MAAM,+BAA+B,CAAA;AAAA;AACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IAAO,GAAsD,EAAA;AAC3D,IAAO,OAAA,IAAA;AAAA;AACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAwB,EAA+C,EAAA;AACrE,IAAA,OAAO,IAAI,IAAA,CAAO,EAAG,CAAA,IAAA,CAAK,KAAK,CAAC,CAAA;AAAA;AAClC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,QACE,GAC4B,EAAA;AAC5B,IAAO,OAAA,IAAA;AAAA;AACT;AAAA;AAAA;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,KAAM,IAAK;AAAA,KAClB,CAAA;AAAA;AAEL,CAAA;;;ACzEA,SAASA,IAAM,KAAqB,EAAA;AAClC,EAAO,OAAA,IAAI,GAAO,KAAK,CAAA;AACzB;AAYA,SAASC,KAAqB,KAA+B,EAAA;AAC3D,EAAO,OAAA,IAAI,IAAQ,KAAK,CAAA;AAC1B;AAGC,MAAA,CAAe,EAAKD,GAAAA,GAAAA;AAEpB,MAAA,CAAe,GAAMC,GAAAA,IAAAA","file":"index.js","sourcesContent":["import type { Ok } from \"./ok\";\nimport type { ResultDefinition } from \"./result\";\n\n/**\n * Represents a failed result (`Err`) that contains an error value.\n * @template E The type of the error contained in this `Err`.\n */\nexport class Err<E extends Error>\n extends Error\n implements ResultDefinition<never, E>\n{\n private error: E;\n /**\n * Creates a new `Err` instance with the given error value.\n * @param error The error to wrap in the `Err` instance.\n */\n constructor(error: E | string) {\n super(typeof error === \"string\" ? error : error.message);\n this.error =\n typeof error === \"string\" ? (new Error(error) as E) : (error as E);\n Object.setPrototypeOf(this, Err.prototype);\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, Err);\n }\n }\n\n /**\n * Checks if this result is an `Ok`.\n * @returns `false` because this is an `Err`.\n */\n isOk(): this is Ok<never> {\n return false;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `true` because this is an `Err`.\n */\n isErr(): this is Err<E extends Error ? E : Error> {\n return true;\n }\n\n /**\n * Retrieves the value contained in this result. Since this is an `Err`, an error is thrown.\n * @throws An error because `unwrap` is called on an `Err`.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on an Err value\");\n }\n\n /**\n * Maps the value (if any). Since this is an `Err`, the mapping function is ignored, and the original `Err` is returned.\n * @template U The type of the value (ignored for `Err`).\n * @param _fn The mapping function for values (not used).\n * @returns The original `Err` instance.\n */\n map<U>(_fn: (value: never) => U): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Maps the error value using a transformation function and returns a new `Result` with the transformed error.\n * @template U The type of the transformed error.\n * @param fn The transformation function to apply to the error value.\n * @returns A new `Err` containing the transformed error.\n */\n mapErr<U extends Error>(fn: (err: E) => U): ResultDefinition<never, U> {\n return new Err<U>(fn(this.error)) as unknown as ResultDefinition<never, U>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value (which does not exist) of this `Err`.\n * @template U The type of the value in the resulting `Result`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns The original `Err` instance.\n */\n flatMap<U>(\n _fn: (value: never) => ResultDefinition<U, never>,\n ): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Retrieves the error value contained in this `Err`.\n * @returns The error value contained in this `Err`.\n */\n unwrapErr(): E {\n return this.error;\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return None();\n }\n}\n","import type { ResultDefinition } from \"./result\";\nimport type { Err } from \"./err\";\n\n/**\n * Represents a successful result (`Ok`) that contains a value.\n * @template T The type of the value contained in this `Ok`.\n */\nexport class Ok<T> implements ResultDefinition<T, never> {\n /**\n * Creates a new `Ok` instance with the given value.\n * @param value The value to wrap in the `Ok` instance.\n */\n constructor(private value: T) {}\n /**\n * Checks if this result is an `Ok`.\n * @returns `true` because this is an `Ok`.\n */\n isOk(): this is Ok<T> {\n return true;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `false` because this is an `Ok`.\n */\n isErr(): this is Err<never> {\n return false;\n }\n\n /**\n * Retrieves the value contained in this `Ok`.\n * @returns The value contained in this `Ok`.\n */\n unwrap(): T {\n return this.value;\n }\n\n /**\n * Applies a transformation function to the value contained in this `Ok` and returns a new `Result` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Ok` containing the transformed value.\n */\n map<U>(fn: (value: T) => U): ResultDefinition<U, never> {\n return new Ok(fn(this.value)) as ResultDefinition<U, never>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value contained in this `Ok`.\n * @template U The type of the value in the resulting `Result`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U>(\n fn: (value: T) => ResultDefinition<U, never>,\n ): ResultDefinition<U, never> {\n return fn(this.value);\n }\n\n /**\n * Maps the error value (if any). Since this is an `Ok`, the error mapping function is ignored, and the original `Ok` is returned.\n * @template U The type of the error (ignored for `Ok`).\n * @param _fn The mapping function for errors (not used).\n * @returns The original `Ok` instance.\n */\n // mapErr<U extends Error | string>(fn: (err: U) => U): Result<T, never> {\n // \treturn this;\n mapErr<U extends Error>(_fn: (err: never) => U): ResultDefinition<T, U> {\n return this as unknown as ResultDefinition<T, U>;\n }\n\n /**\n * Retrieves the error contained in this result. Since this is an `Ok`, an error is thrown.\n * @throws An error because `unwrapErr` is called on an `Ok`.\n */\n unwrapErr(): never {\n throw new Error(\"Called unwrapErr on an Ok value\");\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return match(this, {\n Ok: (v) => Some(v),\n Err: (_) => None(),\n });\n }\n}\n","import {\n Err as ErrType,\n Ok as OkType,\n type Result,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Ok` instance, representing a successful result.\n * @template T The type of the value contained in the `Ok`.\n * @param value The value to wrap in the `Ok` instance.\n * @returns An `Ok` instance containing the given value.\n * @example\n * const result = Ok(42);\n * console.log(result.isOk()); // true\n * console.log(result.unwrap()); // 42\n */\nfunction Ok<T>(value: T): OkType<T> {\n return new OkType(value);\n}\n\n/**\n * Creates a new `Err` instance, representing a failed result.\n * @template E The type of the error contained in the `Err`.\n * @param error The error to wrap in the `Err` instance.\n * @returns An `Err` instance containing the given error.\n * @example\n * const result = Err(\"Something went wrong\");\n * console.log(result.isErr()); // true\n * console.log(result.unwrapErr()); // \"Something went wrong\"\n */\nfunction Err<E extends Error>(error: E | string): ErrType<E> {\n return new ErrType(error);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Ok = Ok;\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Err = Err;\n\nexport { Err, Ok, Result, ErrType, OkType };\n"]}
|
package/dist/result/result.cjs
CHANGED
|
@@ -166,5 +166,10 @@ function Err2(error) {
|
|
|
166
166
|
}
|
|
167
167
|
global.Ok = Ok2;
|
|
168
168
|
global.Err = Err2;
|
|
169
|
+
|
|
170
|
+
exports.Err = Err2;
|
|
171
|
+
exports.ErrType = Err;
|
|
172
|
+
exports.Ok = Ok2;
|
|
173
|
+
exports.OkType = Ok;
|
|
169
174
|
//# sourceMappingURL=result.cjs.map
|
|
170
175
|
//# sourceMappingURL=result.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/result/__internal__/return-types/err.ts","../../src/result/__internal__/return-types/ok.ts","../../src/result/result.ts"],"names":["Ok","Err"],"mappings":";;;
|
|
1
|
+
{"version":3,"sources":["../../src/result/__internal__/return-types/err.ts","../../src/result/__internal__/return-types/ok.ts","../../src/result/result.ts"],"names":["Ok","Err"],"mappings":";;;AAOa,IAAA,GAAA,GAAN,MAAM,IAAA,SACH,KAEV,CAAA;AAAA,EACU,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKR,YAAY,KAAmB,EAAA;AAC7B,IAAA,KAAA,CAAM,OAAO,KAAA,KAAU,QAAW,GAAA,KAAA,GAAQ,MAAM,OAAO,CAAA;AACvD,IAAA,IAAA,CAAK,QACH,OAAO,KAAA,KAAU,WAAY,IAAI,KAAA,CAAM,KAAK,CAAW,GAAA,KAAA;AACzD,IAAO,MAAA,CAAA,cAAA,CAAe,IAAM,EAAA,IAAA,CAAI,SAAS,CAAA;AAEzC,IAAA,IAAI,MAAM,iBAAmB,EAAA;AAC3B,MAAM,KAAA,CAAA,iBAAA,CAAkB,MAAM,IAAG,CAAA;AAAA;AACnC;AACF;AAAA;AAAA;AAAA;AAAA,EAMA,I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,GAAA,CAAG,EAAG,CAAA,IAAA,CAAK,KAAK,CAAC,CAAA;AAAA;AAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,QACE,EAC4B,EAAA;AAC5B,IAAO,OAAA,EAAA,CAAG,KAAK,KAAK,CAAA;AAAA;AACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAwB,GAAgD,EAAA;AACtE,IAAO,OAAA,IAAA;AAAA;AACT;AAAA;AAAA;AAAA;AAAA,EAMA,SAAmB,GAAA;AACjB,IAAM,MAAA,IAAI,MAAM,iCAAiC,CAAA;AAAA;AACnD;AAAA;AAAA;AAAA;AAAA,EAMA,EAAK,GAAA;AACH,IAAA,OAAO,MAAM,IAAM,EAAA;AAAA,MACjB,EAAI,EAAA,CAAC,CAAM,KAAA,IAAA,CAAK,CAAC,CAAA;AAAA,MACjB,GAAA,EAAK,CAAC,CAAA,KAAM,IAAK;AAAA,KAClB,CAAA;AAAA;AAEL;;;ACzEA,SAASA,IAAM,KAAqB,EAAA;AAClC,EAAO,OAAA,IAAI,GAAO,KAAK,CAAA;AACzB;AAYA,SAASC,KAAqB,KAA+B,EAAA;AAC3D,EAAO,OAAA,IAAI,IAAQ,KAAK,CAAA;AAC1B;AAGC,MAAA,CAAe,EAAKD,GAAAA,GAAAA;AAEpB,MAAA,CAAe,GAAMC,GAAAA,IAAAA","file":"result.cjs","sourcesContent":["import type { Ok } from \"./ok\";\nimport type { ResultDefinition } from \"./result\";\n\n/**\n * Represents a failed result (`Err`) that contains an error value.\n * @template E The type of the error contained in this `Err`.\n */\nexport class Err<E extends Error>\n extends Error\n implements ResultDefinition<never, E>\n{\n private error: E;\n /**\n * Creates a new `Err` instance with the given error value.\n * @param error The error to wrap in the `Err` instance.\n */\n constructor(error: E | string) {\n super(typeof error === \"string\" ? error : error.message);\n this.error =\n typeof error === \"string\" ? (new Error(error) as E) : (error as E);\n Object.setPrototypeOf(this, Err.prototype);\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, Err);\n }\n }\n\n /**\n * Checks if this result is an `Ok`.\n * @returns `false` because this is an `Err`.\n */\n isOk(): this is Ok<never> {\n return false;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `true` because this is an `Err`.\n */\n isErr(): this is Err<E extends Error ? E : Error> {\n return true;\n }\n\n /**\n * Retrieves the value contained in this result. Since this is an `Err`, an error is thrown.\n * @throws An error because `unwrap` is called on an `Err`.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on an Err value\");\n }\n\n /**\n * Maps the value (if any). Since this is an `Err`, the mapping function is ignored, and the original `Err` is returned.\n * @template U The type of the value (ignored for `Err`).\n * @param _fn The mapping function for values (not used).\n * @returns The original `Err` instance.\n */\n map<U>(_fn: (value: never) => U): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Maps the error value using a transformation function and returns a new `Result` with the transformed error.\n * @template U The type of the transformed error.\n * @param fn The transformation function to apply to the error value.\n * @returns A new `Err` containing the transformed error.\n */\n mapErr<U extends Error>(fn: (err: E) => U): ResultDefinition<never, U> {\n return new Err<U>(fn(this.error)) as unknown as ResultDefinition<never, U>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value (which does not exist) of this `Err`.\n * @template U The type of the value in the resulting `Result`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns The original `Err` instance.\n */\n flatMap<U>(\n _fn: (value: never) => ResultDefinition<U, never>,\n ): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Retrieves the error value contained in this `Err`.\n * @returns The error value contained in this `Err`.\n */\n unwrapErr(): E {\n return this.error;\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return None();\n }\n}\n","import type { ResultDefinition } from \"./result\";\nimport type { Err } from \"./err\";\n\n/**\n * Represents a successful result (`Ok`) that contains a value.\n * @template T The type of the value contained in this `Ok`.\n */\nexport class Ok<T> implements ResultDefinition<T, never> {\n /**\n * Creates a new `Ok` instance with the given value.\n * @param value The value to wrap in the `Ok` instance.\n */\n constructor(private value: T) {}\n /**\n * Checks if this result is an `Ok`.\n * @returns `true` because this is an `Ok`.\n */\n isOk(): this is Ok<T> {\n return true;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `false` because this is an `Ok`.\n */\n isErr(): this is Err<never> {\n return false;\n }\n\n /**\n * Retrieves the value contained in this `Ok`.\n * @returns The value contained in this `Ok`.\n */\n unwrap(): T {\n return this.value;\n }\n\n /**\n * Applies a transformation function to the value contained in this `Ok` and returns a new `Result` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Ok` containing the transformed value.\n */\n map<U>(fn: (value: T) => U): ResultDefinition<U, never> {\n return new Ok(fn(this.value)) as ResultDefinition<U, never>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value contained in this `Ok`.\n * @template U The type of the value in the resulting `Result`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U>(\n fn: (value: T) => ResultDefinition<U, never>,\n ): ResultDefinition<U, never> {\n return fn(this.value);\n }\n\n /**\n * Maps the error value (if any). Since this is an `Ok`, the error mapping function is ignored, and the original `Ok` is returned.\n * @template U The type of the error (ignored for `Ok`).\n * @param _fn The mapping function for errors (not used).\n * @returns The original `Ok` instance.\n */\n // mapErr<U extends Error | string>(fn: (err: U) => U): Result<T, never> {\n // \treturn this;\n mapErr<U extends Error>(_fn: (err: never) => U): ResultDefinition<T, U> {\n return this as unknown as ResultDefinition<T, U>;\n }\n\n /**\n * Retrieves the error contained in this result. Since this is an `Ok`, an error is thrown.\n * @throws An error because `unwrapErr` is called on an `Ok`.\n */\n unwrapErr(): never {\n throw new Error(\"Called unwrapErr on an Ok value\");\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return match(this, {\n Ok: (v) => Some(v),\n Err: (_) => None(),\n });\n }\n}\n","import {\n Err as ErrType,\n Ok as OkType,\n type Result,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Ok` instance, representing a successful result.\n * @template T The type of the value contained in the `Ok`.\n * @param value The value to wrap in the `Ok` instance.\n * @returns An `Ok` instance containing the given value.\n * @example\n * const result = Ok(42);\n * console.log(result.isOk()); // true\n * console.log(result.unwrap()); // 42\n */\nfunction Ok<T>(value: T): OkType<T> {\n return new OkType(value);\n}\n\n/**\n * Creates a new `Err` instance, representing a failed result.\n * @template E The type of the error contained in the `Err`.\n * @param error The error to wrap in the `Err` instance.\n * @returns An `Err` instance containing the given error.\n * @example\n * const result = Err(\"Something went wrong\");\n * console.log(result.isErr()); // true\n * console.log(result.unwrapErr()); // \"Something went wrong\"\n */\nfunction Err<E extends Error>(error: E | string): ErrType<E> {\n return new ErrType(error);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Ok = Ok;\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Err = Err;\n\nexport { Err, Ok, Result, ErrType, OkType };\n"]}
|
package/dist/result/result.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/result/__internal__/return-types/err.ts","../../src/result/__internal__/return-types/ok.ts","../../src/result/result.ts"],"names":["Ok","Err"],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../src/result/__internal__/return-types/err.ts","../../src/result/__internal__/return-types/ok.ts","../../src/result/result.ts"],"names":["Ok","Err"],"mappings":";AAOa,IAAA,GAAA,GAAN,MAAM,IAAA,SACH,KAEV,CAAA;AAAA,EACU,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKR,YAAY,KAAmB,EAAA;AAC7B,IAAA,KAAA,CAAM,OAAO,KAAA,KAAU,QAAW,GAAA,KAAA,GAAQ,MAAM,OAAO,CAAA;AACvD,IAAA,IAAA,CAAK,QACH,OAAO,K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O,OAAA,IAAA;AAAA;AACT;AAAA;AAAA;AAAA;AAAA,EAMA,KAA4B,GAAA;AAC1B,IAAO,OAAA,KAAA;AAAA;AACT;AAAA;AAAA;AAAA;AAAA,EAMA,MAAY,GAAA;AACV,IAAA,OAAO,IAAK,CAAA,KAAA;AAAA;AACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IAAO,EAAiD,EAAA;AACtD,IAAA,OAAO,IAAI,GAAA,CAAG,EAAG,CAAA,IAAA,CAAK,KAAK,CAAC,CAAA;AAAA;AAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,QACE,EAC4B,EAAA;AAC5B,IAAO,OAAA,EAAA,CAAG,KAAK,KAAK,CAAA;AAAA;AACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAwB,GAAgD,EAAA;AACtE,IAAO,OAAA,IAAA;AAAA;AACT;AAAA;AAAA;AAAA;AAAA,EAMA,SAAmB,GAAA;AACjB,IAAM,MAAA,IAAI,MAAM,iCAAiC,CAAA;AAAA;AACnD;AAAA;AAAA;AAAA;AAAA,EAMA,EAAK,GAAA;AACH,IAAA,OAAO,MAAM,IAAM,EAAA;AAAA,MACjB,EAAI,EAAA,CAAC,CAAM,KAAA,IAAA,CAAK,CAAC,CAAA;AAAA,MACjB,GAAA,EAAK,CAAC,CAAA,KAAM,IAAK;AAAA,KAClB,CAAA;AAAA;AAEL;;;ACzEA,SAASA,IAAM,KAAqB,EAAA;AAClC,EAAO,OAAA,IAAI,GAAO,KAAK,CAAA;AACzB;AAYA,SAASC,KAAqB,KAA+B,EAAA;AAC3D,EAAO,OAAA,IAAI,IAAQ,KAAK,CAAA;AAC1B;AAGC,MAAA,CAAe,EAAKD,GAAAA,GAAAA;AAEpB,MAAA,CAAe,GAAMC,GAAAA,IAAAA","file":"result.js","sourcesContent":["import type { Ok } from \"./ok\";\nimport type { ResultDefinition } from \"./result\";\n\n/**\n * Represents a failed result (`Err`) that contains an error value.\n * @template E The type of the error contained in this `Err`.\n */\nexport class Err<E extends Error>\n extends Error\n implements ResultDefinition<never, E>\n{\n private error: E;\n /**\n * Creates a new `Err` instance with the given error value.\n * @param error The error to wrap in the `Err` instance.\n */\n constructor(error: E | string) {\n super(typeof error === \"string\" ? error : error.message);\n this.error =\n typeof error === \"string\" ? (new Error(error) as E) : (error as E);\n Object.setPrototypeOf(this, Err.prototype);\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, Err);\n }\n }\n\n /**\n * Checks if this result is an `Ok`.\n * @returns `false` because this is an `Err`.\n */\n isOk(): this is Ok<never> {\n return false;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `true` because this is an `Err`.\n */\n isErr(): this is Err<E extends Error ? E : Error> {\n return true;\n }\n\n /**\n * Retrieves the value contained in this result. Since this is an `Err`, an error is thrown.\n * @throws An error because `unwrap` is called on an `Err`.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on an Err value\");\n }\n\n /**\n * Maps the value (if any). Since this is an `Err`, the mapping function is ignored, and the original `Err` is returned.\n * @template U The type of the value (ignored for `Err`).\n * @param _fn The mapping function for values (not used).\n * @returns The original `Err` instance.\n */\n map<U>(_fn: (value: never) => U): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Maps the error value using a transformation function and returns a new `Result` with the transformed error.\n * @template U The type of the transformed error.\n * @param fn The transformation function to apply to the error value.\n * @returns A new `Err` containing the transformed error.\n */\n mapErr<U extends Error>(fn: (err: E) => U): ResultDefinition<never, U> {\n return new Err<U>(fn(this.error)) as unknown as ResultDefinition<never, U>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value (which does not exist) of this `Err`.\n * @template U The type of the value in the resulting `Result`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns The original `Err` instance.\n */\n flatMap<U>(\n _fn: (value: never) => ResultDefinition<U, never>,\n ): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Retrieves the error value contained in this `Err`.\n * @returns The error value contained in this `Err`.\n */\n unwrapErr(): E {\n return this.error;\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return None();\n }\n}\n","import type { ResultDefinition } from \"./result\";\nimport type { Err } from \"./err\";\n\n/**\n * Represents a successful result (`Ok`) that contains a value.\n * @template T The type of the value contained in this `Ok`.\n */\nexport class Ok<T> implements ResultDefinition<T, never> {\n /**\n * Creates a new `Ok` instance with the given value.\n * @param value The value to wrap in the `Ok` instance.\n */\n constructor(private value: T) {}\n /**\n * Checks if this result is an `Ok`.\n * @returns `true` because this is an `Ok`.\n */\n isOk(): this is Ok<T> {\n return true;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `false` because this is an `Ok`.\n */\n isErr(): this is Err<never> {\n return false;\n }\n\n /**\n * Retrieves the value contained in this `Ok`.\n * @returns The value contained in this `Ok`.\n */\n unwrap(): T {\n return this.value;\n }\n\n /**\n * Applies a transformation function to the value contained in this `Ok` and returns a new `Result` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Ok` containing the transformed value.\n */\n map<U>(fn: (value: T) => U): ResultDefinition<U, never> {\n return new Ok(fn(this.value)) as ResultDefinition<U, never>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value contained in this `Ok`.\n * @template U The type of the value in the resulting `Result`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U>(\n fn: (value: T) => ResultDefinition<U, never>,\n ): ResultDefinition<U, never> {\n return fn(this.value);\n }\n\n /**\n * Maps the error value (if any). Since this is an `Ok`, the error mapping function is ignored, and the original `Ok` is returned.\n * @template U The type of the error (ignored for `Ok`).\n * @param _fn The mapping function for errors (not used).\n * @returns The original `Ok` instance.\n */\n // mapErr<U extends Error | string>(fn: (err: U) => U): Result<T, never> {\n // \treturn this;\n mapErr<U extends Error>(_fn: (err: never) => U): ResultDefinition<T, U> {\n return this as unknown as ResultDefinition<T, U>;\n }\n\n /**\n * Retrieves the error contained in this result. Since this is an `Ok`, an error is thrown.\n * @throws An error because `unwrapErr` is called on an `Ok`.\n */\n unwrapErr(): never {\n throw new Error(\"Called unwrapErr on an Ok value\");\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return match(this, {\n Ok: (v) => Some(v),\n Err: (_) => None(),\n });\n }\n}\n","import {\n Err as ErrType,\n Ok as OkType,\n type Result,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Ok` instance, representing a successful result.\n * @template T The type of the value contained in the `Ok`.\n * @param value The value to wrap in the `Ok` instance.\n * @returns An `Ok` instance containing the given value.\n * @example\n * const result = Ok(42);\n * console.log(result.isOk()); // true\n * console.log(result.unwrap()); // 42\n */\nfunction Ok<T>(value: T): OkType<T> {\n return new OkType(value);\n}\n\n/**\n * Creates a new `Err` instance, representing a failed result.\n * @template E The type of the error contained in the `Err`.\n * @param error The error to wrap in the `Err` instance.\n * @returns An `Err` instance containing the given error.\n * @example\n * const result = Err(\"Something went wrong\");\n * console.log(result.isErr()); // true\n * console.log(result.unwrapErr()); // \"Something went wrong\"\n */\nfunction Err<E extends Error>(error: E | string): ErrType<E> {\n return new ErrType(error);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Ok = Ok;\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Err = Err;\n\nexport { Err, Ok, Result, ErrType, OkType };\n"]}
|
package/package.json
CHANGED
|
@@ -1,73 +1,74 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
2
|
+
"name": "@consolidados/results",
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"description": "Result types, ease and simple",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"sideEffects": true,
|
|
10
|
+
"homepage": "https://github.com/consolidados/results",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/consolidados/results"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist/"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
"./option": {
|
|
20
|
+
"types": "./dist/option/index.d.ts",
|
|
21
|
+
"require": "./dist/option/index.cjs",
|
|
22
|
+
"default": "./dist/option/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./result": {
|
|
25
|
+
"types": "./dist/result/index.d.ts",
|
|
26
|
+
"require": "./dist/result/index.cjs",
|
|
27
|
+
"default": "./dist/result/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./helpers": {
|
|
30
|
+
"types": "./dist/helpers/match.d.ts",
|
|
31
|
+
"require": "./dist/helpers/match.cjs",
|
|
32
|
+
"default": "./dist/helpers/match.js"
|
|
33
|
+
},
|
|
34
|
+
"./globals": {
|
|
35
|
+
"types": "./dist/types/globals.d.ts"
|
|
36
|
+
},
|
|
37
|
+
".": {
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"require": "./dist/index.cjs",
|
|
40
|
+
"default": "./dist/index.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "rm -rf dist && tsup",
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"release": "release-it",
|
|
47
|
+
"format-and-lint": "biome check .",
|
|
48
|
+
"format-and-lint:fix": "biome check . --write"
|
|
49
|
+
},
|
|
50
|
+
"keywords": [
|
|
51
|
+
"Rust",
|
|
52
|
+
"Result",
|
|
53
|
+
"Option",
|
|
54
|
+
"Some",
|
|
55
|
+
"None",
|
|
56
|
+
"Ok",
|
|
57
|
+
"Err",
|
|
58
|
+
"Match"
|
|
59
|
+
],
|
|
60
|
+
"author": "Johnny Carreiro",
|
|
61
|
+
"license": "ISC",
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@release-it/conventional-changelog": "^10.0.0",
|
|
64
|
+
"@types/node": "^22.13.13",
|
|
65
|
+
"biome": "^0.3.3",
|
|
66
|
+
"release-it": "^18.1.2",
|
|
67
|
+
"tsup": "^8.4.0",
|
|
68
|
+
"typescript": "^5.8.2",
|
|
69
|
+
"vitest": "^3.0.9"
|
|
70
|
+
},
|
|
71
|
+
"publishConfig": {
|
|
72
|
+
"access": "public"
|
|
73
|
+
}
|
|
73
74
|
}
|