decoders 2.9.0 → 2.9.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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/decoders.svg)](https://www.npmjs.com/package/decoders)
4
4
  [![Test Status](https://github.com/nvie/decoders/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/nvie/decoders/actions)
5
- [![Bundle size for decoders](https://pkg-size.dev/badge/bundle/4200)](https://pkg-size.dev/decoders)
5
+ [![Bundle size](https://deno.bundlejs.com/badge?q=decoders@2.9.0&treeshake=[{number,object,optional,string}])](https://bundlejs.com/?q=decoders%402.9.0&treeshake=%5B%7B+number%2Cobject%2Coptional%2Cstring+%7D%5D)
6
6
 
7
7
  Elegant and battle-tested validation library for type-safe input data for TypeScript.
8
8
 
package/dist/index.cjs CHANGED
@@ -1,5 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/lib/utils.ts
2
2
  // @__NO_SIDE_EFFECTS__
3
+ function qty(n, unit) {
4
+ return n === 1 ? `${n} ${unit}` : `${n} ${unit}s`;
5
+ }
6
+ // @__NO_SIDE_EFFECTS__
3
7
  function isNumber(value) {
4
8
  return typeof value === "number";
5
9
  }
@@ -470,7 +474,7 @@ function isNonEmpty(arr) {
470
474
  }
471
475
  // @__NO_SIDE_EFFECTS__
472
476
  function nonEmptyArray(decoder) {
473
- return (/* @__PURE__ */ array(decoder)).refine(isNonEmpty, "Must be non-empty array");
477
+ return (/* @__PURE__ */ array(decoder)).refine(isNonEmpty, "Must have at least 1 item");
474
478
  }
475
479
  var ntuple = /* @__NO_SIDE_EFFECTS__ */ (n) => poja.refine((arr) => arr.length === n, `Must be a ${n}-tuple`);
476
480
  // @__NO_SIDE_EFFECTS__
@@ -507,12 +511,13 @@ function bySizeOptions(options) {
507
511
  const len = _nullishCoalesce(value.length, () => ( value.size));
508
512
  if (typeof value === "string") {
509
513
  if (min2 !== void 0 && len < min2)
510
- return `Too short, must be ${atLeast}${min2} chars`;
514
+ return `Too short, must be ${atLeast}${qty(min2, "char")}`;
511
515
  if (max2 !== void 0 && len > max2)
512
- return `Too long, must be ${atMost}${max2} chars`;
516
+ return `Too long, must be ${atMost}${qty(max2, "char")}`;
513
517
  } else {
514
- if (min2 !== void 0 && len < min2) return `Must have ${atLeast}${min2} items`;
515
- if (max2 !== void 0 && len > max2) return `Must have ${atMost}${max2} items`;
518
+ if (min2 !== void 0 && len < min2)
519
+ return `Must have ${atLeast}${qty(min2, "item")}`;
520
+ if (max2 !== void 0 && len > max2) return `Must have ${atMost}${qty(max2, "item")}`;
516
521
  }
517
522
  return null;
518
523
  };
package/dist/index.js CHANGED
@@ -1,5 +1,9 @@
1
1
  // src/lib/utils.ts
2
2
  // @__NO_SIDE_EFFECTS__
3
+ function qty(n, unit) {
4
+ return n === 1 ? `${n} ${unit}` : `${n} ${unit}s`;
5
+ }
6
+ // @__NO_SIDE_EFFECTS__
3
7
  function isNumber(value) {
4
8
  return typeof value === "number";
5
9
  }
@@ -470,7 +474,7 @@ function isNonEmpty(arr) {
470
474
  }
471
475
  // @__NO_SIDE_EFFECTS__
472
476
  function nonEmptyArray(decoder) {
473
- return (/* @__PURE__ */ array(decoder)).refine(isNonEmpty, "Must be non-empty array");
477
+ return (/* @__PURE__ */ array(decoder)).refine(isNonEmpty, "Must have at least 1 item");
474
478
  }
475
479
  var ntuple = /* @__NO_SIDE_EFFECTS__ */ (n) => poja.refine((arr) => arr.length === n, `Must be a ${n}-tuple`);
476
480
  // @__NO_SIDE_EFFECTS__
@@ -507,12 +511,13 @@ function bySizeOptions(options) {
507
511
  const len = value.length ?? value.size;
508
512
  if (typeof value === "string") {
509
513
  if (min2 !== void 0 && len < min2)
510
- return `Too short, must be ${atLeast}${min2} chars`;
514
+ return `Too short, must be ${atLeast}${qty(min2, "char")}`;
511
515
  if (max2 !== void 0 && len > max2)
512
- return `Too long, must be ${atMost}${max2} chars`;
516
+ return `Too long, must be ${atMost}${qty(max2, "char")}`;
513
517
  } else {
514
- if (min2 !== void 0 && len < min2) return `Must have ${atLeast}${min2} items`;
515
- if (max2 !== void 0 && len > max2) return `Must have ${atMost}${max2} items`;
518
+ if (min2 !== void 0 && len < min2)
519
+ return `Must have ${atLeast}${qty(min2, "item")}`;
520
+ if (max2 !== void 0 && len > max2) return `Must have ${atMost}${qty(max2, "item")}`;
516
521
  }
517
522
  return null;
518
523
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "decoders",
3
- "version": "2.9.0",
3
+ "version": "2.9.1",
4
4
  "description": "Elegant and battle-tested validation library for type-safe input data for TypeScript",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -66,9 +66,9 @@
66
66
  "@release-it/keep-a-changelog": "^7.0.1",
67
67
  "@standard-schema/spec": "^1.1.0",
68
68
  "@vitest/coverage-istanbul": "^4.0.18",
69
- "fast-check": "^4.5.3",
69
+ "fast-check": "^4.6.0",
70
70
  "itertools": "^2.6.0",
71
- "oxlint": "^1.51.0",
71
+ "oxlint": "^1.52.0",
72
72
  "pkg-pr-new": "^0.0.65",
73
73
  "prettier": "^3.8.1",
74
74
  "publint": "^0.3.18",