simple-validators
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -28,2 +28,1 @@ "use strict"; | ||
Object.defineProperty(exports, "filterKeys", { enumerable: true, get: function () { return validators_1.filterKeys; } }); | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=types.js.map |
@@ -33,2 +33,1 @@ "use strict"; | ||
exports.formatDate = formatDate; | ||
//# sourceMappingURL=utils.js.map |
@@ -235,7 +235,10 @@ "use strict"; | ||
function validateKeys(input, keys, opts) { | ||
var _a; | ||
const value = {}; | ||
let required = keys.required || []; | ||
const aliasKeys = Object.keys((_a = keys.alias) !== null && _a !== void 0 ? _a : {}); | ||
const optional = keys.optional || []; | ||
const ignored = []; | ||
Object.keys(input).forEach((k) => { | ||
var _a; | ||
if (required.includes(k) || optional.includes(k)) { | ||
@@ -245,2 +248,12 @@ value[k] = input[k]; | ||
} | ||
else if (aliasKeys.includes(k)) { | ||
const normalized = (_a = keys.alias) === null || _a === void 0 ? void 0 : _a[k]; | ||
if (input[normalized] === undefined) { | ||
value[normalized] = input[k]; | ||
required = required.filter((val) => val !== normalized); | ||
} | ||
else { | ||
validationWarning(`both "${normalized}" and "${k}" were provided, "${k}" was ignored.`, opts); | ||
} | ||
} | ||
else { | ||
@@ -304,2 +317,1 @@ ignored.push(k); | ||
exports.filterKeys = filterKeys; | ||
//# sourceMappingURL=validators.js.map |
export { getDate, formatDate } from './utils'; | ||
export { defined, locationSuffix, incrementOptions, validationError, validationWarning, validateBoolean, validateString, validateNumber, validateUrl, validateSubdomain, validateEmail, validateChoice, validateEnum, validateDate, validateObject, validateKeys, validateObjectKeys, validateList, fillMissingKeys, filterKeys, } from './validators'; | ||
//# sourceMappingURL=index.js.map |
export {}; | ||
//# sourceMappingURL=types.js.map |
@@ -28,2 +28,1 @@ export function getDate(object) { | ||
} | ||
//# sourceMappingURL=utils.js.map |
@@ -217,7 +217,10 @@ import { formatDate } from './utils'; | ||
export function validateKeys(input, keys, opts) { | ||
var _a; | ||
const value = {}; | ||
let required = keys.required || []; | ||
const aliasKeys = Object.keys((_a = keys.alias) !== null && _a !== void 0 ? _a : {}); | ||
const optional = keys.optional || []; | ||
const ignored = []; | ||
Object.keys(input).forEach((k) => { | ||
var _a; | ||
if (required.includes(k) || optional.includes(k)) { | ||
@@ -227,2 +230,12 @@ value[k] = input[k]; | ||
} | ||
else if (aliasKeys.includes(k)) { | ||
const normalized = (_a = keys.alias) === null || _a === void 0 ? void 0 : _a[k]; | ||
if (input[normalized] === undefined) { | ||
value[normalized] = input[k]; | ||
required = required.filter((val) => val !== normalized); | ||
} | ||
else { | ||
validationWarning(`both "${normalized}" and "${k}" were provided, "${k}" was ignored.`, opts); | ||
} | ||
} | ||
else { | ||
@@ -281,2 +294,1 @@ ignored.push(k); | ||
} | ||
//# sourceMappingURL=validators.js.map |
export type { ValidationOptions, KeyOptions } from './types'; | ||
export { getDate, formatDate } from './utils'; | ||
export { defined, locationSuffix, incrementOptions, validationError, validationWarning, validateBoolean, validateString, validateNumber, validateUrl, validateSubdomain, validateEmail, validateChoice, validateEnum, validateDate, validateObject, validateKeys, validateObjectKeys, validateList, fillMissingKeys, filterKeys, } from './validators'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -23,1 +23,2 @@ declare type message = { | ||
export {}; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -7,1 +7,2 @@ export declare function getDate(object: undefined | Date | string | { | ||
}): string; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -99,2 +99,3 @@ import type { KeyOptions, ValidationOptions } from './types'; | ||
optional?: string[]; | ||
alias?: Record<string, string>; | ||
}, opts: KeyOptions): Record<string, any> | undefined; | ||
@@ -109,2 +110,3 @@ /** | ||
optional?: string[]; | ||
alias?: Record<string, string>; | ||
}, opts: KeyOptions): Record<string, any> | undefined; | ||
@@ -120,1 +122,2 @@ /** | ||
export declare function filterKeys(value: Record<string, any>, keys: string[]): Record<string, any>; | ||
//# sourceMappingURL=validators.d.ts.map |
{ | ||
"name": "simple-validators", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"license": "MIT", | ||
@@ -36,4 +36,3 @@ "description": "Schema validation functions and error reporting framework", | ||
"build:cjs": "tsc --project ./tsconfig.json --module commonjs --outDir dist/cjs", | ||
"declarations": "tsc --project ./tsconfig.json --declaration --emitDeclarationOnly --outDir dist/types", | ||
"prepublishOnly": "npm run build", | ||
"declarations": "tsc --project ./tsconfig.json --declaration --emitDeclarationOnly --declarationMap --outDir dist/types", | ||
"build": "npm-run-all -l clean -p build:cjs build:esm declarations" | ||
@@ -47,3 +46,3 @@ }, | ||
"eslint": "^8.21.0", | ||
"eslint-config-curvenote": "*", | ||
"eslint-config-curvenote": "latest", | ||
"jest": "28.1.3", | ||
@@ -50,0 +49,0 @@ "jest-extended": "^3.0.1", |
850
40885
18