@zipbul/baker 3.0.1 → 3.1.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/CHANGELOG.md +11 -0
- package/dist/src/rules/index.d.ts +1 -1
- package/dist/src/rules/index.js +1 -1
- package/dist/src/rules/string.d.ts +3 -1
- package/dist/src/rules/string.js +38 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @zipbul/baker
|
|
2
2
|
|
|
3
|
+
## 3.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- c40834b: Add `isOrigin` and `isCorsOrigin` string rules for RFC 6454 §6.2 serialized-origin
|
|
8
|
+
validation. `isOrigin` accepts only the canonical WHATWG URL `.origin` form (rejecting
|
|
9
|
+
trailing slash, path/query/fragment, uppercase scheme/host, explicit default ports,
|
|
10
|
+
userinfo, and raw IDN — punycode required) plus the opaque `'null'` literal. `isCorsOrigin`
|
|
11
|
+
is the CORS superset that additionally accepts the `'*'` wildcard. Both work standalone
|
|
12
|
+
(`isOrigin('https://a.com')`) and as `@Field` rules.
|
|
13
|
+
|
|
3
14
|
## 3.0.1
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
|
@@ -3,7 +3,7 @@ export type { IsNumberOptions } from './typechecker';
|
|
|
3
3
|
export { min, max, isPositive, isNegative, isDivisibleBy } from './number';
|
|
4
4
|
export { minDate, maxDate } from './date';
|
|
5
5
|
export { equals, notEquals, isEmpty, isNotEmpty, isIn, isNotIn } from './common';
|
|
6
|
-
export { minLength, maxLength, length, contains, notContains, matches, isLowercase, isUppercase, isAscii, isAlpha, isAlphanumeric, isHttpToken, isBooleanString, isNumberString, isDecimal, isFullWidth, isHalfWidth, isVariableWidth, isMultibyte, isSurrogatePair, isHexadecimal, isOctal, isEmail, isURL, isUUID, isIP, isHexColor, isRgbColor, isHSL, isMACAddress, isISBN, isISIN, isISO8601, isISRC, isISSN, isJWT, isLatLong, isLocale, isDataURI, isFQDN, isPort, isEAN, isISO31661Alpha2, isISO31661Alpha3, isBIC, isFirebasePushId, isSemVer, isMongoId, isJSON, isBase32, isBase58, isBase64, isDateString, isMimeType, isCurrency, isMagnetURI, isCreditCard, isIBAN, isByteLength, isHash, isRFC3339, isMilitaryTime, isLatitude, isLongitude, isEthereumAddress, isBtcAddress, isISO4217CurrencyCode, isPhoneNumber, isStrongPassword, isTaxId, isULID, isCUID2, } from './string';
|
|
6
|
+
export { minLength, maxLength, length, contains, notContains, matches, isLowercase, isUppercase, isAscii, isAlpha, isAlphanumeric, isHttpToken, isOrigin, isCorsOrigin, isBooleanString, isNumberString, isDecimal, isFullWidth, isHalfWidth, isVariableWidth, isMultibyte, isSurrogatePair, isHexadecimal, isOctal, isEmail, isURL, isUUID, isIP, isHexColor, isRgbColor, isHSL, isMACAddress, isISBN, isISIN, isISO8601, isISRC, isISSN, isJWT, isLatLong, isLocale, isDataURI, isFQDN, isPort, isEAN, isISO31661Alpha2, isISO31661Alpha3, isBIC, isFirebasePushId, isSemVer, isMongoId, isJSON, isBase32, isBase58, isBase64, isDateString, isMimeType, isCurrency, isMagnetURI, isCreditCard, isIBAN, isByteLength, isHash, isRFC3339, isMilitaryTime, isLatitude, isLongitude, isEthereumAddress, isBtcAddress, isISO4217CurrencyCode, isPhoneNumber, isStrongPassword, isTaxId, isULID, isCUID2, } from './string';
|
|
7
7
|
export type { IsURLOptions, IsBase64Options, IsMACAddressOptions, IsIBANOptions, IsISSNOptions, IsFQDNOptions, IsISO8601Options, IsNumberStringOptions, IsStrongPasswordOptions, } from './string';
|
|
8
8
|
export { arrayContains, arrayNotContains, arrayMinSize, arrayMaxSize, arrayUnique, arrayNotEmpty } from './array';
|
|
9
9
|
export { isNotEmptyObject, isInstance } from './object';
|
package/dist/src/rules/index.js
CHANGED
|
@@ -2,7 +2,7 @@ export { isString, isNumber, isBoolean, isDate, isEnum, isInt, isArray, isObject
|
|
|
2
2
|
export { min, max, isPositive, isNegative, isDivisibleBy } from './number.js';
|
|
3
3
|
export { minDate, maxDate } from './date.js';
|
|
4
4
|
export { equals, notEquals, isEmpty, isNotEmpty, isIn, isNotIn } from './common.js';
|
|
5
|
-
export { minLength, maxLength, length, contains, notContains, matches, isLowercase, isUppercase, isAscii, isAlpha, isAlphanumeric, isHttpToken, isBooleanString, isNumberString, isDecimal, isFullWidth, isHalfWidth, isVariableWidth, isMultibyte, isSurrogatePair, isHexadecimal, isOctal, isEmail, isURL, isUUID, isIP, isHexColor, isRgbColor, isHSL, isMACAddress, isISBN, isISIN, isISO8601, isISRC, isISSN, isJWT, isLatLong, isLocale, isDataURI, isFQDN, isPort, isEAN, isISO31661Alpha2, isISO31661Alpha3, isBIC, isFirebasePushId, isSemVer, isMongoId, isJSON, isBase32, isBase58, isBase64, isDateString, isMimeType, isCurrency, isMagnetURI, isCreditCard, isIBAN, isByteLength, isHash, isRFC3339, isMilitaryTime, isLatitude, isLongitude, isEthereumAddress, isBtcAddress, isISO4217CurrencyCode, isPhoneNumber, isStrongPassword, isTaxId, isULID, isCUID2, } from './string.js';
|
|
5
|
+
export { minLength, maxLength, length, contains, notContains, matches, isLowercase, isUppercase, isAscii, isAlpha, isAlphanumeric, isHttpToken, isOrigin, isCorsOrigin, isBooleanString, isNumberString, isDecimal, isFullWidth, isHalfWidth, isVariableWidth, isMultibyte, isSurrogatePair, isHexadecimal, isOctal, isEmail, isURL, isUUID, isIP, isHexColor, isRgbColor, isHSL, isMACAddress, isISBN, isISIN, isISO8601, isISRC, isISSN, isJWT, isLatLong, isLocale, isDataURI, isFQDN, isPort, isEAN, isISO31661Alpha2, isISO31661Alpha3, isBIC, isFirebasePushId, isSemVer, isMongoId, isJSON, isBase32, isBase58, isBase64, isDateString, isMimeType, isCurrency, isMagnetURI, isCreditCard, isIBAN, isByteLength, isHash, isRFC3339, isMilitaryTime, isLatitude, isLongitude, isEthereumAddress, isBtcAddress, isISO4217CurrencyCode, isPhoneNumber, isStrongPassword, isTaxId, isULID, isCUID2, } from './string.js';
|
|
6
6
|
export { arrayContains, arrayNotContains, arrayMinSize, arrayMaxSize, arrayUnique, arrayNotEmpty } from './array.js';
|
|
7
7
|
export { isNotEmptyObject, isInstance } from './object.js';
|
|
8
8
|
export { isMobilePhone, isPostalCode, isIdentityCard, isPassportNumber } from './locales.js';
|
|
@@ -11,6 +11,8 @@ declare const isAscii: EmittableRule;
|
|
|
11
11
|
declare const isAlpha: EmittableRule;
|
|
12
12
|
declare const isAlphanumeric: EmittableRule;
|
|
13
13
|
declare const isHttpToken: EmittableRule;
|
|
14
|
+
declare const isOrigin: import("../types").InternalRule;
|
|
15
|
+
declare const isCorsOrigin: import("../types").InternalRule;
|
|
14
16
|
declare const isBooleanString: import("../types").InternalRule;
|
|
15
17
|
interface IsNumberStringOptions {
|
|
16
18
|
no_symbols?: boolean;
|
|
@@ -104,5 +106,5 @@ declare function isStrongPassword(options?: IsStrongPasswordOptions): EmittableR
|
|
|
104
106
|
declare function isTaxId(locale: string): EmittableRule;
|
|
105
107
|
declare function isULID(): EmittableRule;
|
|
106
108
|
declare function isCUID2(): EmittableRule;
|
|
107
|
-
export { minLength, maxLength, length, contains, notContains, matches, isLowercase, isUppercase, isAscii, isAlpha, isAlphanumeric, isHttpToken, isBooleanString, isNumberString, isDecimal, isFullWidth, isHalfWidth, isVariableWidth, isMultibyte, isSurrogatePair, isHexadecimal, isOctal, isEmail, isURL, isUUID, isIP, isHexColor, isRgbColor, isHSL, isMACAddress, isISBN, isISIN, isISO8601, isISRC, isISSN, isJWT, isLatLong, isLocale, isDataURI, isFQDN, isPort, isEAN, isISO31661Alpha2, isISO31661Alpha3, isBIC, isFirebasePushId, isSemVer, isMongoId, isJSON, isBase32, isBase58, isBase64, isDateString, isMimeType, isCurrency, isMagnetURI, isCreditCard, isIBAN, isByteLength, isHash, isRFC3339, isMilitaryTime, isLatitude, isLongitude, isEthereumAddress, isBtcAddress, isISO4217CurrencyCode, isPhoneNumber, isStrongPassword, isTaxId, isULID, isCUID2, };
|
|
109
|
+
export { minLength, maxLength, length, contains, notContains, matches, isLowercase, isUppercase, isAscii, isAlpha, isAlphanumeric, isHttpToken, isOrigin, isCorsOrigin, isBooleanString, isNumberString, isDecimal, isFullWidth, isHalfWidth, isVariableWidth, isMultibyte, isSurrogatePair, isHexadecimal, isOctal, isEmail, isURL, isUUID, isIP, isHexColor, isRgbColor, isHSL, isMACAddress, isISBN, isISIN, isISO8601, isISRC, isISSN, isJWT, isLatLong, isLocale, isDataURI, isFQDN, isPort, isEAN, isISO31661Alpha2, isISO31661Alpha3, isBIC, isFirebasePushId, isSemVer, isMongoId, isJSON, isBase32, isBase58, isBase64, isDateString, isMimeType, isCurrency, isMagnetURI, isCreditCard, isIBAN, isByteLength, isHash, isRFC3339, isMilitaryTime, isLatitude, isLongitude, isEthereumAddress, isBtcAddress, isISO4217CurrencyCode, isPhoneNumber, isStrongPassword, isTaxId, isULID, isCUID2, };
|
|
108
110
|
export type { IsNumberStringOptions, IsURLOptions, IsMACAddressOptions, IsISO8601Options, IsISSNOptions, IsFQDNOptions, IsBase64Options, IsIBANOptions, IsStrongPasswordOptions, };
|
package/dist/src/rules/string.js
CHANGED
|
@@ -129,6 +129,43 @@ const isHttpToken = makeStringRule('isHttpToken', v => HTTP_TOKEN_RE.test(v), (v
|
|
|
129
129
|
const i = ctx.addRegex(HTTP_TOKEN_RE);
|
|
130
130
|
return `if (!re[${i}].test(${varName})) ${ctx.fail('isHttpToken')};`;
|
|
131
131
|
});
|
|
132
|
+
// RFC 6454 §6.2 serialized origin — a string equal to WHATWG URL `.origin`.
|
|
133
|
+
// The opaque-origin literal 'null' is matched explicitly because `new URL('null')` throws.
|
|
134
|
+
// '*' (CORS wildcard) is rejected here; use isCorsOrigin for the CORS superset.
|
|
135
|
+
const isOriginValue = (value) => {
|
|
136
|
+
if (value === 'null') {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
return new URL(value).origin === value;
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const isOrigin = makeRule({
|
|
147
|
+
name: 'isOrigin',
|
|
148
|
+
requiresType: 'string',
|
|
149
|
+
constraints: { format: 'origin' },
|
|
150
|
+
validate: value => typeof value === 'string' && isOriginValue(value),
|
|
151
|
+
emit: (varName, ctx) => {
|
|
152
|
+
const i = ctx.addRef(isOriginValue);
|
|
153
|
+
return `if (!(refs[${i}](${varName}))) ${ctx.fail('isOrigin')};`;
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
// CORS superset of isOrigin: additionally accepts the '*' wildcard literal
|
|
157
|
+
// (Access-Control-Allow-Origin). Keep '*' out of the general isOrigin.
|
|
158
|
+
const isCorsOriginValue = (value) => value === '*' || isOriginValue(value);
|
|
159
|
+
const isCorsOrigin = makeRule({
|
|
160
|
+
name: 'isCorsOrigin',
|
|
161
|
+
requiresType: 'string',
|
|
162
|
+
constraints: { format: 'origin', allowWildcard: true },
|
|
163
|
+
validate: value => typeof value === 'string' && isCorsOriginValue(value),
|
|
164
|
+
emit: (varName, ctx) => {
|
|
165
|
+
const i = ctx.addRef(isCorsOriginValue);
|
|
166
|
+
return `if (!(refs[${i}](${varName}))) ${ctx.fail('isCorsOrigin')};`;
|
|
167
|
+
},
|
|
168
|
+
});
|
|
132
169
|
// BooleanString: 'true' | 'false' | '1' | '0'
|
|
133
170
|
const isBooleanString = makeRule({
|
|
134
171
|
name: 'isBooleanString',
|
|
@@ -1995,4 +2032,4 @@ function isCUID2() {
|
|
|
1995
2032
|
return `if (!re[${i}].test(${varName})) ${ctx.fail('isCUID2')};`;
|
|
1996
2033
|
}, 'string', { format: 'cuid2' });
|
|
1997
2034
|
}
|
|
1998
|
-
export { minLength, maxLength, length, contains, notContains, matches, isLowercase, isUppercase, isAscii, isAlpha, isAlphanumeric, isHttpToken, isBooleanString, isNumberString, isDecimal, isFullWidth, isHalfWidth, isVariableWidth, isMultibyte, isSurrogatePair, isHexadecimal, isOctal, isEmail, isURL, isUUID, isIP, isHexColor, isRgbColor, isHSL, isMACAddress, isISBN, isISIN, isISO8601, isISRC, isISSN, isJWT, isLatLong, isLocale, isDataURI, isFQDN, isPort, isEAN, isISO31661Alpha2, isISO31661Alpha3, isBIC, isFirebasePushId, isSemVer, isMongoId, isJSON, isBase32, isBase58, isBase64, isDateString, isMimeType, isCurrency, isMagnetURI, isCreditCard, isIBAN, isByteLength, isHash, isRFC3339, isMilitaryTime, isLatitude, isLongitude, isEthereumAddress, isBtcAddress, isISO4217CurrencyCode, isPhoneNumber, isStrongPassword, isTaxId, isULID, isCUID2, };
|
|
2035
|
+
export { minLength, maxLength, length, contains, notContains, matches, isLowercase, isUppercase, isAscii, isAlpha, isAlphanumeric, isHttpToken, isOrigin, isCorsOrigin, isBooleanString, isNumberString, isDecimal, isFullWidth, isHalfWidth, isVariableWidth, isMultibyte, isSurrogatePair, isHexadecimal, isOctal, isEmail, isURL, isUUID, isIP, isHexColor, isRgbColor, isHSL, isMACAddress, isISBN, isISIN, isISO8601, isISRC, isISSN, isJWT, isLatLong, isLocale, isDataURI, isFQDN, isPort, isEAN, isISO31661Alpha2, isISO31661Alpha3, isBIC, isFirebasePushId, isSemVer, isMongoId, isJSON, isBase32, isBase58, isBase64, isDateString, isMimeType, isCurrency, isMagnetURI, isCreditCard, isIBAN, isByteLength, isHash, isRFC3339, isMilitaryTime, isLatitude, isLongitude, isEthereumAddress, isBtcAddress, isISO4217CurrencyCode, isPhoneNumber, isStrongPassword, isTaxId, isULID, isCUID2, };
|
package/package.json
CHANGED