UNPKG

@jirutka/ajv-cli

Version:

CLI for Ajv JSON Schema Validator with human-friendly error messages

35 lines 1.25 kB
import * as crypto from 'node:crypto'; import { glob } from './glob.js'; import reservedWords from './reserved-words.js'; export function arrify(value) { return (value == null ? [] : Array.isArray(value) ? value : [value]); } export function deepClone(input) { if (typeof input !== 'object' || input === null) { return input; } if (input instanceof Date) { return new Date(input.getTime()); } const cloned = Array.isArray(input) ? Array(input.length) : {}; for (const key in input) { const value = input[key]; cloned[key] = typeof value === 'object' && value !== null ? deepClone(value) : value; } return cloned; } export function expandFilePaths(args) { return arrify(args).flatMap(arg => glob(arg) ?? arg); } /** Sanitises `input` to be a valid JS identifier. */ export function sanitizeId(input) { const id = input.trim().replace(/\W+/g, '_'); return reservedWords.has(id) || /^\d/.test(id) ? `_${id}` : id; } export function sha1sum(data) { return crypto.createHash('sha1').update(JSON.stringify(data)).digest('hex'); } export function unescapeJsonPointer(pointer) { return pointer.replaceAll('~1', '/').replaceAll('~0', '~'); } //# sourceMappingURL=utils.js.map