get-or-throw 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,8 +12,6 @@
12
12
  */
13
13
  declare function getOrThrow<T extends object, K extends keyof T>(objOrArr: T, keyOrIndex: K, errorMessage?: string): NonNullable<T[K]>;
14
14
  declare function getOrThrow<T>(objOrArr: T[], keyOrIndex: number, errorMessage?: string): T;
15
- /** Export the same function under the alias 'got' */
16
-
17
15
  //#endregion
18
16
  export { getOrThrow, getOrThrow as got };
19
- //# sourceMappingURL=index-CLvtl5bd.d.ts.map
17
+ //# sourceMappingURL=index.d.cts.map
@@ -12,8 +12,6 @@
12
12
  */
13
13
  declare function getOrThrow<T extends object, K extends keyof T>(objOrArr: T, keyOrIndex: K, errorMessage?: string): NonNullable<T[K]>;
14
14
  declare function getOrThrow<T>(objOrArr: T[], keyOrIndex: number, errorMessage?: string): T;
15
- /** Export the same function under the alias 'got' */
16
-
17
15
  //#endregion
18
16
  export { getOrThrow, getOrThrow as got };
19
- //# sourceMappingURL=index-CRoiksIS.d.cts.map
17
+ //# sourceMappingURL=index.d.mts.map
@@ -19,4 +19,4 @@ function getOrThrow(objOrArr, keyOrIndex, errorMessage) {
19
19
  //#endregion
20
20
  export { getOrThrow, getOrThrow as got };
21
21
 
22
- //# sourceMappingURL=index.js.map
22
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/get-or-throw.ts"],"sourcesContent":["/**\n * Get a value from an object or array, and throw an error if the key or index\n * does not exist or if the resulting value is undefined.\n *\n * @param objOrArr The object or array to get the value from.\n * @param keyOrIndex The key or index to get the value from.\n * @param errorMessage Optional error message to include in the error thrown.\n * @returns The value at the given key or index, guaranteed to be defined.\n * @throws An error if the key or index does not exist, or if the value is\n * undefined.\n */\nexport function getOrThrow<T extends object, K extends keyof T>(\n objOrArr: T,\n keyOrIndex: K,\n errorMessage?: string,\n): NonNullable<T[K]>;\nexport function getOrThrow<T>(\n objOrArr: T[],\n keyOrIndex: number,\n errorMessage?: string,\n): T;\nexport function getOrThrow<T extends object, K extends keyof T>(\n objOrArr: T | T[],\n keyOrIndex: K | number,\n errorMessage?: string,\n): T[K] | T {\n if (Array.isArray(objOrArr)) {\n const length = objOrArr.length;\n let index = keyOrIndex as number;\n\n /** Allow for negative indexing. */\n if (index < 0) {\n index = length + index;\n }\n\n if (index >= 0 && index < length) {\n const value = objOrArr[index];\n\n if (value === undefined) {\n throw new Error(\n errorMessage ?? `Value at index ${String(keyOrIndex)} is undefined.`,\n );\n }\n return value;\n } else {\n throw new Error(\n errorMessage ?? `Index ${String(keyOrIndex)} is out of bounds.`,\n );\n }\n } else {\n if (keyOrIndex in objOrArr) {\n const value = objOrArr[keyOrIndex as K];\n\n if (value === undefined) {\n throw new Error(\n errorMessage ?? `Value at key \"${String(keyOrIndex)}\" is undefined.`,\n );\n }\n return value;\n } else {\n throw new Error(\n errorMessage ??\n `Key \"${String(keyOrIndex)}\" does not exist in the object.`,\n );\n }\n }\n}\n\n/** Export the same function under the alias 'got' */\nexport { getOrThrow as got };\n"],"mappings":";AAqBA,SAAgB,WACd,UACA,YACA,cACU;AACV,KAAI,MAAM,QAAQ,SAAS,EAAE;EAC3B,MAAM,SAAS,SAAS;EACxB,IAAI,QAAQ;;AAGZ,MAAI,QAAQ,EACV,SAAQ,SAAS;AAGnB,MAAI,SAAS,KAAK,QAAQ,QAAQ;GAChC,MAAM,QAAQ,SAAS;AAEvB,OAAI,UAAU,KAAA,EACZ,OAAM,IAAI,MACR,gBAAgB,kBAAkB,OAAO,WAAW,CAAC,gBACtD;AAEH,UAAO;QAEP,OAAM,IAAI,MACR,gBAAgB,SAAS,OAAO,WAAW,CAAC,oBAC7C;YAGC,cAAc,UAAU;EAC1B,MAAM,QAAQ,SAAS;AAEvB,MAAI,UAAU,KAAA,EACZ,OAAM,IAAI,MACR,gBAAgB,iBAAiB,OAAO,WAAW,CAAC,iBACrD;AAEH,SAAO;OAEP,OAAM,IAAI,MACR,gBACE,QAAQ,OAAO,WAAW,CAAC,iCAC9B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "get-or-throw",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "A convenience function for safely getting values from dynamic objects and arrays",
5
5
  "keywords": [
6
6
  "indexed",
@@ -45,16 +45,16 @@
45
45
  "docs:preview": "vitepress preview docs"
46
46
  },
47
47
  "devDependencies": {
48
- "@codecompose/typescript-config": "^3.0.0",
49
- "del-cli": "^5.1.0",
50
- "oxfmt": "^0.33.0",
51
- "oxlint": "^1.48.0",
52
- "oxlint-tsgolint": "^0.15.0",
53
- "tsdown": "^0.12.0",
54
- "typescript": "6.0.0-beta",
55
- "vite": "^6.0.0",
48
+ "@codecompose/typescript-config": "^3.1.0",
49
+ "del-cli": "^7.0.0",
50
+ "oxfmt": "^0.43.0",
51
+ "oxlint": "^1.58.0",
52
+ "oxlint-tsgolint": "^0.20.0",
53
+ "tsdown": "^0.21.7",
54
+ "typescript": "6.0.2",
55
+ "vite": "^8.0.5",
56
56
  "vitepress": "^1.6.0",
57
- "vitest": "^3.0.8"
57
+ "vitest": "^4.1.2"
58
58
  },
59
59
  "engines": {
60
60
  "node": ">=22.12.0"
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/get-or-throw.ts"],"sourcesContent":["/**\n * Get a value from an object or array, and throw an error if the key or index\n * does not exist or if the resulting value is undefined.\n *\n * @param objOrArr The object or array to get the value from.\n * @param keyOrIndex The key or index to get the value from.\n * @param errorMessage Optional error message to include in the error thrown.\n * @returns The value at the given key or index, guaranteed to be defined.\n * @throws An error if the key or index does not exist, or if the value is\n * undefined.\n */\nexport function getOrThrow<T extends object, K extends keyof T>(\n objOrArr: T,\n keyOrIndex: K,\n errorMessage?: string,\n): NonNullable<T[K]>;\nexport function getOrThrow<T>(\n objOrArr: T[],\n keyOrIndex: number,\n errorMessage?: string,\n): T;\nexport function getOrThrow<T extends object, K extends keyof T>(\n objOrArr: T | T[],\n keyOrIndex: K | number,\n errorMessage?: string,\n): T[K] | T {\n if (Array.isArray(objOrArr)) {\n const length = objOrArr.length;\n let index = keyOrIndex as number;\n\n /** Allow for negative indexing. */\n if (index < 0) {\n index = length + index;\n }\n\n if (index >= 0 && index < length) {\n const value = objOrArr[index];\n\n if (value === undefined) {\n throw new Error(\n errorMessage ?? `Value at index ${String(keyOrIndex)} is undefined.`,\n );\n }\n return value;\n } else {\n throw new Error(\n errorMessage ?? `Index ${String(keyOrIndex)} is out of bounds.`,\n );\n }\n } else {\n if (keyOrIndex in objOrArr) {\n const value = objOrArr[keyOrIndex as K];\n\n if (value === undefined) {\n throw new Error(\n errorMessage ?? `Value at key \"${String(keyOrIndex)}\" is undefined.`,\n );\n }\n return value;\n } else {\n throw new Error(\n errorMessage ??\n `Key \"${String(keyOrIndex)}\" does not exist in the object.`,\n );\n }\n }\n}\n\n/** Export the same function under the alias 'got' */\nexport { getOrThrow as got };\n"],"mappings":";AAqBA,SAAgB,WACd,UACA,YACA,cACU;AACV,KAAI,MAAM,QAAQ,SAAS,EAAE;EAC3B,MAAM,SAAS,SAAS;EACxB,IAAI,QAAQ;;AAGZ,MAAI,QAAQ,EACV,SAAQ,SAAS;AAGnB,MAAI,SAAS,KAAK,QAAQ,QAAQ;GAChC,MAAM,QAAQ,SAAS;AAEvB,OAAI,UAAU,KAAA,EACZ,OAAM,IAAI,MACR,gBAAgB,kBAAkB,OAAO,WAAW,CAAC,gBACtD;AAEH,UAAO;QAEP,OAAM,IAAI,MACR,gBAAgB,SAAS,OAAO,WAAW,CAAC,oBAC7C;YAGC,cAAc,UAAU;EAC1B,MAAM,QAAQ,SAAS;AAEvB,MAAI,UAAU,KAAA,EACZ,OAAM,IAAI,MACR,gBAAgB,iBAAiB,OAAO,WAAW,CAAC,iBACrD;AAEH,SAAO;OAEP,OAAM,IAAI,MACR,gBACE,QAAQ,OAAO,WAAW,CAAC,iCAC9B"}