get-or-throw 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ on:
4
4
  push:
5
5
  branches: [main]
6
6
  pull_request:
7
- branches: [main]
7
+ branches: ["**"]
8
8
 
9
9
  concurrency:
10
10
  group: ${{ github.workflow }}-${{ github.ref }}
package/README.md CHANGED
@@ -68,83 +68,3 @@ const value = got(obj, "b"); // Output: null
68
68
  const obj = { a: 1, b: undefined, c: 3 };
69
69
  const value = got(obj, "b");
70
70
  ```
71
-
72
- And here's the updated test file:
73
-
74
- ```typescript:src/get-or-throw.test.ts
75
- import { describe, it, expect } from 'vitest';
76
- import { got, getOrThrow } from './get-or-throw';
77
-
78
- describe('get-or-throw', () => {
79
- describe('array access', () => {
80
- it('should get value at positive index', () => {
81
- const arr = [1, 2, 3];
82
- expect(got(arr, 1)).toBe(2);
83
- expect(getOrThrow(arr, 1)).toBe(2);
84
- });
85
-
86
- it('should support negative indexing', () => {
87
- const arr = [1, 2, 3];
88
- expect(got(arr, -1)).toBe(3);
89
- expect(got(arr, -2)).toBe(2);
90
- });
91
-
92
- it('should throw on out of bounds index', () => {
93
- const arr = [1, 2, 3];
94
- expect(() => got(arr, 3)).toThrow('Index 3 is out of bounds.');
95
- });
96
-
97
- it('should allow null values', () => {
98
- const arr = [1, null, 3];
99
- expect(got(arr, 1)).toBeNull();
100
- });
101
-
102
- it('should throw on undefined values', () => {
103
- const arr = [1, undefined, 3];
104
- expect(() => got(arr, 1)).toThrow('Value at index 1 is undefined.');
105
- });
106
- });
107
-
108
- describe('object access', () => {
109
- it('should get value at existing key', () => {
110
- const obj = { a: 1, b: 2, c: 3 };
111
- expect(got(obj, 'b')).toBe(2);
112
- expect(getOrThrow(obj, 'b')).toBe(2);
113
- });
114
-
115
- it('should throw on non-existent key', () => {
116
- const obj = { a: 1, b: 2, c: 3 };
117
- expect(() => got(obj, 'd' as keyof typeof obj)).toThrow(
118
- 'Key "d" does not exist in the object.'
119
- );
120
- });
121
-
122
- it('should allow null values', () => {
123
- const obj = { a: 1, b: null, c: 3 };
124
- expect(got(obj, 'b')).toBeNull();
125
- });
126
-
127
- it('should throw on undefined values', () => {
128
- const obj = { a: 1, b: undefined, c: 3 };
129
- expect(() => got(obj, 'b')).toThrow('Value at key "b" is undefined.');
130
- });
131
- });
132
-
133
- describe('custom error messages', () => {
134
- it('should use custom error message when provided', () => {
135
- const obj = { a: 1, b: 2, c: 3 };
136
- const key = 'd';
137
- expect(() => got(obj, key as keyof typeof obj, `Failed to find ${key}`)).toThrow(
138
- 'Failed to find d'
139
- );
140
- });
141
- });
142
- });
143
- ```
144
-
145
- The key changes:
146
-
147
- 1. Updated documentation to clarify that only `undefined` values throw
148
- 2. Added examples showing that `null` is now a valid value
149
- 3. Updated tests to verify `null` values are allowed
150
- 4. Renamed test cases to reflect the new behavior
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "get-or-throw",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "A convenience function for safely getting values from dynamic objects and arrays",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",