decoders 2.12.3 → 2.13.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 +12 -1
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +11 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1026,6 +1026,16 @@ var uuidv4 = (
|
|
|
1026
1026
|
// https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random)
|
|
1027
1027
|
/* @__PURE__ */ uuid.refine((value) => value[14] === "4", "Must be uuidv4")
|
|
1028
1028
|
);
|
|
1029
|
+
function isKsuid(value) {
|
|
1030
|
+
return /^[0-9a-z]{27}$/i.test(value) && // Base62 alphabet sorts like ASCII, so the 2^160 - 1 upper bound is a
|
|
1031
|
+
// string comparison
|
|
1032
|
+
value <= "aWgEPTl1tmebfsQzFP4bxwgy80V";
|
|
1033
|
+
}
|
|
1034
|
+
// @__NO_SIDE_EFFECTS__
|
|
1035
|
+
function ksuid(options) {
|
|
1036
|
+
const prefix = _optionalChain([options, 'optionalAccess', _8 => _8.prefix]);
|
|
1037
|
+
return prefix ? (/* @__PURE__ */ startsWith(prefix)).refine((s) => isKsuid(s.slice(prefix.length)), "Must be ksuid") : string.refine(isKsuid, "Must be ksuid");
|
|
1038
|
+
}
|
|
1029
1039
|
var decimal = /* @__PURE__ */ regex(/^[0-9]+$/, "Must only contain digits");
|
|
1030
1040
|
var hexadecimal = /* @__PURE__ */ regex(
|
|
1031
1041
|
/^[0-9a-f]+$/i,
|
|
@@ -1193,6 +1203,7 @@ var json = /* @__PURE__ */ either(
|
|
|
1193
1203
|
|
|
1194
1204
|
|
|
1195
1205
|
|
|
1196
|
-
|
|
1206
|
+
|
|
1207
|
+
exports._annotate = public_annotate; exports.always = always; exports.anyNumber = anyNumber; exports.anything = anything; exports.array = array; exports.between = between; exports.bigint = bigint; exports.boolean = boolean; exports.constant = constant; exports.date = date; exports.dateString = dateString; exports.datelike = datelike; exports.decimal = decimal; exports.define = define; exports.either = either; exports.email = email; exports.endsWith = endsWith; exports.enum_ = enum_; exports.err = err; exports.exact = exact; exports.fail = fail; exports.flexDate = flexDate; exports.formatInline = formatInline; exports.formatShort = formatShort; exports.hexadecimal = hexadecimal; exports.httpsUrl = httpsUrl; exports.identifier = identifier; exports.inexact = inexact; exports.instanceOf = instanceOf; exports.integer = integer; exports.isDate = isDate; exports.isDecoder = isDecoder; exports.isPlainObject = isPlainObject; exports.isPromiseLike = isPromiseLike; exports.iso8601 = iso8601; exports.isoDate = isoDate; exports.isoDateString = isoDateString; exports.json = json; exports.jsonArray = jsonArray; exports.jsonObject = jsonObject; exports.ksuid = ksuid; exports.lazy = lazy; exports.mapping = mapping; exports.max = max; exports.min = min; exports.nanoid = nanoid; exports.natural = natural; exports.never = never; exports.nonEmptyArray = nonEmptyArray; exports.nonEmptyString = nonEmptyString; exports.nonNegativeNumber = nonNegativeNumber; 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.setFromArray = setFromArray; exports.sized = sized; 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.urlString = urlString; exports.uuid = uuid; exports.uuidv1 = uuidv1; exports.uuidv4 = uuidv4;
|
|
1197
1208
|
// istanbul ignore next -- @preserve
|
|
1198
1209
|
// istanbul ignore else -- @preserve
|
package/dist/index.d.cts
CHANGED
|
@@ -645,6 +645,16 @@ declare const uuidv1: Decoder<string>;
|
|
|
645
645
|
* strings.
|
|
646
646
|
*/
|
|
647
647
|
declare const uuidv4: Decoder<string>;
|
|
648
|
+
/**
|
|
649
|
+
* Accepts and returns [KSUID](https://github.com/segmentio/ksuid) strings
|
|
650
|
+
* (K-Sortable Unique IDentifier): 27 base62 chars, encoding a 160-bit value.
|
|
651
|
+
* Optionally, specify a prefix the KSUID must be preceded by, e.g.
|
|
652
|
+
* `ksuid({ prefix: 'msg_' })` accepts `msg_0ujtsYcgvSTl8PAuAdqWYSMnLOv`.
|
|
653
|
+
*/
|
|
654
|
+
declare function ksuid(): Decoder<string>;
|
|
655
|
+
declare function ksuid<P extends string>(options: {
|
|
656
|
+
prefix: P;
|
|
657
|
+
}): Decoder<`${P}${string}`>;
|
|
648
658
|
/**
|
|
649
659
|
* Accepts and returns strings with decimal digits only (base-10).
|
|
650
660
|
* To convert these to numbers, use the `numeric` decoder.
|
|
@@ -733,4 +743,4 @@ declare function isPromiseLike(value: unknown): value is PromiseLike<unknown>;
|
|
|
733
743
|
*/
|
|
734
744
|
declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
735
745
|
|
|
736
|
-
export { type Annotation, type ArrayAnnotation, type DecodeResult, type Decoder, type DecoderType, type Err, type Formatter, type JSONArray, type JSONObject, type JSONValue, type ObjectAnnotation, type Ok, type OpaqueAnnotation, type Relax, type Result, type Scalar, type ScalarAnnotation, type SizeOptions, type Sized, public_annotate as _annotate, always, anyNumber, anything, array, between, bigint, boolean, constant, date, dateString, datelike, decimal, define, either, email, endsWith, enum_, err, exact, fail, flexDate, formatInline, formatShort, hexadecimal, httpsUrl, identifier, inexact, instanceOf, integer, isDate, isDecoder, isPlainObject, isPromiseLike, iso8601, isoDate, isoDateString, json, jsonArray, jsonObject, lazy, mapping, max, min, nanoid, natural, never, nonEmptyArray, nonEmptyString, nonNegativeNumber, null_, nullable, nullish, number, numeric, object, ok, oneOf, optional, poja, pojo, positiveInteger, positiveNumber, prep, record, regex, select, setFromArray, sized, startsWith, string, taggedUnion, truthy, tuple, undefined_, unknown, url, urlString, uuid, uuidv1, uuidv4 };
|
|
746
|
+
export { type Annotation, type ArrayAnnotation, type DecodeResult, type Decoder, type DecoderType, type Err, type Formatter, type JSONArray, type JSONObject, type JSONValue, type ObjectAnnotation, type Ok, type OpaqueAnnotation, type Relax, type Result, type Scalar, type ScalarAnnotation, type SizeOptions, type Sized, public_annotate as _annotate, always, anyNumber, anything, array, between, bigint, boolean, constant, date, dateString, datelike, decimal, define, either, email, endsWith, enum_, err, exact, fail, flexDate, formatInline, formatShort, hexadecimal, httpsUrl, identifier, inexact, instanceOf, integer, isDate, isDecoder, isPlainObject, isPromiseLike, iso8601, isoDate, isoDateString, json, jsonArray, jsonObject, ksuid, lazy, mapping, max, min, nanoid, natural, never, nonEmptyArray, nonEmptyString, nonNegativeNumber, null_, nullable, nullish, number, numeric, object, ok, oneOf, optional, poja, pojo, positiveInteger, positiveNumber, prep, record, regex, select, setFromArray, sized, startsWith, string, taggedUnion, truthy, tuple, undefined_, unknown, url, urlString, uuid, uuidv1, uuidv4 };
|
package/dist/index.d.ts
CHANGED
|
@@ -645,6 +645,16 @@ declare const uuidv1: Decoder<string>;
|
|
|
645
645
|
* strings.
|
|
646
646
|
*/
|
|
647
647
|
declare const uuidv4: Decoder<string>;
|
|
648
|
+
/**
|
|
649
|
+
* Accepts and returns [KSUID](https://github.com/segmentio/ksuid) strings
|
|
650
|
+
* (K-Sortable Unique IDentifier): 27 base62 chars, encoding a 160-bit value.
|
|
651
|
+
* Optionally, specify a prefix the KSUID must be preceded by, e.g.
|
|
652
|
+
* `ksuid({ prefix: 'msg_' })` accepts `msg_0ujtsYcgvSTl8PAuAdqWYSMnLOv`.
|
|
653
|
+
*/
|
|
654
|
+
declare function ksuid(): Decoder<string>;
|
|
655
|
+
declare function ksuid<P extends string>(options: {
|
|
656
|
+
prefix: P;
|
|
657
|
+
}): Decoder<`${P}${string}`>;
|
|
648
658
|
/**
|
|
649
659
|
* Accepts and returns strings with decimal digits only (base-10).
|
|
650
660
|
* To convert these to numbers, use the `numeric` decoder.
|
|
@@ -733,4 +743,4 @@ declare function isPromiseLike(value: unknown): value is PromiseLike<unknown>;
|
|
|
733
743
|
*/
|
|
734
744
|
declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
735
745
|
|
|
736
|
-
export { type Annotation, type ArrayAnnotation, type DecodeResult, type Decoder, type DecoderType, type Err, type Formatter, type JSONArray, type JSONObject, type JSONValue, type ObjectAnnotation, type Ok, type OpaqueAnnotation, type Relax, type Result, type Scalar, type ScalarAnnotation, type SizeOptions, type Sized, public_annotate as _annotate, always, anyNumber, anything, array, between, bigint, boolean, constant, date, dateString, datelike, decimal, define, either, email, endsWith, enum_, err, exact, fail, flexDate, formatInline, formatShort, hexadecimal, httpsUrl, identifier, inexact, instanceOf, integer, isDate, isDecoder, isPlainObject, isPromiseLike, iso8601, isoDate, isoDateString, json, jsonArray, jsonObject, lazy, mapping, max, min, nanoid, natural, never, nonEmptyArray, nonEmptyString, nonNegativeNumber, null_, nullable, nullish, number, numeric, object, ok, oneOf, optional, poja, pojo, positiveInteger, positiveNumber, prep, record, regex, select, setFromArray, sized, startsWith, string, taggedUnion, truthy, tuple, undefined_, unknown, url, urlString, uuid, uuidv1, uuidv4 };
|
|
746
|
+
export { type Annotation, type ArrayAnnotation, type DecodeResult, type Decoder, type DecoderType, type Err, type Formatter, type JSONArray, type JSONObject, type JSONValue, type ObjectAnnotation, type Ok, type OpaqueAnnotation, type Relax, type Result, type Scalar, type ScalarAnnotation, type SizeOptions, type Sized, public_annotate as _annotate, always, anyNumber, anything, array, between, bigint, boolean, constant, date, dateString, datelike, decimal, define, either, email, endsWith, enum_, err, exact, fail, flexDate, formatInline, formatShort, hexadecimal, httpsUrl, identifier, inexact, instanceOf, integer, isDate, isDecoder, isPlainObject, isPromiseLike, iso8601, isoDate, isoDateString, json, jsonArray, jsonObject, ksuid, lazy, mapping, max, min, nanoid, natural, never, nonEmptyArray, nonEmptyString, nonNegativeNumber, null_, nullable, nullish, number, numeric, object, ok, oneOf, optional, poja, pojo, positiveInteger, positiveNumber, prep, record, regex, select, setFromArray, sized, startsWith, string, taggedUnion, truthy, tuple, undefined_, unknown, url, urlString, uuid, uuidv1, uuidv4 };
|
package/dist/index.js
CHANGED
|
@@ -1026,6 +1026,16 @@ var uuidv4 = (
|
|
|
1026
1026
|
// https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random)
|
|
1027
1027
|
/* @__PURE__ */ uuid.refine((value) => value[14] === "4", "Must be uuidv4")
|
|
1028
1028
|
);
|
|
1029
|
+
function isKsuid(value) {
|
|
1030
|
+
return /^[0-9a-z]{27}$/i.test(value) && // Base62 alphabet sorts like ASCII, so the 2^160 - 1 upper bound is a
|
|
1031
|
+
// string comparison
|
|
1032
|
+
value <= "aWgEPTl1tmebfsQzFP4bxwgy80V";
|
|
1033
|
+
}
|
|
1034
|
+
// @__NO_SIDE_EFFECTS__
|
|
1035
|
+
function ksuid(options) {
|
|
1036
|
+
const prefix = options?.prefix;
|
|
1037
|
+
return prefix ? (/* @__PURE__ */ startsWith(prefix)).refine((s) => isKsuid(s.slice(prefix.length)), "Must be ksuid") : string.refine(isKsuid, "Must be ksuid");
|
|
1038
|
+
}
|
|
1029
1039
|
var decimal = /* @__PURE__ */ regex(/^[0-9]+$/, "Must only contain digits");
|
|
1030
1040
|
var hexadecimal = /* @__PURE__ */ regex(
|
|
1031
1041
|
/^[0-9a-f]+$/i,
|
|
@@ -1152,6 +1162,7 @@ export {
|
|
|
1152
1162
|
json,
|
|
1153
1163
|
jsonArray,
|
|
1154
1164
|
jsonObject,
|
|
1165
|
+
ksuid,
|
|
1155
1166
|
lazy,
|
|
1156
1167
|
mapping,
|
|
1157
1168
|
max,
|