@awesomeness-js/utils 1.2.7 → 1.2.9

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/package.json CHANGED
@@ -1,27 +1,27 @@
1
1
  {
2
- "name": "@awesomeness-js/utils",
3
- "version": "1.2.7",
4
- "description": "Awesomeness - Utils",
5
- "repository": {
6
- "type": "git",
7
- "url": "git+https://github.com/awesomeness-js/utils.git"
8
- },
9
- "scripts": {
10
- "prebuild": "node ./build/build.js",
11
- "build": "tsc && npm run postBuild",
12
- "postBuild": "node ./build/postBuild.js",
13
- "test": "vitest"
14
- },
15
- "type": "module",
16
- "types": "./types/index.d.ts",
17
- "main": "index.js",
18
- "author": "Scott Forte",
19
- "license": "MIT",
20
- "publishConfig": {
21
- "access": "public"
22
- },
23
- "devDependencies": {
24
- "vitest": "^3.0.9",
25
- "chokidar": "^4.0.3"
26
- }
2
+ "name": "@awesomeness-js/utils",
3
+ "version": "1.2.9",
4
+ "description": "Awesomeness - Utils",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/awesomeness-js/utils.git"
8
+ },
9
+ "scripts": {
10
+ "prebuild": "node ./build/build.js",
11
+ "build": "tsc && npm run postBuild",
12
+ "postBuild": "node ./build/postBuild.js",
13
+ "test": "vitest"
14
+ },
15
+ "type": "module",
16
+ "types": "./types/index.d.ts",
17
+ "main": "index.js",
18
+ "author": "Scott Forte",
19
+ "license": "MIT",
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "devDependencies": {
24
+ "vitest": "^3.0.9",
25
+ "chokidar": "^4.0.3"
26
+ }
27
27
  }
@@ -132,7 +132,7 @@ function cleanArray(arr, schema = {}, {
132
132
 
133
133
  if(supposedToBeType === 'object'){
134
134
 
135
- cleanedItem = cleanObject(item, schema.properties, {
135
+ cleanedItem = cleanObject(item, schema.items, {
136
136
  testMode,
137
137
  allOrNothing,
138
138
  path: path ? `${path}.${key}` : key
@@ -257,10 +257,14 @@ function cleanObject(obj, schema, {
257
257
 
258
258
  if(origLength !== keysPassed.length){
259
259
 
260
+ const extraKeys = Object.keys(obj).filter((key) => !keysSchema.includes(key));
261
+
260
262
  throw {
261
263
  name: 'KeyError',
262
264
  message: 'Object contains keys not in schema',
263
- keysPassed,
265
+ keysPassed: Object.keys(obj),
266
+ extraKeys,
267
+ filteredKeys: keysPassed,
264
268
  keysSchema,
265
269
  obj
266
270
  };
@@ -134,6 +134,41 @@ const schemaForArrayOfObjects = {
134
134
  }
135
135
  };
136
136
 
137
+ const versesArray = [
138
+ {
139
+ book: 'GEN',
140
+ chapter: 1,
141
+ verse: 1,
142
+ },
143
+ {
144
+ book: 'PSA',
145
+ chapter: 23,
146
+ verse: 4,
147
+ }
148
+ ];
149
+
150
+ const versesSchema = {
151
+ type: 'array',
152
+ required: true,
153
+ items: {
154
+ type: 'object',
155
+ properties: {
156
+ book: {
157
+ type: 'string',
158
+ required: true
159
+ },
160
+ chapter: {
161
+ type: 'integer',
162
+ required: true
163
+ },
164
+ verse: {
165
+ type: 'integer',
166
+ required: true
167
+ }
168
+ }
169
+ }
170
+ };
171
+
137
172
  test('testStringArray', () => {
138
173
 
139
174
  const x = utils.clean.array(testStringArray, schemaForStrings);
@@ -197,4 +232,12 @@ test('schemaForArrayOfObjects', () => {
197
232
 
198
233
  expect(x).toStrictEqual(arrayOfObjects);
199
234
 
235
+ });
236
+
237
+ test('verses array of objects schema', () => {
238
+
239
+ const x = utils.clean.array(versesArray, versesSchema);
240
+
241
+ expect(x).toStrictEqual(versesArray);
242
+
200
243
  });