get-or-throw 1.4.0 → 1.5.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.
- package/README.md +10 -5
- package/dist/index.cjs +4 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
- package/src/get-or-throw.ts +3 -0
package/README.md
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
# get-or-throw
|
|
2
2
|
|
|
3
|
-
A convenience function for
|
|
4
|
-
|
|
3
|
+
A simple convenience function for safely accessing values in objects and arrays.
|
|
4
|
+
It gets a value from an object or array at a specified key or index, and throw
|
|
5
|
+
an error if the resulting value is `undefined` or `null`. Optionally, you can
|
|
6
|
+
set custom error message.
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
This was created to make it easy to adhere to Typescript's
|
|
9
|
+
[noUncheckedIndexedAccess](https://www.typescriptlang.org/tsconfig/#noUncheckedIndexedAccess)
|
|
10
|
+
setting, which is recommended for strict type checking.
|
|
9
11
|
|
|
10
12
|
## Features
|
|
11
13
|
|
|
@@ -14,6 +16,7 @@ or null.
|
|
|
14
16
|
- Supports negative indexing for arrays.
|
|
15
17
|
- Allows for custom error messages.
|
|
16
18
|
- Zero dependencies.
|
|
19
|
+
- Provides `got` as alias for `getOrThrow`
|
|
17
20
|
|
|
18
21
|
## Installation
|
|
19
22
|
|
|
@@ -58,3 +61,5 @@ console.log(getOrThrow(arr, 1));
|
|
|
58
61
|
const obj = { a: 1, b: undefined, c: 3 };
|
|
59
62
|
console.log(getOrThrow(obj, "b"));
|
|
60
63
|
```
|
|
64
|
+
|
|
65
|
+
## Alias
|
package/dist/index.cjs
CHANGED
|
@@ -20,7 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
-
getOrThrow: () => getOrThrow
|
|
23
|
+
getOrThrow: () => getOrThrow,
|
|
24
|
+
got: () => getOrThrow
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(src_exports);
|
|
26
27
|
|
|
@@ -73,5 +74,6 @@ function getOrThrow(objOrArr, keyOrIndex, errorMessage) {
|
|
|
73
74
|
}
|
|
74
75
|
// Annotate the CommonJS export names for ESM import in node:
|
|
75
76
|
0 && (module.exports = {
|
|
76
|
-
getOrThrow
|
|
77
|
+
getOrThrow,
|
|
78
|
+
got
|
|
77
79
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -13,4 +13,4 @@
|
|
|
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): NonNullable<T>;
|
|
15
15
|
|
|
16
|
-
export { getOrThrow };
|
|
16
|
+
export { getOrThrow, getOrThrow as got };
|
package/dist/index.d.ts
CHANGED
|
@@ -13,4 +13,4 @@
|
|
|
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): NonNullable<T>;
|
|
15
15
|
|
|
16
|
-
export { getOrThrow };
|
|
16
|
+
export { getOrThrow, getOrThrow as got };
|
package/dist/index.js
CHANGED
package/package.json
CHANGED