decoders 2.4.2 → 2.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/dist/index.cjs CHANGED
@@ -709,6 +709,18 @@ var nonEmptyString = regex(/\S/, "Must be non-empty string");
709
709
  function regex(regex2, msg) {
710
710
  return string.refine((s) => regex2.test(s), msg);
711
711
  }
712
+ function startsWith(prefix) {
713
+ return string.refine(
714
+ (s) => s.startsWith(prefix),
715
+ `Must start with '${prefix}'`
716
+ );
717
+ }
718
+ function endsWith(suffix) {
719
+ return string.refine(
720
+ (s) => s.endsWith(suffix),
721
+ `Must end with '${suffix}'`
722
+ );
723
+ }
712
724
  var email = regex(
713
725
  // The almost perfect email regex, taken from https://emailregex.com/
714
726
  /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
@@ -873,4 +885,6 @@ var json = either(
873
885
 
874
886
 
875
887
 
876
- exports.always = always; exports.anyNumber = anyNumber; exports.array = array; exports.bigint = bigint; exports.boolean = boolean; exports.constant = constant; exports.date = date; exports.datelike = datelike; exports.decimal = decimal; exports.define = define; exports.dict = dict; exports.either = either; exports.email = email; exports.enum_ = enum_; exports.err = err; exports.exact = exact; exports.fail = fail; exports.formatInline = formatInline; exports.formatShort = formatShort; exports.hardcoded = hardcoded; exports.hexadecimal = hexadecimal; exports.httpsUrl = httpsUrl; exports.identifier = identifier; exports.inexact = inexact; exports.instanceOf = instanceOf; exports.integer = integer; exports.iso8601 = iso8601; exports.json = json; exports.jsonArray = jsonArray; exports.jsonObject = jsonObject; exports.lazy = lazy; exports.mapping = mapping; exports.maybe = maybe; exports.mixed = mixed; exports.nanoid = nanoid; exports.never = never; exports.nonEmptyArray = nonEmptyArray; exports.nonEmptyString = nonEmptyString; exports.null_ = null_; exports.nullable = nullable; exports.nullish = nullish; exports.number = number; exports.numeric = numeric; exports.object = object; exports.ok = ok; exports.oneOf = oneOf; exports.optional = optional; exports.poja = poja; exports.pojo = pojo; exports.positiveInteger = positiveInteger; exports.positiveNumber = positiveNumber; exports.prep = prep; exports.record = record; exports.regex = regex; exports.select = select; exports.set = set; exports.setFromArray = setFromArray; exports.string = string; exports.taggedUnion = taggedUnion; exports.truthy = truthy; exports.tuple = tuple; exports.undefined_ = undefined_; exports.unknown = unknown; exports.url = url; exports.uuid = uuid; exports.uuidv1 = uuidv1; exports.uuidv4 = uuidv4;
888
+
889
+
890
+ exports.always = always; exports.anyNumber = anyNumber; exports.array = array; exports.bigint = bigint; exports.boolean = boolean; exports.constant = constant; exports.date = date; exports.datelike = datelike; exports.decimal = decimal; exports.define = define; exports.dict = dict; exports.either = either; exports.email = email; exports.endsWith = endsWith; exports.enum_ = enum_; exports.err = err; exports.exact = exact; exports.fail = fail; exports.formatInline = formatInline; exports.formatShort = formatShort; exports.hardcoded = hardcoded; exports.hexadecimal = hexadecimal; exports.httpsUrl = httpsUrl; exports.identifier = identifier; exports.inexact = inexact; exports.instanceOf = instanceOf; exports.integer = integer; exports.iso8601 = iso8601; exports.json = json; exports.jsonArray = jsonArray; exports.jsonObject = jsonObject; exports.lazy = lazy; exports.mapping = mapping; exports.maybe = maybe; exports.mixed = mixed; exports.nanoid = nanoid; exports.never = never; exports.nonEmptyArray = nonEmptyArray; exports.nonEmptyString = nonEmptyString; exports.null_ = null_; exports.nullable = nullable; exports.nullish = nullish; exports.number = number; exports.numeric = numeric; exports.object = object; exports.ok = ok; exports.oneOf = oneOf; exports.optional = optional; exports.poja = poja; exports.pojo = pojo; exports.positiveInteger = positiveInteger; exports.positiveNumber = positiveNumber; exports.prep = prep; exports.record = record; exports.regex = regex; exports.select = select; exports.set = set; exports.setFromArray = setFromArray; exports.startsWith = startsWith; exports.string = string; exports.taggedUnion = taggedUnion; exports.truthy = truthy; exports.tuple = tuple; exports.undefined_ = undefined_; exports.unknown = unknown; exports.url = url; exports.uuid = uuid; exports.uuidv1 = uuidv1; exports.uuidv4 = uuidv4;
package/dist/index.d.cts CHANGED
@@ -476,6 +476,14 @@ declare const nonEmptyString: Decoder<string>;
476
476
  * Accepts and returns strings that match the given regular expression.
477
477
  */
478
478
  declare function regex(regex: RegExp, msg: string): Decoder<string>;
479
+ /**
480
+ * Accepts and returns strings that start with the given prefix.
481
+ */
482
+ declare function startsWith<P extends string>(prefix: P): Decoder<`${P}${string}`>;
483
+ /**
484
+ * Accepts and returns strings that end with the given suffix.
485
+ */
486
+ declare function endsWith<S extends string>(suffix: S): Decoder<`${string}${S}`>;
479
487
  /**
480
488
  * Accepts and returns strings that are syntactically valid email addresses.
481
489
  * (This will not mean that the email address actually exist.)
@@ -592,4 +600,4 @@ declare function taggedUnion<O extends Record<string, Decoder<unknown>>>(field:
592
600
  */
593
601
  declare function select<T, D extends Decoder<unknown>>(scout: Decoder<T>, selectFn: (result: T) => D): Decoder<DecoderType<D>>;
594
602
 
595
- export { type DecodeResult, type Decoder, type DecoderType, type Err, type Formatter, type JSONArray, type JSONObject, type JSONValue, type Ok, type Result, type Scalar, type SizeOptions, always, anyNumber, array, bigint, boolean, constant, date, datelike, decimal, define, dict, either, email, enum_, err, exact, fail, formatInline, formatShort, hardcoded, hexadecimal, httpsUrl, identifier, inexact, instanceOf, integer, iso8601, json, jsonArray, jsonObject, lazy, mapping, maybe, mixed, nanoid, never, nonEmptyArray, nonEmptyString, null_, nullable, nullish, number, numeric, object, ok, oneOf, optional, poja, pojo, positiveInteger, positiveNumber, prep, record, regex, select, set, setFromArray, string, taggedUnion, truthy, tuple, undefined_, unknown, url, uuid, uuidv1, uuidv4 };
603
+ export { type DecodeResult, type Decoder, type DecoderType, type Err, type Formatter, type JSONArray, type JSONObject, type JSONValue, type Ok, type Result, type Scalar, type SizeOptions, always, anyNumber, array, bigint, boolean, constant, date, datelike, decimal, define, dict, either, email, endsWith, enum_, err, exact, fail, formatInline, formatShort, hardcoded, hexadecimal, httpsUrl, identifier, inexact, instanceOf, integer, iso8601, json, jsonArray, jsonObject, lazy, mapping, maybe, mixed, nanoid, never, nonEmptyArray, nonEmptyString, null_, nullable, nullish, number, numeric, object, ok, oneOf, optional, poja, pojo, positiveInteger, positiveNumber, prep, record, regex, select, set, setFromArray, startsWith, string, taggedUnion, truthy, tuple, undefined_, unknown, url, uuid, uuidv1, uuidv4 };
package/dist/index.d.ts CHANGED
@@ -476,6 +476,14 @@ declare const nonEmptyString: Decoder<string>;
476
476
  * Accepts and returns strings that match the given regular expression.
477
477
  */
478
478
  declare function regex(regex: RegExp, msg: string): Decoder<string>;
479
+ /**
480
+ * Accepts and returns strings that start with the given prefix.
481
+ */
482
+ declare function startsWith<P extends string>(prefix: P): Decoder<`${P}${string}`>;
483
+ /**
484
+ * Accepts and returns strings that end with the given suffix.
485
+ */
486
+ declare function endsWith<S extends string>(suffix: S): Decoder<`${string}${S}`>;
479
487
  /**
480
488
  * Accepts and returns strings that are syntactically valid email addresses.
481
489
  * (This will not mean that the email address actually exist.)
@@ -592,4 +600,4 @@ declare function taggedUnion<O extends Record<string, Decoder<unknown>>>(field:
592
600
  */
593
601
  declare function select<T, D extends Decoder<unknown>>(scout: Decoder<T>, selectFn: (result: T) => D): Decoder<DecoderType<D>>;
594
602
 
595
- export { type DecodeResult, type Decoder, type DecoderType, type Err, type Formatter, type JSONArray, type JSONObject, type JSONValue, type Ok, type Result, type Scalar, type SizeOptions, always, anyNumber, array, bigint, boolean, constant, date, datelike, decimal, define, dict, either, email, enum_, err, exact, fail, formatInline, formatShort, hardcoded, hexadecimal, httpsUrl, identifier, inexact, instanceOf, integer, iso8601, json, jsonArray, jsonObject, lazy, mapping, maybe, mixed, nanoid, never, nonEmptyArray, nonEmptyString, null_, nullable, nullish, number, numeric, object, ok, oneOf, optional, poja, pojo, positiveInteger, positiveNumber, prep, record, regex, select, set, setFromArray, string, taggedUnion, truthy, tuple, undefined_, unknown, url, uuid, uuidv1, uuidv4 };
603
+ export { type DecodeResult, type Decoder, type DecoderType, type Err, type Formatter, type JSONArray, type JSONObject, type JSONValue, type Ok, type Result, type Scalar, type SizeOptions, always, anyNumber, array, bigint, boolean, constant, date, datelike, decimal, define, dict, either, email, endsWith, enum_, err, exact, fail, formatInline, formatShort, hardcoded, hexadecimal, httpsUrl, identifier, inexact, instanceOf, integer, iso8601, json, jsonArray, jsonObject, lazy, mapping, maybe, mixed, nanoid, never, nonEmptyArray, nonEmptyString, null_, nullable, nullish, number, numeric, object, ok, oneOf, optional, poja, pojo, positiveInteger, positiveNumber, prep, record, regex, select, set, setFromArray, startsWith, string, taggedUnion, truthy, tuple, undefined_, unknown, url, uuid, uuidv1, uuidv4 };
package/dist/index.js CHANGED
@@ -709,6 +709,18 @@ var nonEmptyString = regex(/\S/, "Must be non-empty string");
709
709
  function regex(regex2, msg) {
710
710
  return string.refine((s) => regex2.test(s), msg);
711
711
  }
712
+ function startsWith(prefix) {
713
+ return string.refine(
714
+ (s) => s.startsWith(prefix),
715
+ `Must start with '${prefix}'`
716
+ );
717
+ }
718
+ function endsWith(suffix) {
719
+ return string.refine(
720
+ (s) => s.endsWith(suffix),
721
+ `Must end with '${suffix}'`
722
+ );
723
+ }
712
724
  var email = regex(
713
725
  // The almost perfect email regex, taken from https://emailregex.com/
714
726
  /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
@@ -819,6 +831,7 @@ export {
819
831
  dict,
820
832
  either,
821
833
  email,
834
+ endsWith,
822
835
  enum_,
823
836
  err,
824
837
  exact,
@@ -863,6 +876,7 @@ export {
863
876
  select,
864
877
  set,
865
878
  setFromArray,
879
+ startsWith,
866
880
  string,
867
881
  taggedUnion,
868
882
  truthy,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "decoders",
3
- "version": "2.4.2",
3
+ "version": "2.5.0",
4
4
  "description": "Elegant and battle-tested validation library for type-safe input data for TypeScript",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -61,7 +61,7 @@
61
61
  "verify"
62
62
  ],
63
63
  "devDependencies": {
64
- "@arethetypeswrong/cli": "^0.15.3",
64
+ "@arethetypeswrong/cli": "^0.16.4",
65
65
  "@release-it/keep-a-changelog": "^5.0.0",
66
66
  "@types/eslint": "^8.56.10",
67
67
  "@typescript-eslint/eslint-plugin": "^7.14.1",
@@ -70,15 +70,15 @@
70
70
  "eslint": "^8.57.0",
71
71
  "eslint-plugin-import": "^2.29.1",
72
72
  "eslint-plugin-simple-import-sort": "^12.1.0",
73
- "fast-check": "^3.19.0",
73
+ "fast-check": "^3.22.0",
74
74
  "itertools": "^2.3.2",
75
- "pkg-pr-new": "^0.0.9",
76
- "prettier": "^3.3.2",
77
- "publint": "^0.2.8",
78
- "release-it": "^17.4.0",
75
+ "pkg-pr-new": "^0.0.24",
76
+ "prettier": "^3.3.3",
77
+ "publint": "^0.2.11",
78
+ "release-it": "^17.6.0",
79
79
  "ts-morph": "^23.0.0",
80
- "tsd": "^0.31.1",
81
- "tsup": "^8.1.0",
80
+ "tsd": "^0.31.2",
81
+ "tsup": "^8.3.0",
82
82
  "typescript": "^5.5.2",
83
83
  "vite-tsconfig-paths": "^4.3.2",
84
84
  "vitest": "^1.6.0"