@bedrockio/yada 1.5.2 → 1.6.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 1.6.1
2
+
3
+ - Fixed empty string not allowed when enum provided.
4
+ - Some development version bumps.
5
+
6
+ ## 1.6.0
7
+
8
+ - Make `expandDotSyntax` option default and rename inverse option to
9
+ `preserveKeys`.
10
+
1
11
  ## 1.5.2
2
12
 
3
13
  - Removed boolean requried fields for further schema adherence.
@@ -7,6 +7,7 @@ exports.default = void 0;
7
7
  exports.isSchema = isSchema;
8
8
  var _lodash = require("lodash");
9
9
  var _errors = require("./errors");
10
+ var _utils = require("./utils");
10
11
  const INITIAL_TYPES = ['default', 'required', 'type', 'transform', 'empty'];
11
12
  const REQUIRED_TYPES = ['default', 'required', 'missing'];
12
13
  function isSchema(arg) {
@@ -351,6 +352,9 @@ class Schema {
351
352
  return this.clone({
352
353
  enum: set
353
354
  }).assert('enum', async (val, options) => {
355
+ if (val === '' && (0, _utils.canAllowEmptyString)(options)) {
356
+ return;
357
+ }
354
358
  if (val !== undefined) {
355
359
  let captured = [];
356
360
  for (let el of set) {
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.ValidationError = exports.TypeError = exports.LocalizedError = exports.FormatError = exports.FieldError = exports.ElementError = exports.AssertionError = exports.ArrayError = exports.AllowedError = void 0;
7
7
  exports.isSchemaError = isSchemaError;
8
- var _messages = require("./messages");
9
8
  var _localization = require("./localization");
9
+ var _messages = require("./messages");
10
10
  class LocalizedError extends Error {
11
11
  constructor(message, values = {}) {
12
12
  super((0, _localization.localize)(message, values));
package/dist/cjs/index.js CHANGED
@@ -80,19 +80,19 @@ Object.defineProperty(exports, "useLocalizer", {
80
80
  return _localization.useLocalizer;
81
81
  }
82
82
  });
83
- var _string = _interopRequireDefault(require("./string"));
84
- var _number = _interopRequireDefault(require("./number"));
83
+ var _Schema = _interopRequireWildcard(require("./Schema"));
84
+ var _array = _interopRequireDefault(require("./array"));
85
85
  var _boolean = _interopRequireDefault(require("./boolean"));
86
86
  var _date = _interopRequireDefault(require("./date"));
87
+ var _errors = require("./errors");
88
+ var _localization = require("./localization");
89
+ var _number = _interopRequireDefault(require("./number"));
87
90
  var _object = _interopRequireDefault(require("./object"));
88
- var _array = _interopRequireDefault(require("./array"));
91
+ var _string = _interopRequireDefault(require("./string"));
89
92
  var _tuple = _interopRequireDefault(require("./tuple"));
90
- var _Schema = _interopRequireWildcard(require("./Schema"));
91
- var _localization = require("./localization");
92
- var _errors = require("./errors");
93
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
93
94
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
94
95
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
95
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
96
96
  /**
97
97
  * Accepts anything.
98
98
  */
@@ -5,12 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = _default;
7
7
  var _lodash = require("lodash");
8
+ var _Schema = _interopRequireWildcard(require("./Schema"));
8
9
  var _TypeSchema = _interopRequireDefault(require("./TypeSchema"));
9
10
  var _errors = require("./errors");
10
- var _Schema = _interopRequireWildcard(require("./Schema"));
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
12
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
13
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
14
  const APPEND_ASSERTION_TYPES = ['required', 'type', 'custom'];
15
15
 
16
16
  /**
@@ -33,12 +33,12 @@ class ObjectSchema extends _TypeSchema.default {
33
33
  fields,
34
34
  stripUnknown,
35
35
  stripEmpty,
36
- expandDotSyntax
36
+ preserveKeys
37
37
  } = options;
38
38
  if (obj) {
39
39
  const result = {};
40
- if (expandDotSyntax) {
41
- obj = expandDotProperties(obj);
40
+ if (!preserveKeys) {
41
+ obj = expandKeys(obj);
42
42
  }
43
43
  for (let key of Object.keys(obj)) {
44
44
  const value = obj[key];
@@ -259,6 +259,20 @@ class ObjectSchema extends _TypeSchema.default {
259
259
  return schema;
260
260
  }
261
261
 
262
+ /**
263
+ * `stripEmpty` - Removes properties that are empty strings.
264
+ * `stripUnknown` - Removes properties not in the schema.
265
+ * `preserveKeys` - Prevents expansion of "flat" keys using dot syntax.
266
+ *
267
+ * @param {Object} [options]
268
+ * @param {boolean} [options.stripEmpty]
269
+ * @param {boolean} [options.stripUnknown]
270
+ * @param {boolean} [options.preserveKeys]
271
+ */
272
+ options(options) {
273
+ return super.options(options);
274
+ }
275
+
262
276
  // Private
263
277
 
264
278
  toJSON(extra) {
@@ -283,23 +297,14 @@ class ObjectSchema extends _TypeSchema.default {
283
297
  };
284
298
  }
285
299
  }
286
- function expandDotProperties(obj) {
287
- const result = {};
288
- for (let [key, val] of Object.entries(obj || {})) {
289
- const split = key.split('.');
290
- if (split.length > 1) {
291
- let node = result;
292
- for (let i = 0; i < split.length; i++) {
293
- const token = split[i];
294
- if (i === split.length - 1) {
295
- node[token] = val;
296
- } else {
297
- node[token] = {};
298
- }
299
- node = node[token];
300
- }
301
- } else {
302
- result[key] = val;
300
+ function expandKeys(obj) {
301
+ const result = {
302
+ ...obj
303
+ };
304
+ for (let [key, value] of Object.entries(result)) {
305
+ if (key.includes('.')) {
306
+ delete result[key];
307
+ (0, _lodash.set)(result, key, value);
303
308
  }
304
309
  }
305
310
  return result;
@@ -8,6 +8,7 @@ var _validator = _interopRequireDefault(require("validator"));
8
8
  var _TypeSchema = _interopRequireDefault(require("./TypeSchema"));
9
9
  var _errors = require("./errors");
10
10
  var _password = require("./password");
11
+ var _utils = require("./utils");
11
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
13
  const SLUG_REG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
13
14
  const PHONE_REG = /^\+\d{1,3}\d{3,14}$/;
@@ -31,11 +32,7 @@ class StringSchema extends _TypeSchema.default {
31
32
  return val;
32
33
  });
33
34
  this.assert('empty', (val, options) => {
34
- const {
35
- required,
36
- allowEmpty
37
- } = options;
38
- if (val === '' && (required || allowEmpty === false)) {
35
+ if (val === '' && !(0, _utils.canAllowEmptyString)(options)) {
39
36
  throw new _errors.LocalizedError('Value is required.');
40
37
  }
41
38
  return val;
@@ -411,10 +408,7 @@ class StringSchema extends _TypeSchema.default {
411
408
  return this.clone({
412
409
  format: name
413
410
  }).assert('format', function (val, options) {
414
- const {
415
- allowEmpty
416
- } = options;
417
- if (val === '' && allowEmpty !== false) {
411
+ if (val === '' && (0, _utils.canAllowEmptyString)(options)) {
418
412
  return;
419
413
  }
420
414
  fn(val, options);
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.canAllowEmptyString = canAllowEmptyString;
7
+ function canAllowEmptyString(options) {
8
+ const {
9
+ type,
10
+ required,
11
+ allowEmpty
12
+ } = options;
13
+ return type === 'string' && !required && allowEmpty !== false;
14
+ }
package/eslint.config.js CHANGED
@@ -1,3 +1,3 @@
1
- import { jest, recommended, nodeImports } from '@bedrockio/eslint-plugin';
1
+ import { jest, nodeImports, recommended } from '@bedrockio/eslint-plugin';
2
2
 
3
3
  export default [jest, recommended, nodeImports];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/yada",
3
- "version": "1.5.2",
3
+ "version": "1.6.1",
4
4
  "description": "Validation library inspired by Joi.",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -24,12 +24,12 @@
24
24
  "@babel/cli": "^7.20.7",
25
25
  "@babel/core": "^7.20.12",
26
26
  "@babel/preset-env": "^7.20.2",
27
- "@bedrockio/eslint-plugin": "^1.1.7",
28
- "@bedrockio/prettier-config": "^1.0.2",
27
+ "@bedrockio/eslint-plugin": "^1.2.2",
28
+ "@bedrockio/prettier-config": "^1.1.1",
29
29
  "babel-plugin-add-module-exports": "^1.0.4",
30
- "eslint": "^9.19.0",
31
- "jest": "^29.6.2",
32
- "prettier": "^3.4.2",
30
+ "eslint": "^9.36.0",
31
+ "jest": "^30.1.3",
32
+ "prettier": "^3.6.2",
33
33
  "typescript": "^5.7.2"
34
34
  },
35
35
  "prettier": "@bedrockio/prettier-config",
package/src/Schema.js CHANGED
@@ -1,14 +1,16 @@
1
1
  import { omit, uniqBy } from 'lodash';
2
2
 
3
3
  import {
4
- TypeError,
5
- FormatError,
6
4
  AllowedError,
7
5
  AssertionError,
6
+ FormatError,
8
7
  LocalizedError,
8
+ TypeError,
9
9
  ValidationError,
10
10
  } from './errors';
11
11
 
12
+ import { canAllowEmptyString } from './utils';
13
+
12
14
  const INITIAL_TYPES = ['default', 'required', 'type', 'transform', 'empty'];
13
15
  const REQUIRED_TYPES = ['default', 'required', 'missing'];
14
16
 
@@ -329,6 +331,9 @@ export default class Schema {
329
331
  set = set[0];
330
332
  }
331
333
  return this.clone({ enum: set }).assert('enum', async (val, options) => {
334
+ if (val === '' && canAllowEmptyString(options)) {
335
+ return;
336
+ }
332
337
  if (val !== undefined) {
333
338
  let captured = [];
334
339
 
package/src/errors.js CHANGED
@@ -1,5 +1,5 @@
1
- import { getFullMessage } from './messages';
2
1
  import { localize } from './localization';
2
+ import { getFullMessage } from './messages';
3
3
 
4
4
  export class LocalizedError extends Error {
5
5
  constructor(message, values = {}) {
package/src/index.js CHANGED
@@ -1,17 +1,15 @@
1
- import string from './string';
2
- import number from './number';
1
+ import Schema from './Schema';
2
+ import { isSchema } from './Schema';
3
+ import array from './array';
3
4
  import boolean from './boolean';
4
5
  import date from './date';
5
- import object from './object';
6
- import array from './array';
7
- import tuple from './tuple';
8
-
9
- import Schema from './Schema';
10
- import { useLocalizer, getLocalizedMessages } from './localization';
11
6
  import { LocalizedError } from './errors';
12
-
13
- import { isSchema } from './Schema';
14
7
  import { isSchemaError } from './errors';
8
+ import { getLocalizedMessages, useLocalizer } from './localization';
9
+ import number from './number';
10
+ import object from './object';
11
+ import string from './string';
12
+ import tuple from './tuple';
15
13
 
16
14
  /**
17
15
  * Accepts anything.
@@ -43,22 +41,22 @@ function custom(fn) {
43
41
  }
44
42
 
45
43
  export {
44
+ LocalizedError,
45
+ allow,
46
+ any,
46
47
  array,
47
48
  boolean,
49
+ custom,
48
50
  date,
51
+ getLocalizedMessages,
52
+ isSchema,
53
+ isSchemaError,
49
54
  number,
50
55
  object,
56
+ reject,
51
57
  string,
52
58
  tuple,
53
- any,
54
- allow,
55
- reject,
56
- custom,
57
- isSchema,
58
- isSchemaError,
59
59
  useLocalizer,
60
- getLocalizedMessages,
61
- LocalizedError,
62
60
  };
63
61
 
64
62
  export default {
package/src/object.js CHANGED
@@ -1,8 +1,8 @@
1
- import { set, pick, omit } from 'lodash';
1
+ import { omit, pick, set } from 'lodash';
2
2
 
3
+ import Schema, { isSchema } from './Schema';
3
4
  import TypeSchema from './TypeSchema';
4
5
  import { FieldError, LocalizedError } from './errors';
5
- import Schema, { isSchema } from './Schema';
6
6
 
7
7
  const APPEND_ASSERTION_TYPES = ['required', 'type', 'custom'];
8
8
 
@@ -23,11 +23,11 @@ class ObjectSchema extends TypeSchema {
23
23
  }
24
24
  });
25
25
  this.transform((obj, options) => {
26
- const { fields, stripUnknown, stripEmpty, expandDotSyntax } = options;
26
+ const { fields, stripUnknown, stripEmpty, preserveKeys } = options;
27
27
  if (obj) {
28
28
  const result = {};
29
- if (expandDotSyntax) {
30
- obj = expandDotProperties(obj);
29
+ if (!preserveKeys) {
30
+ obj = expandKeys(obj);
31
31
  }
32
32
  for (let key of Object.keys(obj)) {
33
33
  const value = obj[key];
@@ -250,6 +250,20 @@ class ObjectSchema extends TypeSchema {
250
250
  return schema;
251
251
  }
252
252
 
253
+ /**
254
+ * `stripEmpty` - Removes properties that are empty strings.
255
+ * `stripUnknown` - Removes properties not in the schema.
256
+ * `preserveKeys` - Prevents expansion of "flat" keys using dot syntax.
257
+ *
258
+ * @param {Object} [options]
259
+ * @param {boolean} [options.stripEmpty]
260
+ * @param {boolean} [options.stripUnknown]
261
+ * @param {boolean} [options.preserveKeys]
262
+ */
263
+ options(options) {
264
+ return super.options(options);
265
+ }
266
+
253
267
  // Private
254
268
 
255
269
  toJSON(extra) {
@@ -274,23 +288,12 @@ class ObjectSchema extends TypeSchema {
274
288
  }
275
289
  }
276
290
 
277
- function expandDotProperties(obj) {
278
- const result = {};
279
- for (let [key, val] of Object.entries(obj || {})) {
280
- const split = key.split('.');
281
- if (split.length > 1) {
282
- let node = result;
283
- for (let i = 0; i < split.length; i++) {
284
- const token = split[i];
285
- if (i === split.length - 1) {
286
- node[token] = val;
287
- } else {
288
- node[token] = {};
289
- }
290
- node = node[token];
291
- }
292
- } else {
293
- result[key] = val;
291
+ function expandKeys(obj) {
292
+ const result = { ...obj };
293
+ for (let [key, value] of Object.entries(result)) {
294
+ if (key.includes('.')) {
295
+ delete result[key];
296
+ set(result, key, value);
294
297
  }
295
298
  }
296
299
  return result;
package/src/string.js CHANGED
@@ -2,15 +2,18 @@ import validator from 'validator';
2
2
 
3
3
  import TypeSchema from './TypeSchema';
4
4
  import { LocalizedError } from './errors';
5
+
5
6
  import {
7
+ getPasswordOptions,
6
8
  validateLength,
7
9
  validateLowercase,
8
- validateUppercase,
9
10
  validateNumbers,
10
11
  validateSymbols,
11
- getPasswordOptions,
12
+ validateUppercase,
12
13
  } from './password';
13
14
 
15
+ import { canAllowEmptyString } from './utils';
16
+
14
17
  const SLUG_REG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
15
18
  const PHONE_REG = /^\+\d{1,3}\d{3,14}$/;
16
19
  const NANP_REG = /^\+1[2-9]\d{2}[2-9]\d{6}$/;
@@ -37,8 +40,7 @@ class StringSchema extends TypeSchema {
37
40
  return val;
38
41
  });
39
42
  this.assert('empty', (val, options) => {
40
- const { required, allowEmpty } = options;
41
- if (val === '' && (required || allowEmpty === false)) {
43
+ if (val === '' && !canAllowEmptyString(options)) {
42
44
  throw new LocalizedError('Value is required.');
43
45
  }
44
46
  return val;
@@ -429,8 +431,7 @@ class StringSchema extends TypeSchema {
429
431
  return this.clone({ format: name }).assert(
430
432
  'format',
431
433
  function (val, options) {
432
- const { allowEmpty } = options;
433
- if (val === '' && allowEmpty !== false) {
434
+ if (val === '' && canAllowEmptyString(options)) {
434
435
  return;
435
436
  }
436
437
  fn(val, options);
package/src/utils.js ADDED
@@ -0,0 +1,4 @@
1
+ export function canAllowEmptyString(options) {
2
+ const { type, required, allowEmpty } = options;
3
+ return type === 'string' && !required && allowEmpty !== false;
4
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../src/Schema.js"],"names":[],"mappings":"AAcA,kDAEC;AAED;IACE,uBAGC;IAFC,kBAAoB;IACpB,SAAgB;IAKlB;;OAEG;IACH,YAFa,IAAI,CAQhB;IAED;;;OAGG;IACH,mBAFa,IAAI,CAShB;IAED;;;;OAIG;IACH,sBAFa,IAAI,CAShB;IAED;;;;OAIG;IACH,uBAFa,IAAI,CAShB;IAED;;;;OAIG;IACH,mBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,sBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,uBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,YAFa,IAAI,CAIhB;IAED;;OAEG;IACH,uBAFa,IAAI,CAIhB;IAED;;OAEG;IACH,gBAFa,IAAI,CAShB;IAED;;OAEG;IACH,+BAFa,IAAI,CAMhB;IAED;;OAEG;IACH,uBAFa,IAAI,CAIhB;IAED,iDAwCC;IAED;;OAEG;IACH,kBAFa,IAAI,CAOhB;IAED;;;OAGG;IACH,qBAFa,MAAM,CAMlB;IAED;;;;;OAKG;IACH,yBAWC;IAED;;;OAGG;IACH,gCAEC;IAED;;MAOC;IAED;;;;MASC;IAED;;MAOC;IAED,eAsCC;IAED,4BAMC;IAED,kBAEC;IAED,YAGC;IAID;;OAEG;IACH,kCAFa,IAAI,CAmDhB;IAED;;OAEG;IACH,4BAFa,IAAI,CAUhB;IAED,oCAKC;IAED,gEAQC;IAED;;OAEG;IACH,oBAFa,IAAI,CAShB;IAED,gCAGC;IAED,qEAYC;CACF"}
1
+ {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../src/Schema.js"],"names":[],"mappings":"AAgBA,kDAEC;AAED;IACE,uBAGC;IAFC,kBAAoB;IACpB,SAAgB;IAKlB;;OAEG;IACH,YAFa,IAAI,CAQhB;IAED;;;OAGG;IACH,mBAFa,IAAI,CAShB;IAED;;;;OAIG;IACH,sBAFa,IAAI,CAShB;IAED;;;;OAIG;IACH,uBAFa,IAAI,CAShB;IAED;;;;OAIG;IACH,mBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,sBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,uBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,YAFa,IAAI,CAIhB;IAED;;OAEG;IACH,uBAFa,IAAI,CAIhB;IAED;;OAEG;IACH,gBAFa,IAAI,CAShB;IAED;;OAEG;IACH,+BAFa,IAAI,CAMhB;IAED;;OAEG;IACH,uBAFa,IAAI,CAIhB;IAED,iDAwCC;IAED;;OAEG;IACH,kBAFa,IAAI,CAOhB;IAED;;;OAGG;IACH,qBAFa,MAAM,CAMlB;IAED;;;;;OAKG;IACH,yBAWC;IAED;;;OAGG;IACH,gCAEC;IAED;;MAOC;IAED;;;;MASC;IAED;;MAOC;IAED,eAsCC;IAED,4BAMC;IAED,kBAEC;IAED,YAGC;IAID;;OAEG;IACH,kCAFa,IAAI,CAsDhB;IAED;;OAEG;IACH,4BAFa,IAAI,CAUhB;IAED,oCAKC;IAED,gEAQC;IAED;;OAEG;IACH,oBAFa,IAAI,CAShB;IAED,gCAGC;IAED,qEAYC;CACF"}
package/types/index.d.ts CHANGED
@@ -17,35 +17,35 @@ declare namespace _default {
17
17
  export { LocalizedError };
18
18
  }
19
19
  export default _default;
20
- import array from './array';
21
- import boolean from './boolean';
22
- import date from './date';
23
- import number from './number';
24
- import object from './object';
25
- import string from './string';
26
- import tuple from './tuple';
27
- /**
28
- * Accepts anything.
29
- */
30
- export function any(): Schema;
20
+ import { LocalizedError } from './errors';
31
21
  /**
32
22
  * Accept values or schemas. [Link](https://github.com/bedrockio/yada#allow)
33
23
  */
34
24
  export function allow(...args: any[]): Schema;
35
25
  /**
36
- * Reject values or schemas. [Link](https://github.com/bedrockio/yada#reject)
26
+ * Accepts anything.
37
27
  */
38
- export function reject(...args: any[]): Schema;
28
+ export function any(): Schema;
29
+ import array from './array';
30
+ import boolean from './boolean';
39
31
  /**
40
32
  * Validate by a custom function. [Link](https://github.com/bedrockio/yada#custom)
41
33
  * @param {Function} fn
42
34
  */
43
35
  export function custom(fn: Function): Schema;
36
+ import date from './date';
37
+ import { getLocalizedMessages } from './localization';
44
38
  import { isSchema } from './Schema';
45
39
  import { isSchemaError } from './errors';
40
+ import number from './number';
41
+ import object from './object';
42
+ /**
43
+ * Reject values or schemas. [Link](https://github.com/bedrockio/yada#reject)
44
+ */
45
+ export function reject(...args: any[]): Schema;
46
+ import string from './string';
47
+ import tuple from './tuple';
46
48
  import { useLocalizer } from './localization';
47
- import { getLocalizedMessages } from './localization';
48
- import { LocalizedError } from './errors';
49
49
  import Schema from './Schema';
50
- export { array, boolean, date, number, object, string, tuple, isSchema, isSchemaError, useLocalizer, getLocalizedMessages, LocalizedError };
50
+ export { LocalizedError, array, boolean, date, getLocalizedMessages, isSchema, isSchemaError, number, object, string, tuple, useLocalizer };
51
51
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;kBAKkB,SAAS;oBAHP,WAAW;iBACd,QAAQ;mBAFN,UAAU;mBAGV,UAAU;mBAJV,UAAU;kBAMX,SAAS;AAS3B;;GAEG;AACH,8BAEC;AAED;;GAEG;AACH,8CAEC;AAED;;GAEG;AACH,+CAEC;AAED;;;GAGG;AACH,6CAEC;yBA9BwB,UAAU;8BACL,UAAU;6BAJW,gBAAgB;qCAAhB,gBAAgB;+BACpC,UAAU;mBAFtB,UAAU"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;+BAK+B,UAAU;AAezC;;GAEG;AACH,8CAEC;AAZD;;GAEG;AACH,8BAEC;kBAhBiB,SAAS;oBACP,WAAW;AA+B/B;;;GAGG;AACH,6CAEC;iBApCgB,QAAQ;qCAG0B,gBAAgB;yBAN1C,UAAU;8BAKL,UAAU;mBAErB,UAAU;mBACV,UAAU;AAkB7B;;GAEG;AACH,+CAEC;mBAtBkB,UAAU;kBACX,SAAS;6BAJwB,gBAAgB;mBAPhD,UAAU"}
package/types/object.d.ts CHANGED
@@ -71,6 +71,21 @@ declare class ObjectSchema extends TypeSchema {
71
71
  * @param {SchemaMap|Schema} arg Object or schema to append.
72
72
  */
73
73
  append(arg: SchemaMap | Schema): ObjectSchema;
74
+ /**
75
+ * `stripEmpty` - Removes properties that are empty strings.
76
+ * `stripUnknown` - Removes properties not in the schema.
77
+ * `preserveKeys` - Prevents expansion of "flat" keys using dot syntax.
78
+ *
79
+ * @param {Object} [options]
80
+ * @param {boolean} [options.stripEmpty]
81
+ * @param {boolean} [options.stripUnknown]
82
+ * @param {boolean} [options.preserveKeys]
83
+ */
84
+ options(options?: {
85
+ stripEmpty?: boolean;
86
+ stripUnknown?: boolean;
87
+ preserveKeys?: boolean;
88
+ }): this;
74
89
  }
75
90
  import Schema from './Schema';
76
91
  import TypeSchema from './TypeSchema';
@@ -1 +1 @@
1
- {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.js"],"names":[],"mappings":"AA4TA;;;;;;GAMG;AACH,uCAJW,SAAS,gBAQnB;wBA9TY;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,EAAE;AAD3C;;GAEG;AAEH;IACE,uBAGC;IAED,cA8EC;IAED;;;;;;OAMG;IACH,WAFW,MAAM,GAAC,KAAK,CAAC,MAAM,CAAC,OAsB9B;IAED;;;;;;OAMG;IACH,cAFW,MAAM,GAAC,KAAK,CAAC,MAAM,CAAC,OAY9B;IAED;;;;OAIG;IACH,gBAFc,MAAM,EAAA,gBASnB;IAED;;;;OAIG;IACH,gBAFc,MAAM,EAAA,gBASnB;IAED;;;;;;;OAOG;IACH,mBAHc,MAAM,EAAA,gBAmBnB;IAED;;;;;;OAMG;IACH,cAEC;IAED;;;;;;;;;OASG;IACH,YAFW,SAAS,GAAC,MAAM,gBA+B1B;CAwBF;mBA9QgC,UAAU;uBAFpB,cAAc"}
1
+ {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.js"],"names":[],"mappings":"AA+TA;;;;;;GAMG;AACH,uCAJW,SAAS,gBAQnB;wBAjUY;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,EAAE;AAD3C;;GAEG;AAEH;IACE,uBAGC;IAED,cA8EC;IAED;;;;;;OAMG;IACH,WAFW,MAAM,GAAC,KAAK,CAAC,MAAM,CAAC,OAsB9B;IAED;;;;;;OAMG;IACH,cAFW,MAAM,GAAC,KAAK,CAAC,MAAM,CAAC,OAY9B;IAED;;;;OAIG;IACH,gBAFc,MAAM,EAAA,gBASnB;IAED;;;;OAIG;IACH,gBAFc,MAAM,EAAA,gBASnB;IAED;;;;;;;OAOG;IACH,mBAHc,MAAM,EAAA,gBAmBnB;IAED;;;;;;OAMG;IACH,cAEC;IAED;;;;;;;;;OASG;IACH,YAFW,SAAS,GAAC,MAAM,gBA+B1B;IAED;;;;;;;;;OASG;IACH,kBAJG;QAA0B,UAAU,GAA5B,OAAO;QACW,YAAY,GAA9B,OAAO;QACW,YAAY,GAA9B,OAAO;KAAwB,QAIzC;CAwBF;mBA9RgC,UAAU;uBACpB,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.js"],"names":[],"mappings":"AAwcA;;GAEG;AACH,iDAEC;AArbD;IACE,cAoBC;IAED;;OAEG;IACH,YAFa,IAAI,CAQhB;IAED;;OAEG;IACH,eAFW,MAAM,QAUhB;IAED;;OAEG;IACH,YAFW,MAAM,QAUhB;IAED;;OAEG;IACH,YAFW,MAAM,QAUhB;IAED,aAIC;IAED;;OAEG;IACH,mBAFW,OAAO,QAYjB;IAED;;OAEG;IACH,mBAFW,OAAO,QAYjB;IAED;;OAEG;IACH,WAFW,MAAM,QAahB;IAED,cAMC;IAED,uBASC;IAED,YAMC;IAED,YAMC;IAED,aAMC;IAED,cAMC;IAED;;;OAGG;IACH,iBAFG;QAA0B,OAAO,GAAzB,OAAO;KAAmB,QAQpC;IAED,mBAMC;IAED,WAMC;IAED,gBAMC;IAED,eAMC;IAED,YAMC;IAED,aAOC;IAED,eAMC;IAED;;OAEG;IACH,oBAFW,MAAM,QAQhB;IAED,gBAMC;IAED;;;;;;;OAOG;IACH,mBANG;QAAyB,SAAS,GAA1B,MAAM;QACW,UAAU,GAA3B,MAAM;QACW,UAAU,GAA3B,MAAM;QACW,YAAY,GAA7B,MAAM;QACW,YAAY,GAA7B,MAAM;KAAwB,QA+BxC;IAED;;;;;;;;;;;OAWG;IACH,cAVG;QAA0B,gBAAgB,GAAlC,OAAO;QACW,sBAAsB,GAAxC,OAAO;QACW,YAAY,GAA9B,OAAO;QACW,YAAY,GAA9B,OAAO;QACW,4BAA4B,GAA9C,OAAO;QACW,eAAe,GAAjC,OAAO;QACW,sBAAsB,GAAxC,OAAO;QACW,eAAe,GAAjC,OAAO;QACY,SAAS,GAA5B,MAAM,EAAE;KAAqB,QAQvC;IAED;;;;;;;;OAQG;IACH,iBAPG;QAA0B,WAAW,GAA7B,OAAO;QACW,iBAAiB,GAAnC,OAAO;QACW,kBAAkB,GAApC,OAAO;QACW,iBAAiB,GAAnC,OAAO;QACW,cAAc,GAAhC,OAAO;QACW,iBAAiB,GAAnC,OAAO;KAAmC,QAQpD;IAED;;OAEG;IACH,eAFW,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,QAQ3B;IAED,YAMC;IAED,YAMC;IAED,cAMC;IAED,cAMC;IAED;;;;;;;;;;;OAWG;IACH,iBAMC;IAED,iCAWC;CAgBF;uBApcsB,cAAc"}
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.js"],"names":[],"mappings":"AAycA;;GAEG;AACH,iDAEC;AAnbD;IACE,cAmBC;IAED;;OAEG;IACH,YAFa,IAAI,CAQhB;IAED;;OAEG;IACH,eAFW,MAAM,QAUhB;IAED;;OAEG;IACH,YAFW,MAAM,QAUhB;IAED;;OAEG;IACH,YAFW,MAAM,QAUhB;IAED,aAIC;IAED;;OAEG;IACH,mBAFW,OAAO,QAYjB;IAED;;OAEG;IACH,mBAFW,OAAO,QAYjB;IAED;;OAEG;IACH,WAFW,MAAM,QAahB;IAED,cAMC;IAED,uBASC;IAED,YAMC;IAED,YAMC;IAED,aAMC;IAED,cAMC;IAED;;;OAGG;IACH,iBAFG;QAA0B,OAAO,GAAzB,OAAO;KAAmB,QAQpC;IAED,mBAMC;IAED,WAMC;IAED,gBAMC;IAED,eAMC;IAED,YAMC;IAED,aAOC;IAED,eAMC;IAED;;OAEG;IACH,oBAFW,MAAM,QAQhB;IAED,gBAMC;IAED;;;;;;;OAOG;IACH,mBANG;QAAyB,SAAS,GAA1B,MAAM;QACW,UAAU,GAA3B,MAAM;QACW,UAAU,GAA3B,MAAM;QACW,YAAY,GAA7B,MAAM;QACW,YAAY,GAA7B,MAAM;KAAwB,QA+BxC;IAED;;;;;;;;;;;OAWG;IACH,cAVG;QAA0B,gBAAgB,GAAlC,OAAO;QACW,sBAAsB,GAAxC,OAAO;QACW,YAAY,GAA9B,OAAO;QACW,YAAY,GAA9B,OAAO;QACW,4BAA4B,GAA9C,OAAO;QACW,eAAe,GAAjC,OAAO;QACW,sBAAsB,GAAxC,OAAO;QACW,eAAe,GAAjC,OAAO;QACY,SAAS,GAA5B,MAAM,EAAE;KAAqB,QAQvC;IAED;;;;;;;;OAQG;IACH,iBAPG;QAA0B,WAAW,GAA7B,OAAO;QACW,iBAAiB,GAAnC,OAAO;QACW,kBAAkB,GAApC,OAAO;QACW,iBAAiB,GAAnC,OAAO;QACW,cAAc,GAAhC,OAAO;QACW,iBAAiB,GAAnC,OAAO;KAAmC,QAQpD;IAED;;OAEG;IACH,eAFW,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,QAQ3B;IAED,YAMC;IAED,YAMC;IAED,cAMC;IAED,cAMC;IAED;;;;;;;;;;;OAWG;IACH,iBAMC;IAED,iCAUC;CAgBF;uBArcsB,cAAc"}
package/types/utils.d.ts CHANGED
@@ -1,5 +1,2 @@
1
- export function pick(obj: any, keys: any): {};
2
- export function omit(obj: any, keys: any): {};
3
- export { isSchema } from "./Schema";
4
- export { isSchemaError } from "./errors";
1
+ export function canAllowEmptyString(options: any): boolean;
5
2
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.js"],"names":[],"mappings":"AAGA,8CAMC;AAED,8CAQC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.js"],"names":[],"mappings":"AAAA,2DAGC"}