@naturalcycles/nodejs-lib 15.52.0 → 15.53.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.
@@ -114,6 +114,7 @@ export declare class JsonSchemaStringBuilder<IN extends string = string, OUT = I
114
114
  */
115
115
  ianaTimezone(): JsonSchemaEnumBuilder<string | IANATimezone, IANATimezone, false>;
116
116
  base64Url(): this;
117
+ uuid(): this;
117
118
  }
118
119
  export interface JsonSchemaStringEmailOptions {
119
120
  checkTLD: boolean;
@@ -5,7 +5,7 @@ import { _uniq } from '@naturalcycles/js-lib/array';
5
5
  import { _assert } from '@naturalcycles/js-lib/error';
6
6
  import { _deepCopy, _sortObject } from '@naturalcycles/js-lib/object';
7
7
  import { _objectAssign, JWT_REGEX, } from '@naturalcycles/js-lib/types';
8
- import { BASE64URL_REGEX, COUNTRY_CODE_REGEX, CURRENCY_REGEX, IPV4_REGEX, IPV6_REGEX, LANGUAGE_TAG_REGEX, SEMVER_REGEX, SLUG_REGEX, } from '../regexes.js';
8
+ import { BASE64URL_REGEX, COUNTRY_CODE_REGEX, CURRENCY_REGEX, IPV4_REGEX, IPV6_REGEX, LANGUAGE_TAG_REGEX, SEMVER_REGEX, SLUG_REGEX, UUID_REGEX, } from '../regexes.js';
9
9
  import { TIMEZONES } from '../timezones.js';
10
10
  import { isEveryItemNumber, isEveryItemPrimitive, isEveryItemString, JSON_SCHEMA_ORDER, mergeJsonSchemaObjects, } from './jsonSchemaBuilder.util.js';
11
11
  export const j = {
@@ -325,6 +325,9 @@ export class JsonSchemaStringBuilder extends JsonSchemaAnyBuilder {
325
325
  msg: 'contains characters not allowed in Base64 URL characterset',
326
326
  });
327
327
  }
328
+ uuid() {
329
+ return this.regex(UUID_REGEX, { msg: 'is an invalid UUID' });
330
+ }
328
331
  }
329
332
  export class JsonSchemaIsoDateBuilder extends JsonSchemaAnyBuilder {
330
333
  constructor() {
@@ -1,6 +1,7 @@
1
1
  export declare const BASE62_REGEX: RegExp;
2
2
  export declare const BASE64_REGEX: RegExp;
3
3
  export declare const BASE64URL_REGEX: RegExp;
4
+ export declare const UUID_REGEX: RegExp;
4
5
  export declare const COUNTRY_CODE_REGEX: RegExp;
5
6
  export declare const CURRENCY_REGEX: RegExp;
6
7
  /**
@@ -1,6 +1,8 @@
1
1
  export const BASE62_REGEX = /^[a-zA-Z0-9]+$/;
2
2
  export const BASE64_REGEX = /^[a-zA-Z0-9+/]+={0,2}$/;
3
3
  export const BASE64URL_REGEX = /^[a-zA-Z0-9_-]+$/;
4
+ // from `ajv-formats`
5
+ export const UUID_REGEX = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
4
6
  export const COUNTRY_CODE_REGEX = /^[A-Z]{2}$/;
5
7
  export const CURRENCY_REGEX = /^[A-Z]{3}$/;
6
8
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
3
  "type": "module",
4
- "version": "15.52.0",
4
+ "version": "15.53.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@types/js-yaml": "^4",
@@ -35,6 +35,7 @@ import {
35
35
  LANGUAGE_TAG_REGEX,
36
36
  SEMVER_REGEX,
37
37
  SLUG_REGEX,
38
+ UUID_REGEX,
38
39
  } from '../regexes.js'
39
40
  import { TIMEZONES } from '../timezones.js'
40
41
  import {
@@ -457,6 +458,10 @@ export class JsonSchemaStringBuilder<
457
458
  msg: 'contains characters not allowed in Base64 URL characterset',
458
459
  })
459
460
  }
461
+
462
+ uuid(): this {
463
+ return this.regex(UUID_REGEX, { msg: 'is an invalid UUID' })
464
+ }
460
465
  }
461
466
 
462
467
  export interface JsonSchemaStringEmailOptions {
@@ -1,6 +1,8 @@
1
1
  export const BASE62_REGEX = /^[a-zA-Z0-9]+$/
2
2
  export const BASE64_REGEX = /^[a-zA-Z0-9+/]+={0,2}$/
3
3
  export const BASE64URL_REGEX = /^[a-zA-Z0-9_-]+$/
4
+ // from `ajv-formats`
5
+ export const UUID_REGEX = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i
4
6
  export const COUNTRY_CODE_REGEX = /^[A-Z]{2}$/
5
7
  export const CURRENCY_REGEX = /^[A-Z]{3}$/
6
8
  /**