isx-intent 0.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/LICENSE +21 -0
- package/README.md +112 -0
- package/dist/index.cjs +362 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +119 -0
- package/dist/index.d.ts +119 -0
- package/dist/index.js +333 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hiren Tumbadiya <tumbadiyahiren@gmail.com> (https://github.com/HirenTumbadiya)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# isx
|
|
2
|
+
|
|
3
|
+
Tiny, **intent-based** string validation for JavaScript and TypeScript. Zero dependencies, extremely lightweight, and tree-shakeable.
|
|
4
|
+
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://www.npmjs.com/package/isx-intent)
|
|
7
|
+
[](https://bundlephobia.com/package/isx-intent)
|
|
8
|
+
|
|
9
|
+
## 🚀 Overview
|
|
10
|
+
|
|
11
|
+
`isx` is designed for developers who want clear, readable, and type-safe string validation. Instead of writing complex regex for every project, use `isx` to express your **intent**.
|
|
12
|
+
|
|
13
|
+
- **Tiny**: No dependencies, minimal footprint.
|
|
14
|
+
- **Type-Safe**: Written in TypeScript with full support for Type Guards and Assertion Functions.
|
|
15
|
+
- **Modular**: Only bundle what you use.
|
|
16
|
+
|
|
17
|
+
## 📦 Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install isx-intent
|
|
21
|
+
# or
|
|
22
|
+
yarn add isx-intent
|
|
23
|
+
# or
|
|
24
|
+
pnpm add isx-intent
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 🛠️ Usage
|
|
28
|
+
|
|
29
|
+
### Boolean Validation (`isx`)
|
|
30
|
+
Returns `true` if valid, `false` otherwise. Acts as a Type Guard.
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
```typescript
|
|
34
|
+
import { isx } from 'isx-intent';
|
|
35
|
+
|
|
36
|
+
if (isx.email('hello@world.com')) {
|
|
37
|
+
// TypeScript knows value is a valid email string here
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
isx.url('https://google.com'); // true
|
|
41
|
+
isx.port(8080); // true
|
|
42
|
+
isx.uuid('f47ac10b...'); // true
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Assertion Validation (`assert`)
|
|
46
|
+
Throws a `ValidationError` if the check fails. Useful for flow control and early returns.
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
```typescript
|
|
50
|
+
import { assert } from 'isx-intent';
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
assert.email(userInput);
|
|
54
|
+
// Proceed with confidence
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.log(error.message); // "Invalid email address"
|
|
57
|
+
console.log(error.code); // "INVALID_EMAIL"
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## 📚 API Reference
|
|
64
|
+
|
|
65
|
+
### Identity & Web
|
|
66
|
+
- `email(value)`: Validates email format.
|
|
67
|
+
- `url(value)`: Validates URL format (supports localhost and ports).
|
|
68
|
+
- `ip(value, version?)`: Validates IPv4 or IPv6.
|
|
69
|
+
- `fqdn(value)`: Fully Qualified Domain Name.
|
|
70
|
+
|
|
71
|
+
### Security & ID
|
|
72
|
+
- `password(value, options?)`: Defaults to min length 8. Can require special chars.
|
|
73
|
+
- `uuid(value)`: RFC4122 v4 UUID.
|
|
74
|
+
- `ulid(value)`: Universal Unique Lexicographically Sortable Identifier.
|
|
75
|
+
- `cuid(value)`: Collision-resistant IDs.
|
|
76
|
+
- `mongodbId(value)`: MongoDB ObjectId format.
|
|
77
|
+
|
|
78
|
+
### Commerce & Finance
|
|
79
|
+
- `creditCard(value)`: Validates using Luhn algorithm.
|
|
80
|
+
- `currency(value, codes?)`: ISO currency codes (USD, EUR, etc.).
|
|
81
|
+
- `iban(value)`: International Bank Account Number format.
|
|
82
|
+
|
|
83
|
+
### Utilities
|
|
84
|
+
- `json(value)`: Checks if string is valid parsable JSON.
|
|
85
|
+
- `semver(value)`: Semantic Versioning (e.g., `1.2.3-beta.1`).
|
|
86
|
+
- `port(value)`: Number between 0 and 65535.
|
|
87
|
+
- `handle(value)`: Social handles (e.g., `@username`).
|
|
88
|
+
- `macAddress(value)`: Standard MAC address format.
|
|
89
|
+
- `hexColor(value)`, `rgbColor(value)`, `hslColor(value)`: CSS color formats.
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 🛡️ Error Handling
|
|
94
|
+
|
|
95
|
+
The `assert` API throws a `ValidationError` which extends the native `Error` class and includes a `code` property for programmatic handling.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
```typescript
|
|
99
|
+
import { ValidationError } from 'isx-intent';
|
|
100
|
+
|
|
101
|
+
// ... inside a catch block
|
|
102
|
+
if (error instanceof ValidationError) {
|
|
103
|
+
switch (error.code) {
|
|
104
|
+
case 'INVALID_EMAIL':
|
|
105
|
+
// handle specific error
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 📄 License
|
|
111
|
+
|
|
112
|
+
MIT © [Hiren Tumbadiya](https://github.com/HirenTumbadiya)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ValidationError: () => ValidationError,
|
|
24
|
+
assert: () => assert,
|
|
25
|
+
isx: () => isx
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/regex/email.ts
|
|
30
|
+
var EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
|
|
31
|
+
|
|
32
|
+
// src/is/email.ts
|
|
33
|
+
function email(value) {
|
|
34
|
+
if (typeof value !== "string") return false;
|
|
35
|
+
if (value.length > 254) return false;
|
|
36
|
+
return EMAIL_REGEX.test(value);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/regex/url.ts
|
|
40
|
+
var URL_REGEX = /^(https?:\/\/)?((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|((\d{1,3}\.){3}\d{1,3})|localhost)(:\d+)?(\/[-a-z\d%_.~+]*)*(\?[;&a-z\d%_.~+=-]*)?(\#[-a-z\d_]*)?$/i;
|
|
41
|
+
|
|
42
|
+
// src/is/url.ts
|
|
43
|
+
function url(value) {
|
|
44
|
+
if (typeof value !== "string") return false;
|
|
45
|
+
return URL_REGEX.test(value);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/is/password.ts
|
|
49
|
+
function password(value, options = {}) {
|
|
50
|
+
if (typeof value !== "string") return false;
|
|
51
|
+
const { minLength = 8, requireSpecial = false } = options;
|
|
52
|
+
if (value.length < minLength) return false;
|
|
53
|
+
if (requireSpecial && !/[!@#$%^&*(),.?":{}|<>]/.test(value)) return false;
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/regex/identifiers.ts
|
|
58
|
+
var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|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9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,6}|:)|(?::(?:(?::[a-fA-F\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,7}|:)))(?:%[0-9a-zA-Z]{1,})?$/;
|
|
61
|
+
|
|
62
|
+
// src/is/uuid.ts
|
|
63
|
+
function uuid(value) {
|
|
64
|
+
if (typeof value !== "string") return false;
|
|
65
|
+
return UUID_REGEX.test(value);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/is/ip.ts
|
|
69
|
+
function ip(value, version) {
|
|
70
|
+
if (typeof value !== "string") return false;
|
|
71
|
+
if (version === 4) return IPV4_REGEX.test(value);
|
|
72
|
+
if (version === 6) return IPV6_REGEX.test(value);
|
|
73
|
+
return IPV4_REGEX.test(value) || IPV6_REGEX.test(value);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/is/json.ts
|
|
77
|
+
function json(value) {
|
|
78
|
+
if (typeof value !== "string") return false;
|
|
79
|
+
try {
|
|
80
|
+
JSON.parse(value);
|
|
81
|
+
return true;
|
|
82
|
+
} catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/regex/modern-identifiers.ts
|
|
88
|
+
var ULID_REGEX = /^[0-9A-HJKMNPQRSTVWXYZ]{26}$/i;
|
|
89
|
+
var CUID_REGEX = /^c[a-z0-9]{24}$/;
|
|
90
|
+
var MONGODB_ID_REGEX = /^[a-f\d]{24}$/i;
|
|
91
|
+
|
|
92
|
+
// src/is/ulid.ts
|
|
93
|
+
function ulid(value) {
|
|
94
|
+
if (typeof value !== "string") return false;
|
|
95
|
+
return ULID_REGEX.test(value);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// src/is/cuid.ts
|
|
99
|
+
function cuid(value) {
|
|
100
|
+
if (typeof value !== "string") return false;
|
|
101
|
+
return CUID_REGEX.test(value);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/is/mongodbId.ts
|
|
105
|
+
function mongodbId(value) {
|
|
106
|
+
if (typeof value !== "string") return false;
|
|
107
|
+
return MONGODB_ID_REGEX.test(value);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/is/creditCard.ts
|
|
111
|
+
function creditCard(value) {
|
|
112
|
+
if (typeof value !== "string") return false;
|
|
113
|
+
const sanitized = value.replace(/[- ]/g, "");
|
|
114
|
+
if (!/^\d{13,19}$/.test(sanitized)) return false;
|
|
115
|
+
let sum = 0;
|
|
116
|
+
let shouldDouble = false;
|
|
117
|
+
for (let i = sanitized.length - 1; i >= 0; i--) {
|
|
118
|
+
let digit = parseInt(sanitized.charAt(i), 10);
|
|
119
|
+
if (shouldDouble) {
|
|
120
|
+
digit *= 2;
|
|
121
|
+
if (digit > 9) digit -= 9;
|
|
122
|
+
}
|
|
123
|
+
sum += digit;
|
|
124
|
+
shouldDouble = !shouldDouble;
|
|
125
|
+
}
|
|
126
|
+
return sum % 10 === 0;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/is/currency.ts
|
|
130
|
+
var CURRENCY_CODES = /* @__PURE__ */ new Set(["USD", "EUR", "GBP", "JPY", "CNY", "INR", "CAD", "AUD", "CHF", "BTC", "ETH"]);
|
|
131
|
+
function currency(value, codes = CURRENCY_CODES) {
|
|
132
|
+
if (typeof value !== "string") return false;
|
|
133
|
+
return codes instanceof Set ? codes.has(value.toUpperCase()) : codes.includes(value.toUpperCase());
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// src/is/iban.ts
|
|
137
|
+
var IBAN_REGEX = /^[A-Z]{2}\d{2}[A-Z\d]{1,30}$/;
|
|
138
|
+
function iban(value) {
|
|
139
|
+
if (typeof value !== "string") return false;
|
|
140
|
+
const s = value.toUpperCase().replace(/ /g, "");
|
|
141
|
+
if (!IBAN_REGEX.test(s)) return false;
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/regex/extended.ts
|
|
146
|
+
var FQDN_REGEX = /^(?!:\/\/)(?:[a-zA-Z0-9-]{1,63}\.)+[a-zA-Z]{2,63}$/;
|
|
147
|
+
var MAC_REGEX = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/;
|
|
148
|
+
var SEMVER_REGEX = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
149
|
+
var HEX_COLOR_REGEX = /^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;
|
|
150
|
+
var RGB_COLOR_REGEX = /^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*(?:\.\d+)?))?\)$/i;
|
|
151
|
+
var HSL_COLOR_REGEX = /^hsla?\((\d+),\s*([\d.]+)%,\s*([\d.]+)%(?:,\s*(\d*(?:\.\d+)?))?\)$/i;
|
|
152
|
+
|
|
153
|
+
// src/is/extended.ts
|
|
154
|
+
function fqdn(value) {
|
|
155
|
+
if (typeof value !== "string") return false;
|
|
156
|
+
return FQDN_REGEX.test(value);
|
|
157
|
+
}
|
|
158
|
+
function macAddress(value) {
|
|
159
|
+
if (typeof value !== "string") return false;
|
|
160
|
+
return MAC_REGEX.test(value);
|
|
161
|
+
}
|
|
162
|
+
function semver(value) {
|
|
163
|
+
if (typeof value !== "string") return false;
|
|
164
|
+
return SEMVER_REGEX.test(value);
|
|
165
|
+
}
|
|
166
|
+
function hexColor(value) {
|
|
167
|
+
if (typeof value !== "string") return false;
|
|
168
|
+
return HEX_COLOR_REGEX.test(value);
|
|
169
|
+
}
|
|
170
|
+
function rgbColor(value) {
|
|
171
|
+
if (typeof value !== "string") return false;
|
|
172
|
+
return RGB_COLOR_REGEX.test(value);
|
|
173
|
+
}
|
|
174
|
+
function hslColor(value) {
|
|
175
|
+
if (typeof value !== "string") return false;
|
|
176
|
+
return HSL_COLOR_REGEX.test(value);
|
|
177
|
+
}
|
|
178
|
+
function port(value) {
|
|
179
|
+
if (typeof value !== "number" || isNaN(value)) return false;
|
|
180
|
+
return value >= 0 && value <= 65535;
|
|
181
|
+
}
|
|
182
|
+
function handle(value) {
|
|
183
|
+
if (typeof value !== "string") return false;
|
|
184
|
+
return /^@[a-z0-9_]{1,30}$/i.test(value);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/is/index.ts
|
|
188
|
+
var isx = {
|
|
189
|
+
email,
|
|
190
|
+
url,
|
|
191
|
+
password,
|
|
192
|
+
uuid,
|
|
193
|
+
ip,
|
|
194
|
+
json,
|
|
195
|
+
ulid,
|
|
196
|
+
cuid,
|
|
197
|
+
mongodbId,
|
|
198
|
+
creditCard,
|
|
199
|
+
currency,
|
|
200
|
+
iban,
|
|
201
|
+
fqdn,
|
|
202
|
+
macAddress,
|
|
203
|
+
semver,
|
|
204
|
+
hexColor,
|
|
205
|
+
rgbColor,
|
|
206
|
+
hslColor,
|
|
207
|
+
port,
|
|
208
|
+
handle
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// src/errors/ValidationError.ts
|
|
212
|
+
var ValidationError = class extends Error {
|
|
213
|
+
code;
|
|
214
|
+
constructor(message, code = "INVALID_VALUE") {
|
|
215
|
+
super(message);
|
|
216
|
+
this.name = "ValidationError";
|
|
217
|
+
this.code = code;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
// src/assert/email.ts
|
|
222
|
+
function email2(value) {
|
|
223
|
+
if (!isx.email(value)) {
|
|
224
|
+
throw new ValidationError(
|
|
225
|
+
"Invalid email address",
|
|
226
|
+
"INVALID_EMAIL"
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// src/assert/url.ts
|
|
232
|
+
function url2(value) {
|
|
233
|
+
if (!isx.url(value)) {
|
|
234
|
+
throw new ValidationError(
|
|
235
|
+
"Invalid URL",
|
|
236
|
+
"INVALID_URL"
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// src/assert/password.ts
|
|
242
|
+
function password2(value, options) {
|
|
243
|
+
if (!isx.password(value, options)) {
|
|
244
|
+
throw new ValidationError(
|
|
245
|
+
"Invalid password",
|
|
246
|
+
"INVALID_PASSWORD"
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// src/assert/uuid.ts
|
|
252
|
+
function uuid2(value) {
|
|
253
|
+
if (!isx.uuid(value)) {
|
|
254
|
+
throw new ValidationError(
|
|
255
|
+
"Invalid UUID",
|
|
256
|
+
"INVALID_UUID"
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// src/assert/ip.ts
|
|
262
|
+
function ip2(value, version) {
|
|
263
|
+
if (!isx.ip(value, version)) {
|
|
264
|
+
throw new ValidationError(
|
|
265
|
+
`Invalid IPv${version || "any"} address`,
|
|
266
|
+
"INVALID_IP"
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// src/assert/json.ts
|
|
272
|
+
function json2(value) {
|
|
273
|
+
if (!isx.json(value)) {
|
|
274
|
+
throw new ValidationError(
|
|
275
|
+
"Invalid JSON string",
|
|
276
|
+
"INVALID_JSON"
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// src/assert/modern-identifiers.ts
|
|
282
|
+
function ulid2(value) {
|
|
283
|
+
if (!isx.ulid(value)) {
|
|
284
|
+
throw new ValidationError("Invalid ULID", "INVALID_ULID");
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function cuid2(value) {
|
|
288
|
+
if (!isx.cuid(value)) {
|
|
289
|
+
throw new ValidationError("Invalid CUID", "INVALID_CUID");
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function mongodbId2(value) {
|
|
293
|
+
if (!isx.mongodbId(value)) {
|
|
294
|
+
throw new ValidationError("Invalid MongoDB ID", "INVALID_MONGODB_ID");
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// src/assert/extended.ts
|
|
299
|
+
function creditCard2(value) {
|
|
300
|
+
if (!isx.creditCard(value)) throw new ValidationError("Invalid credit card", "INVALID_CREDIT_CARD");
|
|
301
|
+
}
|
|
302
|
+
function currency2(value, codes) {
|
|
303
|
+
if (!isx.currency(value, codes)) throw new ValidationError("Invalid currency code", "INVALID_CURRENCY");
|
|
304
|
+
}
|
|
305
|
+
function iban2(value) {
|
|
306
|
+
if (!isx.iban(value)) throw new ValidationError("Invalid IBAN", "INVALID_IBAN");
|
|
307
|
+
}
|
|
308
|
+
function fqdn2(value) {
|
|
309
|
+
if (!isx.fqdn(value)) throw new ValidationError("Invalid FQDN", "INVALID_FQDN");
|
|
310
|
+
}
|
|
311
|
+
function macAddress2(value) {
|
|
312
|
+
if (!isx.macAddress(value)) throw new ValidationError("Invalid MAC address", "INVALID_MAC");
|
|
313
|
+
}
|
|
314
|
+
function semver2(value) {
|
|
315
|
+
if (!isx.semver(value)) throw new ValidationError("Invalid Semantic Version", "INVALID_SEMVER");
|
|
316
|
+
}
|
|
317
|
+
function hexColor2(value) {
|
|
318
|
+
if (!isx.hexColor(value)) throw new ValidationError("Invalid hex color", "INVALID_HEX_COLOR");
|
|
319
|
+
}
|
|
320
|
+
function rgbColor2(value) {
|
|
321
|
+
if (!isx.rgbColor(value)) throw new ValidationError("Invalid RGB color", "INVALID_RGB_COLOR");
|
|
322
|
+
}
|
|
323
|
+
function hslColor2(value) {
|
|
324
|
+
if (!isx.hslColor(value)) throw new ValidationError("Invalid HSL color", "INVALID_HSL_COLOR");
|
|
325
|
+
}
|
|
326
|
+
function port2(value) {
|
|
327
|
+
if (!isx.port(value)) throw new ValidationError("Invalid port number", "INVALID_PORT");
|
|
328
|
+
}
|
|
329
|
+
function handle2(value) {
|
|
330
|
+
if (!isx.handle(value)) throw new ValidationError("Invalid handle", "INVALID_HANDLE");
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// src/assert/index.ts
|
|
334
|
+
var assert = {
|
|
335
|
+
email: email2,
|
|
336
|
+
url: url2,
|
|
337
|
+
password: password2,
|
|
338
|
+
uuid: uuid2,
|
|
339
|
+
ip: ip2,
|
|
340
|
+
json: json2,
|
|
341
|
+
ulid: ulid2,
|
|
342
|
+
cuid: cuid2,
|
|
343
|
+
mongodbId: mongodbId2,
|
|
344
|
+
creditCard: creditCard2,
|
|
345
|
+
currency: currency2,
|
|
346
|
+
iban: iban2,
|
|
347
|
+
fqdn: fqdn2,
|
|
348
|
+
macAddress: macAddress2,
|
|
349
|
+
semver: semver2,
|
|
350
|
+
hexColor: hexColor2,
|
|
351
|
+
rgbColor: rgbColor2,
|
|
352
|
+
hslColor: hslColor2,
|
|
353
|
+
port: port2,
|
|
354
|
+
handle: handle2
|
|
355
|
+
};
|
|
356
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
357
|
+
0 && (module.exports = {
|
|
358
|
+
ValidationError,
|
|
359
|
+
assert,
|
|
360
|
+
isx
|
|
361
|
+
});
|
|
362
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/regex/email.ts","../src/is/email.ts","../src/regex/url.ts","../src/is/url.ts","../src/is/password.ts","../src/regex/identifiers.ts","../src/is/uuid.ts","../src/is/ip.ts","../src/is/json.ts","../src/regex/modern-identifiers.ts","../src/is/ulid.ts","../src/is/cuid.ts","../src/is/mongodbId.ts","../src/is/creditCard.ts","../src/is/currency.ts","../src/is/iban.ts","../src/regex/extended.ts","../src/is/extended.ts","../src/is/index.ts","../src/errors/ValidationError.ts","../src/assert/email.ts","../src/assert/url.ts","../src/assert/password.ts","../src/assert/uuid.ts","../src/assert/ip.ts","../src/assert/json.ts","../src/assert/modern-identifiers.ts","../src/assert/extended.ts","../src/assert/index.ts"],"sourcesContent":["export { isx } from \"./is\";\r\nexport { assert } from \"./assert\";\r\nexport { ValidationError } from \"./errors/ValidationError\";","export const EMAIL_REGEX =\r\n /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$/;","import { EMAIL_REGEX } from \"../regex/email\";\r\n\r\nexport function email(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n if (value.length > 254) return false; // RFC-safe max length\r\n return EMAIL_REGEX.test(value);\r\n}\r\n\r\n\r\n","export const URL_REGEX =\r\n /^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3})|localhost)(:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$/i;\r\n","import { URL_REGEX } from \"../regex/url\";\r\n\r\nexport function url(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return URL_REGEX.test(value);\r\n}\r\n","export function password(value: unknown, options: { minLength?: number; requireSpecial?: boolean } = {}): value is string {\r\n if (typeof value !== \"string\") return false;\r\n const { minLength = 8, requireSpecial = false } = options;\r\n if (value.length < minLength) return false;\r\n if (requireSpecial && !/[!@#$%^&*(),.?\":{}|<>]/.test(value)) return false;\r\n return true;\r\n}\r\n","export const UUID_REGEX =\r\n /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\r\n\r\nexport const IPV4_REGEX =\r\n /^(?:25[0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[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,6}|:)|(?::(?:(?::[a-fA-F\\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,7}|:)))(?:%[0-9a-zA-Z]{1,})?$/;\r\n","import { UUID_REGEX } from \"../regex/identifiers\";\r\n\r\nexport function uuid(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return UUID_REGEX.test(value);\r\n}\r\n","import { IPV4_REGEX, IPV6_REGEX } from \"../regex/identifiers\";\r\n\r\nexport function ip(value: unknown, version?: 4 | 6): value is string {\r\n if (typeof value !== \"string\") return false;\r\n if (version === 4) return IPV4_REGEX.test(value);\r\n if (version === 6) return IPV6_REGEX.test(value);\r\n return IPV4_REGEX.test(value) || IPV6_REGEX.test(value);\r\n}\r\n","export function json(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n try {\r\n JSON.parse(value);\r\n return true;\r\n } catch {\r\n return false;\r\n }\r\n}\r\n","export const ULID_REGEX = /^[0-9A-HJKMNPQRSTVWXYZ]{26}$/i;\r\nexport const CUID_REGEX = /^c[a-z0-9]{24}$/;\r\nexport const MONGODB_ID_REGEX = /^[a-f\\d]{24}$/i;\r\n","import { ULID_REGEX } from \"../regex/modern-identifiers\";\r\n\r\nexport function ulid(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return ULID_REGEX.test(value);\r\n}\r\n","import { CUID_REGEX } from \"../regex/modern-identifiers\";\r\n\r\nexport function cuid(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return CUID_REGEX.test(value);\r\n}\r\n","import { MONGODB_ID_REGEX } from \"../regex/modern-identifiers\";\r\n\r\nexport function mongodbId(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return MONGODB_ID_REGEX.test(value);\r\n}\r\n","export function creditCard(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n const sanitized = value.replace(/[- ]/g, \"\");\r\n if (!/^\\d{13,19}$/.test(sanitized)) return false;\r\n\r\n let sum = 0;\r\n let shouldDouble = false;\r\n for (let i = sanitized.length - 1; i >= 0; i--) {\r\n let digit = parseInt(sanitized.charAt(i), 10);\r\n if (shouldDouble) {\r\n digit *= 2;\r\n if (digit > 9) digit -= 9;\r\n }\r\n sum += digit;\r\n shouldDouble = !shouldDouble;\r\n }\r\n return sum % 10 === 0;\r\n}\r\n","export const CURRENCY_CODES = new Set([\"USD\", \"EUR\", \"GBP\", \"JPY\", \"CNY\", \"INR\", \"CAD\", \"AUD\", \"CHF\", \"BTC\", \"ETH\"]); // Add more as needed\r\n\r\nexport function currency(value: unknown, codes: string[] | Set<string> = CURRENCY_CODES): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return codes instanceof Set ? codes.has(value.toUpperCase()) : codes.includes(value.toUpperCase());\r\n}\r\n","const IBAN_REGEX = /^[A-Z]{2}\\d{2}[A-Z\\d]{1,30}$/;\r\n\r\nexport function iban(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n const s = value.toUpperCase().replace(/ /g, \"\");\r\n if (!IBAN_REGEX.test(s)) return false;\r\n\r\n // Basic validation without full checksum for now, can be expanded\r\n return true;\r\n}\r\n","export const FQDN_REGEX = /^(?!:\\/\\/)(?:[a-zA-Z0-9-]{1,63}\\.)+[a-zA-Z]{2,63}$/;\r\nexport const MAC_REGEX = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/;\r\nexport const SEMVER_REGEX = /^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$/;\r\nexport const HEX_COLOR_REGEX = /^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;\r\nexport const RGB_COLOR_REGEX = /^rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)(?:,\\s*(\\d*(?:\\.\\d+)?))?\\)$/i;\r\nexport const HSL_COLOR_REGEX = /^hsla?\\((\\d+),\\s*([\\d.]+)%,\\s*([\\d.]+)%(?:,\\s*(\\d*(?:\\.\\d+)?))?\\)$/i;\r\n","import { FQDN_REGEX, MAC_REGEX, SEMVER_REGEX, HEX_COLOR_REGEX, RGB_COLOR_REGEX, HSL_COLOR_REGEX } from \"../regex/extended\";\r\n\r\nexport function fqdn(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return FQDN_REGEX.test(value);\r\n}\r\n\r\nexport function macAddress(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return MAC_REGEX.test(value);\r\n}\r\n\r\nexport function semver(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return SEMVER_REGEX.test(value);\r\n}\r\n\r\nexport function hexColor(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return HEX_COLOR_REGEX.test(value);\r\n}\r\n\r\nexport function rgbColor(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return RGB_COLOR_REGEX.test(value);\r\n}\r\n\r\nexport function hslColor(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return HSL_COLOR_REGEX.test(value);\r\n}\r\n\r\nexport function port(value: unknown): value is number {\r\n if (typeof value !== \"number\" || isNaN(value)) return false;\r\n return value >= 0 && value <= 65535;\r\n}\r\n\r\nexport function handle(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return /^@[a-z0-9_]{1,30}$/i.test(value);\r\n}\r\n\r\n","import { email } from \"./email\";\r\nimport { url } from \"./url\";\r\nimport { password } from \"./password\";\r\nimport { uuid } from \"./uuid\";\r\nimport { ip } from \"./ip\";\r\nimport { json } from \"./json\";\r\nimport { ulid } from \"./ulid\";\r\nimport { cuid } from \"./cuid\";\r\nimport { mongodbId } from \"./mongodbId\";\r\nimport { creditCard } from \"./creditCard\";\r\nimport { currency } from \"./currency\";\r\nimport { iban } from \"./iban\";\r\nimport {\r\n fqdn,\r\n macAddress,\r\n semver,\r\n hexColor,\r\n rgbColor,\r\n hslColor,\r\n port,\r\n handle,\r\n} from \"./extended\";\r\n\r\nexport const isx = {\r\n email,\r\n url,\r\n password,\r\n uuid,\r\n ip,\r\n json,\r\n ulid,\r\n cuid,\r\n mongodbId,\r\n creditCard,\r\n currency,\r\n iban,\r\n fqdn,\r\n macAddress,\r\n semver,\r\n hexColor,\r\n rgbColor,\r\n hslColor,\r\n port,\r\n handle,\r\n};\r\n","export class ValidationError extends Error {\r\n readonly code: string;\r\n\r\n constructor(message: string, code = \"INVALID_VALUE\") {\r\n super(message);\r\n this.name = \"ValidationError\";\r\n this.code = code;\r\n }\r\n}","import { isx } from \"../is\";\r\nimport { ValidationError } from \"../errors/ValidationError\";\r\n\r\nexport function email(value: unknown): asserts value is string {\r\n if (!isx.email(value)) {\r\n throw new ValidationError(\r\n \"Invalid email address\",\r\n \"INVALID_EMAIL\"\r\n );\r\n }\r\n}","import { isx } from \"../is\";\r\nimport { ValidationError } from \"../errors/ValidationError\";\r\n\r\nexport function url(value: unknown): asserts value is string {\r\n if (!isx.url(value)) {\r\n throw new ValidationError(\r\n \"Invalid URL\",\r\n \"INVALID_URL\"\r\n );\r\n }\r\n}\r\n","import { isx } from \"../is\";\r\nimport { ValidationError } from \"../errors/ValidationError\";\r\n\r\nexport function password(value: unknown, options?: { minLength?: number; requireSpecial?: boolean }): asserts value is string {\r\n if (!isx.password(value, options)) {\r\n throw new ValidationError(\r\n \"Invalid password\",\r\n \"INVALID_PASSWORD\"\r\n );\r\n }\r\n}\r\n","import { isx } from \"../is\";\r\nimport { ValidationError } from \"../errors/ValidationError\";\r\n\r\nexport function uuid(value: unknown): asserts value is string {\r\n if (!isx.uuid(value)) {\r\n throw new ValidationError(\r\n \"Invalid UUID\",\r\n \"INVALID_UUID\"\r\n );\r\n }\r\n}\r\n","import { isx } from \"../is\";\r\nimport { ValidationError } from \"../errors/ValidationError\";\r\n\r\nexport function ip(value: unknown, version?: 4 | 6): asserts value is string {\r\n if (!isx.ip(value, version)) {\r\n throw new ValidationError(\r\n `Invalid IPv${version || \"any\"} address`,\r\n \"INVALID_IP\"\r\n );\r\n }\r\n}\r\n","import { isx } from \"../is\";\r\nimport { ValidationError } from \"../errors/ValidationError\";\r\n\r\nexport function json(value: unknown): asserts value is string {\r\n if (!isx.json(value)) {\r\n throw new ValidationError(\r\n \"Invalid JSON string\",\r\n \"INVALID_JSON\"\r\n );\r\n }\r\n}\r\n","import { isx } from \"../is\";\r\nimport { ValidationError } from \"../errors/ValidationError\";\r\n\r\nexport function ulid(value: unknown): asserts value is string {\r\n if (!isx.ulid(value)) {\r\n throw new ValidationError(\"Invalid ULID\", \"INVALID_ULID\");\r\n }\r\n}\r\n\r\nexport function cuid(value: unknown): asserts value is string {\r\n if (!isx.cuid(value)) {\r\n throw new ValidationError(\"Invalid CUID\", \"INVALID_CUID\");\r\n }\r\n}\r\n\r\nexport function mongodbId(value: unknown): asserts value is string {\r\n if (!isx.mongodbId(value)) {\r\n throw new ValidationError(\"Invalid MongoDB ID\", \"INVALID_MONGODB_ID\");\r\n }\r\n}\r\n","import { isx } from \"../is\";\r\nimport { ValidationError } from \"../errors/ValidationError\";\r\n\r\nexport function creditCard(value: unknown): asserts value is string {\r\n if (!isx.creditCard(value)) throw new ValidationError(\"Invalid credit card\", \"INVALID_CREDIT_CARD\");\r\n}\r\n\r\nexport function currency(value: unknown, codes?: string[] | Set<string>): asserts value is string {\r\n if (!isx.currency(value, codes)) throw new ValidationError(\"Invalid currency code\", \"INVALID_CURRENCY\");\r\n}\r\n\r\nexport function iban(value: unknown): asserts value is string {\r\n if (!isx.iban(value)) throw new ValidationError(\"Invalid IBAN\", \"INVALID_IBAN\");\r\n}\r\n\r\nexport function fqdn(value: unknown): asserts value is string {\r\n if (!isx.fqdn(value)) throw new ValidationError(\"Invalid FQDN\", \"INVALID_FQDN\");\r\n}\r\n\r\nexport function macAddress(value: unknown): asserts value is string {\r\n if (!isx.macAddress(value)) throw new ValidationError(\"Invalid MAC address\", \"INVALID_MAC\");\r\n}\r\n\r\nexport function semver(value: unknown): asserts value is string {\r\n if (!isx.semver(value)) throw new ValidationError(\"Invalid Semantic Version\", \"INVALID_SEMVER\");\r\n}\r\n\r\nexport function hexColor(value: unknown): asserts value is string {\r\n if (!isx.hexColor(value)) throw new ValidationError(\"Invalid hex color\", \"INVALID_HEX_COLOR\");\r\n}\r\n\r\nexport function rgbColor(value: unknown): asserts value is string {\r\n if (!isx.rgbColor(value)) throw new ValidationError(\"Invalid RGB color\", \"INVALID_RGB_COLOR\");\r\n}\r\n\r\nexport function hslColor(value: unknown): asserts value is string {\r\n if (!isx.hslColor(value)) throw new ValidationError(\"Invalid HSL color\", \"INVALID_HSL_COLOR\");\r\n}\r\n\r\nexport function port(value: unknown): asserts value is number {\r\n if (!isx.port(value)) throw new ValidationError(\"Invalid port number\", \"INVALID_PORT\");\r\n}\r\n\r\nexport function handle(value: unknown): asserts value is string {\r\n if (!isx.handle(value)) throw new ValidationError(\"Invalid handle\", \"INVALID_HANDLE\");\r\n}\r\n","import { email } from \"./email\";\r\nimport { url } from \"./url\";\r\nimport { password } from \"./password\";\r\nimport { uuid } from \"./uuid\";\r\nimport { ip } from \"./ip\";\r\nimport { json } from \"./json\";\r\nimport { ulid, cuid, mongodbId } from \"./modern-identifiers\";\r\nimport {\r\n creditCard,\r\n currency,\r\n iban,\r\n fqdn,\r\n macAddress,\r\n semver,\r\n hexColor,\r\n rgbColor,\r\n hslColor,\r\n port,\r\n handle,\r\n} from \"./extended\";\r\n\r\nexport const assert = {\r\n email,\r\n url,\r\n password,\r\n uuid,\r\n ip,\r\n json,\r\n ulid,\r\n cuid,\r\n mongodbId,\r\n creditCard,\r\n currency,\r\n iban,\r\n fqdn,\r\n macAddress,\r\n semver,\r\n hexColor,\r\n rgbColor,\r\n hslColor,\r\n port,\r\n handle,\r\n};"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,cACX;;;ACCK,SAAS,MAAM,OAAiC;AACrD,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,MAAI,MAAM,SAAS,IAAK,QAAO;AAC/B,SAAO,YAAY,KAAK,KAAK;AAC/B;;;ACNO,IAAM,YACX;;;ACCK,SAAS,IAAI,OAAiC;AACjD,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,SAAO,UAAU,KAAK,KAAK;AAC/B;;;ACLO,SAAS,SAAS,OAAgB,UAA4D,CAAC,GAAoB;AACtH,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,QAAM,EAAE,YAAY,GAAG,iBAAiB,MAAM,IAAI;AAClD,MAAI,MAAM,SAAS,UAAW,QAAO;AACrC,MAAI,kBAAkB,CAAC,yBAAyB,KAAK,KAAK,EAAG,QAAO;AACpE,SAAO;AACX;;;ACNO,IAAM,aACT;AAEG,IAAM,aACT;AAEG,IAAM,aACT;;;ACLG,SAAS,KAAK,OAAiC;AAClD,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,SAAO,WAAW,KAAK,KAAK;AAChC;;;ACHO,SAAS,GAAG,OAAgB,SAAkC;AACjE,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,MAAI,YAAY,EAAG,QAAO,WAAW,KAAK,KAAK;AAC/C,MAAI,YAAY,EAAG,QAAO,WAAW,KAAK,KAAK;AAC/C,SAAO,WAAW,KAAK,KAAK,KAAK,WAAW,KAAK,KAAK;AAC1D;;;ACPO,SAAS,KAAK,OAAiC;AA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B,mBAAmB;AAChG;AAEO,SAASC,UAAS,OAAyC;AAC9D,MAAI,CAAC,IAAI,SAAS,KAAK,EAAG,OAAM,IAAI,gBAAgB,qBAAqB,mBAAmB;AAChG;AAEO,SAASC,MAAK,OAAyC;AAC1D,MAAI,CAAC,IAAI,KAAK,KAAK,EAAG,OAAM,IAAI,gBAAgB,uBAAuB,cAAc;AACzF;AAEO,SAASC,QAAO,OAAyC;AAC5D,MAAI,CAAC,IAAI,OAAO,KAAK,EAAG,OAAM,IAAI,gBAAgB,kBAAkB,gBAAgB;AACxF;;;ACxBO,IAAM,SAAS;AAAA,EACpB,OAAAC;AAAA,EACA,KAAAC;AAAA,EACA,UAAAC;AAAA,EACA,MAAAC;AAAA,EACA,IAAAC;AAAA,EACA,MAAAC;AAAA,EACA,MAAAC;AAAA,EACA,MAAAC;AAAA,EACA,WAAAC;AAAA,EACA,YAAAC;AAAA,EACA,UAAAC;AAAA,EACA,MAAAC;AAAA,EACA,MAAAC;AAAA,EACA,YAAAC;AAAA,EACA,QAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,MAAAC;AAAA,EACA,QAAAC;AACF;","names":["email","url","password","uuid","ip","json","ulid","cuid","mongodbId","creditCard","currency","iban","fqdn","macAddress","semver","hexColor","rgbColor","hslColor","port","handle","email","url","password","uuid","ip","json","ulid","cuid","mongodbId","creditCard","currency","iban","fqdn","macAddress","semver","hexColor","rgbColor","hslColor","port","handle"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
declare function email$1(value: unknown): value is string;
|
|
2
|
+
|
|
3
|
+
declare function url$1(value: unknown): value is string;
|
|
4
|
+
|
|
5
|
+
declare function password$1(value: unknown, options?: {
|
|
6
|
+
minLength?: number;
|
|
7
|
+
requireSpecial?: boolean;
|
|
8
|
+
}): value is string;
|
|
9
|
+
|
|
10
|
+
declare function uuid$1(value: unknown): value is string;
|
|
11
|
+
|
|
12
|
+
declare function ip$1(value: unknown, version?: 4 | 6): value is string;
|
|
13
|
+
|
|
14
|
+
declare function json$1(value: unknown): value is string;
|
|
15
|
+
|
|
16
|
+
declare function ulid$1(value: unknown): value is string;
|
|
17
|
+
|
|
18
|
+
declare function cuid$1(value: unknown): value is string;
|
|
19
|
+
|
|
20
|
+
declare function mongodbId$1(value: unknown): value is string;
|
|
21
|
+
|
|
22
|
+
declare function creditCard$1(value: unknown): value is string;
|
|
23
|
+
|
|
24
|
+
declare function currency$1(value: unknown, codes?: string[] | Set<string>): value is string;
|
|
25
|
+
|
|
26
|
+
declare function iban$1(value: unknown): value is string;
|
|
27
|
+
|
|
28
|
+
declare function fqdn$1(value: unknown): value is string;
|
|
29
|
+
declare function macAddress$1(value: unknown): value is string;
|
|
30
|
+
declare function semver$1(value: unknown): value is string;
|
|
31
|
+
declare function hexColor$1(value: unknown): value is string;
|
|
32
|
+
declare function rgbColor$1(value: unknown): value is string;
|
|
33
|
+
declare function hslColor$1(value: unknown): value is string;
|
|
34
|
+
declare function port$1(value: unknown): value is number;
|
|
35
|
+
declare function handle$1(value: unknown): value is string;
|
|
36
|
+
|
|
37
|
+
declare const isx: {
|
|
38
|
+
email: typeof email$1;
|
|
39
|
+
url: typeof url$1;
|
|
40
|
+
password: typeof password$1;
|
|
41
|
+
uuid: typeof uuid$1;
|
|
42
|
+
ip: typeof ip$1;
|
|
43
|
+
json: typeof json$1;
|
|
44
|
+
ulid: typeof ulid$1;
|
|
45
|
+
cuid: typeof cuid$1;
|
|
46
|
+
mongodbId: typeof mongodbId$1;
|
|
47
|
+
creditCard: typeof creditCard$1;
|
|
48
|
+
currency: typeof currency$1;
|
|
49
|
+
iban: typeof iban$1;
|
|
50
|
+
fqdn: typeof fqdn$1;
|
|
51
|
+
macAddress: typeof macAddress$1;
|
|
52
|
+
semver: typeof semver$1;
|
|
53
|
+
hexColor: typeof hexColor$1;
|
|
54
|
+
rgbColor: typeof rgbColor$1;
|
|
55
|
+
hslColor: typeof hslColor$1;
|
|
56
|
+
port: typeof port$1;
|
|
57
|
+
handle: typeof handle$1;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
declare function email(value: unknown): asserts value is string;
|
|
61
|
+
|
|
62
|
+
declare function url(value: unknown): asserts value is string;
|
|
63
|
+
|
|
64
|
+
declare function password(value: unknown, options?: {
|
|
65
|
+
minLength?: number;
|
|
66
|
+
requireSpecial?: boolean;
|
|
67
|
+
}): asserts value is string;
|
|
68
|
+
|
|
69
|
+
declare function uuid(value: unknown): asserts value is string;
|
|
70
|
+
|
|
71
|
+
declare function ip(value: unknown, version?: 4 | 6): asserts value is string;
|
|
72
|
+
|
|
73
|
+
declare function json(value: unknown): asserts value is string;
|
|
74
|
+
|
|
75
|
+
declare function ulid(value: unknown): asserts value is string;
|
|
76
|
+
declare function cuid(value: unknown): asserts value is string;
|
|
77
|
+
declare function mongodbId(value: unknown): asserts value is string;
|
|
78
|
+
|
|
79
|
+
declare function creditCard(value: unknown): asserts value is string;
|
|
80
|
+
declare function currency(value: unknown, codes?: string[] | Set<string>): asserts value is string;
|
|
81
|
+
declare function iban(value: unknown): asserts value is string;
|
|
82
|
+
declare function fqdn(value: unknown): asserts value is string;
|
|
83
|
+
declare function macAddress(value: unknown): asserts value is string;
|
|
84
|
+
declare function semver(value: unknown): asserts value is string;
|
|
85
|
+
declare function hexColor(value: unknown): asserts value is string;
|
|
86
|
+
declare function rgbColor(value: unknown): asserts value is string;
|
|
87
|
+
declare function hslColor(value: unknown): asserts value is string;
|
|
88
|
+
declare function port(value: unknown): asserts value is number;
|
|
89
|
+
declare function handle(value: unknown): asserts value is string;
|
|
90
|
+
|
|
91
|
+
declare const assert: {
|
|
92
|
+
email: typeof email;
|
|
93
|
+
url: typeof url;
|
|
94
|
+
password: typeof password;
|
|
95
|
+
uuid: typeof uuid;
|
|
96
|
+
ip: typeof ip;
|
|
97
|
+
json: typeof json;
|
|
98
|
+
ulid: typeof ulid;
|
|
99
|
+
cuid: typeof cuid;
|
|
100
|
+
mongodbId: typeof mongodbId;
|
|
101
|
+
creditCard: typeof creditCard;
|
|
102
|
+
currency: typeof currency;
|
|
103
|
+
iban: typeof iban;
|
|
104
|
+
fqdn: typeof fqdn;
|
|
105
|
+
macAddress: typeof macAddress;
|
|
106
|
+
semver: typeof semver;
|
|
107
|
+
hexColor: typeof hexColor;
|
|
108
|
+
rgbColor: typeof rgbColor;
|
|
109
|
+
hslColor: typeof hslColor;
|
|
110
|
+
port: typeof port;
|
|
111
|
+
handle: typeof handle;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
declare class ValidationError extends Error {
|
|
115
|
+
readonly code: string;
|
|
116
|
+
constructor(message: string, code?: string);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export { ValidationError, assert, isx };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
declare function email$1(value: unknown): value is string;
|
|
2
|
+
|
|
3
|
+
declare function url$1(value: unknown): value is string;
|
|
4
|
+
|
|
5
|
+
declare function password$1(value: unknown, options?: {
|
|
6
|
+
minLength?: number;
|
|
7
|
+
requireSpecial?: boolean;
|
|
8
|
+
}): value is string;
|
|
9
|
+
|
|
10
|
+
declare function uuid$1(value: unknown): value is string;
|
|
11
|
+
|
|
12
|
+
declare function ip$1(value: unknown, version?: 4 | 6): value is string;
|
|
13
|
+
|
|
14
|
+
declare function json$1(value: unknown): value is string;
|
|
15
|
+
|
|
16
|
+
declare function ulid$1(value: unknown): value is string;
|
|
17
|
+
|
|
18
|
+
declare function cuid$1(value: unknown): value is string;
|
|
19
|
+
|
|
20
|
+
declare function mongodbId$1(value: unknown): value is string;
|
|
21
|
+
|
|
22
|
+
declare function creditCard$1(value: unknown): value is string;
|
|
23
|
+
|
|
24
|
+
declare function currency$1(value: unknown, codes?: string[] | Set<string>): value is string;
|
|
25
|
+
|
|
26
|
+
declare function iban$1(value: unknown): value is string;
|
|
27
|
+
|
|
28
|
+
declare function fqdn$1(value: unknown): value is string;
|
|
29
|
+
declare function macAddress$1(value: unknown): value is string;
|
|
30
|
+
declare function semver$1(value: unknown): value is string;
|
|
31
|
+
declare function hexColor$1(value: unknown): value is string;
|
|
32
|
+
declare function rgbColor$1(value: unknown): value is string;
|
|
33
|
+
declare function hslColor$1(value: unknown): value is string;
|
|
34
|
+
declare function port$1(value: unknown): value is number;
|
|
35
|
+
declare function handle$1(value: unknown): value is string;
|
|
36
|
+
|
|
37
|
+
declare const isx: {
|
|
38
|
+
email: typeof email$1;
|
|
39
|
+
url: typeof url$1;
|
|
40
|
+
password: typeof password$1;
|
|
41
|
+
uuid: typeof uuid$1;
|
|
42
|
+
ip: typeof ip$1;
|
|
43
|
+
json: typeof json$1;
|
|
44
|
+
ulid: typeof ulid$1;
|
|
45
|
+
cuid: typeof cuid$1;
|
|
46
|
+
mongodbId: typeof mongodbId$1;
|
|
47
|
+
creditCard: typeof creditCard$1;
|
|
48
|
+
currency: typeof currency$1;
|
|
49
|
+
iban: typeof iban$1;
|
|
50
|
+
fqdn: typeof fqdn$1;
|
|
51
|
+
macAddress: typeof macAddress$1;
|
|
52
|
+
semver: typeof semver$1;
|
|
53
|
+
hexColor: typeof hexColor$1;
|
|
54
|
+
rgbColor: typeof rgbColor$1;
|
|
55
|
+
hslColor: typeof hslColor$1;
|
|
56
|
+
port: typeof port$1;
|
|
57
|
+
handle: typeof handle$1;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
declare function email(value: unknown): asserts value is string;
|
|
61
|
+
|
|
62
|
+
declare function url(value: unknown): asserts value is string;
|
|
63
|
+
|
|
64
|
+
declare function password(value: unknown, options?: {
|
|
65
|
+
minLength?: number;
|
|
66
|
+
requireSpecial?: boolean;
|
|
67
|
+
}): asserts value is string;
|
|
68
|
+
|
|
69
|
+
declare function uuid(value: unknown): asserts value is string;
|
|
70
|
+
|
|
71
|
+
declare function ip(value: unknown, version?: 4 | 6): asserts value is string;
|
|
72
|
+
|
|
73
|
+
declare function json(value: unknown): asserts value is string;
|
|
74
|
+
|
|
75
|
+
declare function ulid(value: unknown): asserts value is string;
|
|
76
|
+
declare function cuid(value: unknown): asserts value is string;
|
|
77
|
+
declare function mongodbId(value: unknown): asserts value is string;
|
|
78
|
+
|
|
79
|
+
declare function creditCard(value: unknown): asserts value is string;
|
|
80
|
+
declare function currency(value: unknown, codes?: string[] | Set<string>): asserts value is string;
|
|
81
|
+
declare function iban(value: unknown): asserts value is string;
|
|
82
|
+
declare function fqdn(value: unknown): asserts value is string;
|
|
83
|
+
declare function macAddress(value: unknown): asserts value is string;
|
|
84
|
+
declare function semver(value: unknown): asserts value is string;
|
|
85
|
+
declare function hexColor(value: unknown): asserts value is string;
|
|
86
|
+
declare function rgbColor(value: unknown): asserts value is string;
|
|
87
|
+
declare function hslColor(value: unknown): asserts value is string;
|
|
88
|
+
declare function port(value: unknown): asserts value is number;
|
|
89
|
+
declare function handle(value: unknown): asserts value is string;
|
|
90
|
+
|
|
91
|
+
declare const assert: {
|
|
92
|
+
email: typeof email;
|
|
93
|
+
url: typeof url;
|
|
94
|
+
password: typeof password;
|
|
95
|
+
uuid: typeof uuid;
|
|
96
|
+
ip: typeof ip;
|
|
97
|
+
json: typeof json;
|
|
98
|
+
ulid: typeof ulid;
|
|
99
|
+
cuid: typeof cuid;
|
|
100
|
+
mongodbId: typeof mongodbId;
|
|
101
|
+
creditCard: typeof creditCard;
|
|
102
|
+
currency: typeof currency;
|
|
103
|
+
iban: typeof iban;
|
|
104
|
+
fqdn: typeof fqdn;
|
|
105
|
+
macAddress: typeof macAddress;
|
|
106
|
+
semver: typeof semver;
|
|
107
|
+
hexColor: typeof hexColor;
|
|
108
|
+
rgbColor: typeof rgbColor;
|
|
109
|
+
hslColor: typeof hslColor;
|
|
110
|
+
port: typeof port;
|
|
111
|
+
handle: typeof handle;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
declare class ValidationError extends Error {
|
|
115
|
+
readonly code: string;
|
|
116
|
+
constructor(message: string, code?: string);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export { ValidationError, assert, isx };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
// src/regex/email.ts
|
|
2
|
+
var EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
|
|
3
|
+
|
|
4
|
+
// src/is/email.ts
|
|
5
|
+
function email(value) {
|
|
6
|
+
if (typeof value !== "string") return false;
|
|
7
|
+
if (value.length > 254) return false;
|
|
8
|
+
return EMAIL_REGEX.test(value);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// src/regex/url.ts
|
|
12
|
+
var URL_REGEX = /^(https?:\/\/)?((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|((\d{1,3}\.){3}\d{1,3})|localhost)(:\d+)?(\/[-a-z\d%_.~+]*)*(\?[;&a-z\d%_.~+=-]*)?(\#[-a-z\d_]*)?$/i;
|
|
13
|
+
|
|
14
|
+
// src/is/url.ts
|
|
15
|
+
function url(value) {
|
|
16
|
+
if (typeof value !== "string") return false;
|
|
17
|
+
return URL_REGEX.test(value);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/is/password.ts
|
|
21
|
+
function password(value, options = {}) {
|
|
22
|
+
if (typeof value !== "string") return false;
|
|
23
|
+
const { minLength = 8, requireSpecial = false } = options;
|
|
24
|
+
if (value.length < minLength) return false;
|
|
25
|
+
if (requireSpecial && !/[!@#$%^&*(),.?":{}|<>]/.test(value)) return false;
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// src/regex/identifiers.ts
|
|
30
|
+
var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
31
|
+
var IPV4_REGEX = /^(?:25[0-5]|2[0-4]\d|1\d\d|[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[a-fA-F\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,7}|:)))(?:%[0-9a-zA-Z]{1,})?$/;
|
|
33
|
+
|
|
34
|
+
// src/is/uuid.ts
|
|
35
|
+
function uuid(value) {
|
|
36
|
+
if (typeof value !== "string") return false;
|
|
37
|
+
return UUID_REGEX.test(value);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/is/ip.ts
|
|
41
|
+
function ip(value, version) {
|
|
42
|
+
if (typeof value !== "string") return false;
|
|
43
|
+
if (version === 4) return IPV4_REGEX.test(value);
|
|
44
|
+
if (version === 6) return IPV6_REGEX.test(value);
|
|
45
|
+
return IPV4_REGEX.test(value) || IPV6_REGEX.test(value);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/is/json.ts
|
|
49
|
+
function json(value) {
|
|
50
|
+
if (typeof value !== "string") return false;
|
|
51
|
+
try {
|
|
52
|
+
JSON.parse(value);
|
|
53
|
+
return true;
|
|
54
|
+
} catch {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/regex/modern-identifiers.ts
|
|
60
|
+
var ULID_REGEX = /^[0-9A-HJKMNPQRSTVWXYZ]{26}$/i;
|
|
61
|
+
var CUID_REGEX = /^c[a-z0-9]{24}$/;
|
|
62
|
+
var MONGODB_ID_REGEX = /^[a-f\d]{24}$/i;
|
|
63
|
+
|
|
64
|
+
// src/is/ulid.ts
|
|
65
|
+
function ulid(value) {
|
|
66
|
+
if (typeof value !== "string") return false;
|
|
67
|
+
return ULID_REGEX.test(value);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/is/cuid.ts
|
|
71
|
+
function cuid(value) {
|
|
72
|
+
if (typeof value !== "string") return false;
|
|
73
|
+
return CUID_REGEX.test(value);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/is/mongodbId.ts
|
|
77
|
+
function mongodbId(value) {
|
|
78
|
+
if (typeof value !== "string") return false;
|
|
79
|
+
return MONGODB_ID_REGEX.test(value);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/is/creditCard.ts
|
|
83
|
+
function creditCard(value) {
|
|
84
|
+
if (typeof value !== "string") return false;
|
|
85
|
+
const sanitized = value.replace(/[- ]/g, "");
|
|
86
|
+
if (!/^\d{13,19}$/.test(sanitized)) return false;
|
|
87
|
+
let sum = 0;
|
|
88
|
+
let shouldDouble = false;
|
|
89
|
+
for (let i = sanitized.length - 1; i >= 0; i--) {
|
|
90
|
+
let digit = parseInt(sanitized.charAt(i), 10);
|
|
91
|
+
if (shouldDouble) {
|
|
92
|
+
digit *= 2;
|
|
93
|
+
if (digit > 9) digit -= 9;
|
|
94
|
+
}
|
|
95
|
+
sum += digit;
|
|
96
|
+
shouldDouble = !shouldDouble;
|
|
97
|
+
}
|
|
98
|
+
return sum % 10 === 0;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/is/currency.ts
|
|
102
|
+
var CURRENCY_CODES = /* @__PURE__ */ new Set(["USD", "EUR", "GBP", "JPY", "CNY", "INR", "CAD", "AUD", "CHF", "BTC", "ETH"]);
|
|
103
|
+
function currency(value, codes = CURRENCY_CODES) {
|
|
104
|
+
if (typeof value !== "string") return false;
|
|
105
|
+
return codes instanceof Set ? codes.has(value.toUpperCase()) : codes.includes(value.toUpperCase());
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// src/is/iban.ts
|
|
109
|
+
var IBAN_REGEX = /^[A-Z]{2}\d{2}[A-Z\d]{1,30}$/;
|
|
110
|
+
function iban(value) {
|
|
111
|
+
if (typeof value !== "string") return false;
|
|
112
|
+
const s = value.toUpperCase().replace(/ /g, "");
|
|
113
|
+
if (!IBAN_REGEX.test(s)) return false;
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/regex/extended.ts
|
|
118
|
+
var FQDN_REGEX = /^(?!:\/\/)(?:[a-zA-Z0-9-]{1,63}\.)+[a-zA-Z]{2,63}$/;
|
|
119
|
+
var MAC_REGEX = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/;
|
|
120
|
+
var SEMVER_REGEX = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
121
|
+
var HEX_COLOR_REGEX = /^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;
|
|
122
|
+
var RGB_COLOR_REGEX = /^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*(?:\.\d+)?))?\)$/i;
|
|
123
|
+
var HSL_COLOR_REGEX = /^hsla?\((\d+),\s*([\d.]+)%,\s*([\d.]+)%(?:,\s*(\d*(?:\.\d+)?))?\)$/i;
|
|
124
|
+
|
|
125
|
+
// src/is/extended.ts
|
|
126
|
+
function fqdn(value) {
|
|
127
|
+
if (typeof value !== "string") return false;
|
|
128
|
+
return FQDN_REGEX.test(value);
|
|
129
|
+
}
|
|
130
|
+
function macAddress(value) {
|
|
131
|
+
if (typeof value !== "string") return false;
|
|
132
|
+
return MAC_REGEX.test(value);
|
|
133
|
+
}
|
|
134
|
+
function semver(value) {
|
|
135
|
+
if (typeof value !== "string") return false;
|
|
136
|
+
return SEMVER_REGEX.test(value);
|
|
137
|
+
}
|
|
138
|
+
function hexColor(value) {
|
|
139
|
+
if (typeof value !== "string") return false;
|
|
140
|
+
return HEX_COLOR_REGEX.test(value);
|
|
141
|
+
}
|
|
142
|
+
function rgbColor(value) {
|
|
143
|
+
if (typeof value !== "string") return false;
|
|
144
|
+
return RGB_COLOR_REGEX.test(value);
|
|
145
|
+
}
|
|
146
|
+
function hslColor(value) {
|
|
147
|
+
if (typeof value !== "string") return false;
|
|
148
|
+
return HSL_COLOR_REGEX.test(value);
|
|
149
|
+
}
|
|
150
|
+
function port(value) {
|
|
151
|
+
if (typeof value !== "number" || isNaN(value)) return false;
|
|
152
|
+
return value >= 0 && value <= 65535;
|
|
153
|
+
}
|
|
154
|
+
function handle(value) {
|
|
155
|
+
if (typeof value !== "string") return false;
|
|
156
|
+
return /^@[a-z0-9_]{1,30}$/i.test(value);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// src/is/index.ts
|
|
160
|
+
var isx = {
|
|
161
|
+
email,
|
|
162
|
+
url,
|
|
163
|
+
password,
|
|
164
|
+
uuid,
|
|
165
|
+
ip,
|
|
166
|
+
json,
|
|
167
|
+
ulid,
|
|
168
|
+
cuid,
|
|
169
|
+
mongodbId,
|
|
170
|
+
creditCard,
|
|
171
|
+
currency,
|
|
172
|
+
iban,
|
|
173
|
+
fqdn,
|
|
174
|
+
macAddress,
|
|
175
|
+
semver,
|
|
176
|
+
hexColor,
|
|
177
|
+
rgbColor,
|
|
178
|
+
hslColor,
|
|
179
|
+
port,
|
|
180
|
+
handle
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// src/errors/ValidationError.ts
|
|
184
|
+
var ValidationError = class extends Error {
|
|
185
|
+
code;
|
|
186
|
+
constructor(message, code = "INVALID_VALUE") {
|
|
187
|
+
super(message);
|
|
188
|
+
this.name = "ValidationError";
|
|
189
|
+
this.code = code;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// src/assert/email.ts
|
|
194
|
+
function email2(value) {
|
|
195
|
+
if (!isx.email(value)) {
|
|
196
|
+
throw new ValidationError(
|
|
197
|
+
"Invalid email address",
|
|
198
|
+
"INVALID_EMAIL"
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// src/assert/url.ts
|
|
204
|
+
function url2(value) {
|
|
205
|
+
if (!isx.url(value)) {
|
|
206
|
+
throw new ValidationError(
|
|
207
|
+
"Invalid URL",
|
|
208
|
+
"INVALID_URL"
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/assert/password.ts
|
|
214
|
+
function password2(value, options) {
|
|
215
|
+
if (!isx.password(value, options)) {
|
|
216
|
+
throw new ValidationError(
|
|
217
|
+
"Invalid password",
|
|
218
|
+
"INVALID_PASSWORD"
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// src/assert/uuid.ts
|
|
224
|
+
function uuid2(value) {
|
|
225
|
+
if (!isx.uuid(value)) {
|
|
226
|
+
throw new ValidationError(
|
|
227
|
+
"Invalid UUID",
|
|
228
|
+
"INVALID_UUID"
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// src/assert/ip.ts
|
|
234
|
+
function ip2(value, version) {
|
|
235
|
+
if (!isx.ip(value, version)) {
|
|
236
|
+
throw new ValidationError(
|
|
237
|
+
`Invalid IPv${version || "any"} address`,
|
|
238
|
+
"INVALID_IP"
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// src/assert/json.ts
|
|
244
|
+
function json2(value) {
|
|
245
|
+
if (!isx.json(value)) {
|
|
246
|
+
throw new ValidationError(
|
|
247
|
+
"Invalid JSON string",
|
|
248
|
+
"INVALID_JSON"
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// src/assert/modern-identifiers.ts
|
|
254
|
+
function ulid2(value) {
|
|
255
|
+
if (!isx.ulid(value)) {
|
|
256
|
+
throw new ValidationError("Invalid ULID", "INVALID_ULID");
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function cuid2(value) {
|
|
260
|
+
if (!isx.cuid(value)) {
|
|
261
|
+
throw new ValidationError("Invalid CUID", "INVALID_CUID");
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
function mongodbId2(value) {
|
|
265
|
+
if (!isx.mongodbId(value)) {
|
|
266
|
+
throw new ValidationError("Invalid MongoDB ID", "INVALID_MONGODB_ID");
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// src/assert/extended.ts
|
|
271
|
+
function creditCard2(value) {
|
|
272
|
+
if (!isx.creditCard(value)) throw new ValidationError("Invalid credit card", "INVALID_CREDIT_CARD");
|
|
273
|
+
}
|
|
274
|
+
function currency2(value, codes) {
|
|
275
|
+
if (!isx.currency(value, codes)) throw new ValidationError("Invalid currency code", "INVALID_CURRENCY");
|
|
276
|
+
}
|
|
277
|
+
function iban2(value) {
|
|
278
|
+
if (!isx.iban(value)) throw new ValidationError("Invalid IBAN", "INVALID_IBAN");
|
|
279
|
+
}
|
|
280
|
+
function fqdn2(value) {
|
|
281
|
+
if (!isx.fqdn(value)) throw new ValidationError("Invalid FQDN", "INVALID_FQDN");
|
|
282
|
+
}
|
|
283
|
+
function macAddress2(value) {
|
|
284
|
+
if (!isx.macAddress(value)) throw new ValidationError("Invalid MAC address", "INVALID_MAC");
|
|
285
|
+
}
|
|
286
|
+
function semver2(value) {
|
|
287
|
+
if (!isx.semver(value)) throw new ValidationError("Invalid Semantic Version", "INVALID_SEMVER");
|
|
288
|
+
}
|
|
289
|
+
function hexColor2(value) {
|
|
290
|
+
if (!isx.hexColor(value)) throw new ValidationError("Invalid hex color", "INVALID_HEX_COLOR");
|
|
291
|
+
}
|
|
292
|
+
function rgbColor2(value) {
|
|
293
|
+
if (!isx.rgbColor(value)) throw new ValidationError("Invalid RGB color", "INVALID_RGB_COLOR");
|
|
294
|
+
}
|
|
295
|
+
function hslColor2(value) {
|
|
296
|
+
if (!isx.hslColor(value)) throw new ValidationError("Invalid HSL color", "INVALID_HSL_COLOR");
|
|
297
|
+
}
|
|
298
|
+
function port2(value) {
|
|
299
|
+
if (!isx.port(value)) throw new ValidationError("Invalid port number", "INVALID_PORT");
|
|
300
|
+
}
|
|
301
|
+
function handle2(value) {
|
|
302
|
+
if (!isx.handle(value)) throw new ValidationError("Invalid handle", "INVALID_HANDLE");
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// src/assert/index.ts
|
|
306
|
+
var assert = {
|
|
307
|
+
email: email2,
|
|
308
|
+
url: url2,
|
|
309
|
+
password: password2,
|
|
310
|
+
uuid: uuid2,
|
|
311
|
+
ip: ip2,
|
|
312
|
+
json: json2,
|
|
313
|
+
ulid: ulid2,
|
|
314
|
+
cuid: cuid2,
|
|
315
|
+
mongodbId: mongodbId2,
|
|
316
|
+
creditCard: creditCard2,
|
|
317
|
+
currency: currency2,
|
|
318
|
+
iban: iban2,
|
|
319
|
+
fqdn: fqdn2,
|
|
320
|
+
macAddress: macAddress2,
|
|
321
|
+
semver: semver2,
|
|
322
|
+
hexColor: hexColor2,
|
|
323
|
+
rgbColor: rgbColor2,
|
|
324
|
+
hslColor: hslColor2,
|
|
325
|
+
port: port2,
|
|
326
|
+
handle: handle2
|
|
327
|
+
};
|
|
328
|
+
export {
|
|
329
|
+
ValidationError,
|
|
330
|
+
assert,
|
|
331
|
+
isx
|
|
332
|
+
};
|
|
333
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/regex/email.ts","../src/is/email.ts","../src/regex/url.ts","../src/is/url.ts","../src/is/password.ts","../src/regex/identifiers.ts","../src/is/uuid.ts","../src/is/ip.ts","../src/is/json.ts","../src/regex/modern-identifiers.ts","../src/is/ulid.ts","../src/is/cuid.ts","../src/is/mongodbId.ts","../src/is/creditCard.ts","../src/is/currency.ts","../src/is/iban.ts","../src/regex/extended.ts","../src/is/extended.ts","../src/is/index.ts","../src/errors/ValidationError.ts","../src/assert/email.ts","../src/assert/url.ts","../src/assert/password.ts","../src/assert/uuid.ts","../src/assert/ip.ts","../src/assert/json.ts","../src/assert/modern-identifiers.ts","../src/assert/extended.ts","../src/assert/index.ts"],"sourcesContent":["export const EMAIL_REGEX =\r\n /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$/;","import { EMAIL_REGEX } from \"../regex/email\";\r\n\r\nexport function email(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n if (value.length > 254) return false; // RFC-safe max length\r\n return EMAIL_REGEX.test(value);\r\n}\r\n\r\n\r\n","export const URL_REGEX =\r\n /^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3})|localhost)(:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$/i;\r\n","import { URL_REGEX } from \"../regex/url\";\r\n\r\nexport function url(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return URL_REGEX.test(value);\r\n}\r\n","export function password(value: unknown, options: { minLength?: number; requireSpecial?: boolean } = {}): value is string {\r\n if (typeof value !== \"string\") return false;\r\n const { minLength = 8, requireSpecial = false } = options;\r\n if (value.length < minLength) return false;\r\n if (requireSpecial && !/[!@#$%^&*(),.?\":{}|<>]/.test(value)) return false;\r\n return true;\r\n}\r\n","export const UUID_REGEX =\r\n /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\r\n\r\nexport const IPV4_REGEX =\r\n /^(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}$/;\r\n\r\nexport const IPV6_REGEX =\r\n /^(?:(?:[a-fA-F\\d]{1,4}:){7}(?:[a-fA-F\\d]{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\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,7}|:)))(?:%[0-9a-zA-Z]{1,})?$/;\r\n","import { UUID_REGEX } from \"../regex/identifiers\";\r\n\r\nexport function uuid(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return UUID_REGEX.test(value);\r\n}\r\n","import { IPV4_REGEX, IPV6_REGEX } from \"../regex/identifiers\";\r\n\r\nexport function ip(value: unknown, version?: 4 | 6): value is string {\r\n if (typeof value !== \"string\") return false;\r\n if (version === 4) return IPV4_REGEX.test(value);\r\n if (version === 6) return IPV6_REGEX.test(value);\r\n return IPV4_REGEX.test(value) || IPV6_REGEX.test(value);\r\n}\r\n","export function json(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n try {\r\n JSON.parse(value);\r\n return true;\r\n } catch {\r\n return false;\r\n }\r\n}\r\n","export const ULID_REGEX = /^[0-9A-HJKMNPQRSTVWXYZ]{26}$/i;\r\nexport const CUID_REGEX = /^c[a-z0-9]{24}$/;\r\nexport const MONGODB_ID_REGEX = /^[a-f\\d]{24}$/i;\r\n","import { ULID_REGEX } from \"../regex/modern-identifiers\";\r\n\r\nexport function ulid(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return ULID_REGEX.test(value);\r\n}\r\n","import { CUID_REGEX } from \"../regex/modern-identifiers\";\r\n\r\nexport function cuid(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return CUID_REGEX.test(value);\r\n}\r\n","import { MONGODB_ID_REGEX } from \"../regex/modern-identifiers\";\r\n\r\nexport function mongodbId(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return MONGODB_ID_REGEX.test(value);\r\n}\r\n","export function creditCard(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n const sanitized = value.replace(/[- ]/g, \"\");\r\n if (!/^\\d{13,19}$/.test(sanitized)) return false;\r\n\r\n let sum = 0;\r\n let shouldDouble = false;\r\n for (let i = sanitized.length - 1; i >= 0; i--) {\r\n let digit = parseInt(sanitized.charAt(i), 10);\r\n if (shouldDouble) {\r\n digit *= 2;\r\n if (digit > 9) digit -= 9;\r\n }\r\n sum += digit;\r\n shouldDouble = !shouldDouble;\r\n }\r\n return sum % 10 === 0;\r\n}\r\n","export const CURRENCY_CODES = new Set([\"USD\", \"EUR\", \"GBP\", \"JPY\", \"CNY\", \"INR\", \"CAD\", \"AUD\", \"CHF\", \"BTC\", \"ETH\"]); // Add more as needed\r\n\r\nexport function currency(value: unknown, codes: string[] | Set<string> = CURRENCY_CODES): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return codes instanceof Set ? codes.has(value.toUpperCase()) : codes.includes(value.toUpperCase());\r\n}\r\n","const IBAN_REGEX = /^[A-Z]{2}\\d{2}[A-Z\\d]{1,30}$/;\r\n\r\nexport function iban(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n const s = value.toUpperCase().replace(/ /g, \"\");\r\n if (!IBAN_REGEX.test(s)) return false;\r\n\r\n // Basic validation without full checksum for now, can be expanded\r\n return true;\r\n}\r\n","export const FQDN_REGEX = /^(?!:\\/\\/)(?:[a-zA-Z0-9-]{1,63}\\.)+[a-zA-Z]{2,63}$/;\r\nexport const MAC_REGEX = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/;\r\nexport const SEMVER_REGEX = /^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$/;\r\nexport const HEX_COLOR_REGEX = /^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;\r\nexport const RGB_COLOR_REGEX = /^rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)(?:,\\s*(\\d*(?:\\.\\d+)?))?\\)$/i;\r\nexport const HSL_COLOR_REGEX = /^hsla?\\((\\d+),\\s*([\\d.]+)%,\\s*([\\d.]+)%(?:,\\s*(\\d*(?:\\.\\d+)?))?\\)$/i;\r\n","import { FQDN_REGEX, MAC_REGEX, SEMVER_REGEX, HEX_COLOR_REGEX, RGB_COLOR_REGEX, HSL_COLOR_REGEX } from \"../regex/extended\";\r\n\r\nexport function fqdn(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return FQDN_REGEX.test(value);\r\n}\r\n\r\nexport function macAddress(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return MAC_REGEX.test(value);\r\n}\r\n\r\nexport function semver(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return SEMVER_REGEX.test(value);\r\n}\r\n\r\nexport function hexColor(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return HEX_COLOR_REGEX.test(value);\r\n}\r\n\r\nexport function rgbColor(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return RGB_COLOR_REGEX.test(value);\r\n}\r\n\r\nexport function hslColor(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return HSL_COLOR_REGEX.test(value);\r\n}\r\n\r\nexport function port(value: unknown): value is number {\r\n if (typeof value !== \"number\" || isNaN(value)) return false;\r\n return value >= 0 && value <= 65535;\r\n}\r\n\r\nexport function handle(value: unknown): value is string {\r\n if (typeof value !== \"string\") return false;\r\n return /^@[a-z0-9_]{1,30}$/i.test(value);\r\n}\r\n\r\n","import { email } from \"./email\";\r\nimport { url } from \"./url\";\r\nimport { password } from \"./password\";\r\nimport { uuid } from \"./uuid\";\r\nimport { ip } from \"./ip\";\r\nimport { json } from \"./json\";\r\nimport { ulid } from \"./ulid\";\r\nimport { cuid } from \"./cuid\";\r\nimport { mongodbId } from \"./mongodbId\";\r\nimport { creditCard } from \"./creditCard\";\r\nimport { currency } from \"./currency\";\r\nimport { iban } from \"./iban\";\r\nimport {\r\n fqdn,\r\n macAddress,\r\n semver,\r\n hexColor,\r\n rgbColor,\r\n hslColor,\r\n port,\r\n handle,\r\n} from \"./extended\";\r\n\r\nexport const isx = {\r\n email,\r\n url,\r\n password,\r\n uuid,\r\n ip,\r\n json,\r\n ulid,\r\n cuid,\r\n mongodbId,\r\n creditCard,\r\n currency,\r\n iban,\r\n fqdn,\r\n macAddress,\r\n semver,\r\n hexColor,\r\n rgbColor,\r\n hslColor,\r\n port,\r\n handle,\r\n};\r\n","export class ValidationError extends Error {\r\n readonly code: string;\r\n\r\n constructor(message: string, code = \"INVALID_VALUE\") {\r\n super(message);\r\n this.name = \"ValidationError\";\r\n this.code = code;\r\n }\r\n}","import { isx } from \"../is\";\r\nimport { ValidationError } from \"../errors/ValidationError\";\r\n\r\nexport function email(value: unknown): asserts value is string {\r\n if (!isx.email(value)) {\r\n throw new ValidationError(\r\n \"Invalid email address\",\r\n \"INVALID_EMAIL\"\r\n );\r\n }\r\n}","import { isx } from \"../is\";\r\nimport { ValidationError } from \"../errors/ValidationError\";\r\n\r\nexport function url(value: unknown): asserts value is string {\r\n if (!isx.url(value)) {\r\n throw new ValidationError(\r\n \"Invalid URL\",\r\n \"INVALID_URL\"\r\n );\r\n }\r\n}\r\n","import { isx } from \"../is\";\r\nimport { ValidationError } from \"../errors/ValidationError\";\r\n\r\nexport function password(value: unknown, options?: { minLength?: number; requireSpecial?: boolean }): asserts value is string {\r\n if (!isx.password(value, options)) {\r\n throw new ValidationError(\r\n \"Invalid password\",\r\n \"INVALID_PASSWORD\"\r\n );\r\n }\r\n}\r\n","import { isx } from \"../is\";\r\nimport { ValidationError } from \"../errors/ValidationError\";\r\n\r\nexport function uuid(value: unknown): asserts value is string {\r\n if (!isx.uuid(value)) {\r\n throw new ValidationError(\r\n \"Invalid UUID\",\r\n \"INVALID_UUID\"\r\n );\r\n }\r\n}\r\n","import { isx } from \"../is\";\r\nimport { ValidationError } from \"../errors/ValidationError\";\r\n\r\nexport function ip(value: unknown, version?: 4 | 6): asserts value is string {\r\n if (!isx.ip(value, version)) {\r\n throw new ValidationError(\r\n `Invalid IPv${version || \"any\"} address`,\r\n \"INVALID_IP\"\r\n );\r\n }\r\n}\r\n","import { isx } from \"../is\";\r\nimport { ValidationError } from \"../errors/ValidationError\";\r\n\r\nexport function json(value: unknown): asserts value is string {\r\n if (!isx.json(value)) {\r\n throw new ValidationError(\r\n \"Invalid JSON string\",\r\n \"INVALID_JSON\"\r\n );\r\n }\r\n}\r\n","import { isx } from \"../is\";\r\nimport { ValidationError } from \"../errors/ValidationError\";\r\n\r\nexport function ulid(value: unknown): asserts value is string {\r\n if (!isx.ulid(value)) {\r\n throw new ValidationError(\"Invalid ULID\", \"INVALID_ULID\");\r\n }\r\n}\r\n\r\nexport function cuid(value: unknown): asserts value is string {\r\n if (!isx.cuid(value)) {\r\n throw new ValidationError(\"Invalid CUID\", \"INVALID_CUID\");\r\n }\r\n}\r\n\r\nexport function mongodbId(value: unknown): asserts value is string {\r\n if (!isx.mongodbId(value)) {\r\n throw new ValidationError(\"Invalid MongoDB ID\", \"INVALID_MONGODB_ID\");\r\n }\r\n}\r\n","import { isx } from \"../is\";\r\nimport { ValidationError } from \"../errors/ValidationError\";\r\n\r\nexport function creditCard(value: unknown): asserts value is string {\r\n if (!isx.creditCard(value)) throw new ValidationError(\"Invalid credit card\", \"INVALID_CREDIT_CARD\");\r\n}\r\n\r\nexport function currency(value: unknown, codes?: string[] | Set<string>): asserts value is string {\r\n if (!isx.currency(value, codes)) throw new ValidationError(\"Invalid currency code\", \"INVALID_CURRENCY\");\r\n}\r\n\r\nexport function iban(value: unknown): asserts value is string {\r\n if (!isx.iban(value)) throw new ValidationError(\"Invalid IBAN\", \"INVALID_IBAN\");\r\n}\r\n\r\nexport function fqdn(value: unknown): asserts value is string {\r\n if (!isx.fqdn(value)) throw new ValidationError(\"Invalid FQDN\", \"INVALID_FQDN\");\r\n}\r\n\r\nexport function macAddress(value: unknown): asserts value is string {\r\n if (!isx.macAddress(value)) throw new ValidationError(\"Invalid MAC address\", \"INVALID_MAC\");\r\n}\r\n\r\nexport function semver(value: unknown): asserts value is string {\r\n if (!isx.semver(value)) throw new ValidationError(\"Invalid Semantic Version\", \"INVALID_SEMVER\");\r\n}\r\n\r\nexport function hexColor(value: unknown): asserts value is string {\r\n if (!isx.hexColor(value)) throw new ValidationError(\"Invalid hex color\", \"INVALID_HEX_COLOR\");\r\n}\r\n\r\nexport function rgbColor(value: unknown): asserts value is string {\r\n if (!isx.rgbColor(value)) throw new ValidationError(\"Invalid RGB color\", \"INVALID_RGB_COLOR\");\r\n}\r\n\r\nexport function hslColor(value: unknown): asserts value is string {\r\n if (!isx.hslColor(value)) throw new ValidationError(\"Invalid HSL color\", \"INVALID_HSL_COLOR\");\r\n}\r\n\r\nexport function port(value: unknown): asserts value is number {\r\n if (!isx.port(value)) throw new ValidationError(\"Invalid port number\", \"INVALID_PORT\");\r\n}\r\n\r\nexport function handle(value: unknown): asserts value is string {\r\n if (!isx.handle(value)) throw new ValidationError(\"Invalid handle\", \"INVALID_HANDLE\");\r\n}\r\n","import { email } from \"./email\";\r\nimport { url } from \"./url\";\r\nimport { password } from \"./password\";\r\nimport { uuid } from \"./uuid\";\r\nimport { ip } from \"./ip\";\r\nimport { json } from \"./json\";\r\nimport { ulid, cuid, mongodbId } from \"./modern-identifiers\";\r\nimport {\r\n creditCard,\r\n currency,\r\n iban,\r\n fqdn,\r\n macAddress,\r\n semver,\r\n hexColor,\r\n rgbColor,\r\n hslColor,\r\n port,\r\n handle,\r\n} from \"./extended\";\r\n\r\nexport const assert = {\r\n email,\r\n url,\r\n password,\r\n uuid,\r\n ip,\r\n json,\r\n ulid,\r\n cuid,\r\n mongodbId,\r\n creditCard,\r\n currency,\r\n iban,\r\n fqdn,\r\n macAddress,\r\n semver,\r\n hexColor,\r\n rgbColor,\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,OAAyC;AAC5D,MAAI,CAAC,IAAI,OAAO,KAAK,EAAG,OAAM,IAAI,gBAAgB,kBAAkB,gBAAgB;AACxF;;;ACxBO,IAAM,SAAS;AAAA,EACpB,OAAAC;AAAA,EACA,KAAAC;AAAA,EACA,UAAAC;AAAA,EACA,MAAAC;AAAA,EACA,IAAAC;AAAA,EACA,MAAAC;AAAA,EACA,MAAAC;AAAA,EACA,MAAAC;AAAA,EACA,WAAAC;AAAA,EACA,YAAAC;AAAA,EACA,UAAAC;AAAA,EACA,MAAAC;AAAA,EACA,MAAAC;AAAA,EACA,YAAAC;AAAA,EACA,QAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,MAAAC;AAAA,EACA,QAAAC;AACF;","names":["email","url","password","uuid","ip","json","ulid","cuid","mongodbId","creditCard","currency","iban","fqdn","macAddress","semver","hexColor","rgbColor","hslColor","port","handle","email","url","password","uuid","ip","json","ulid","cuid","mongodbId","creditCard","currency","iban","fqdn","macAddress","semver","hexColor","rgbColor","hslColor","port","handle"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "isx-intent",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Tiny, intent-based string validation for JavaScript & TypeScript",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/HirenTumbadiya/isx"
|
|
8
|
+
},
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/HirenTumbadiya/isx/issues"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/HirenTumbadiya/isx#readme",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsup",
|
|
18
|
+
"dev": "tsup --watch",
|
|
19
|
+
"test": "vitest",
|
|
20
|
+
"prepublishOnly": "npm run build"
|
|
21
|
+
},
|
|
22
|
+
"main": "./dist/index.cjs",
|
|
23
|
+
"module": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"require": "./dist/index.cjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"keywords": [
|
|
36
|
+
"validation",
|
|
37
|
+
"regex",
|
|
38
|
+
"typescript",
|
|
39
|
+
"frontend",
|
|
40
|
+
"backend"
|
|
41
|
+
],
|
|
42
|
+
"author": "Hiren Tumbadiya",
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"tsup": "^8.5.1",
|
|
45
|
+
"typescript": "^5.9.3",
|
|
46
|
+
"vitest": "^4.0.16"
|
|
47
|
+
}
|
|
48
|
+
}
|