ajv-keywords
Advanced tools
Comparing version 4.0.0-beta.2 to 4.0.0-beta.3
import type { CodeKeywordDefinition } from "ajv"; | ||
export default function getDef(): CodeKeywordDefinition; | ||
declare type TransformName = "trimStart" | "trimEnd" | "trimLeft" | "trimRight" | "trim" | "toLowerCase" | "toUpperCase" | "toEnumCase"; | ||
interface TransformConfig { | ||
hash: Record<string, string | undefined>; | ||
} | ||
declare type Transform = (s: string, cfg?: TransformConfig) => string; | ||
declare const transform: { | ||
[key in TransformName]: Transform; | ||
}; | ||
declare const getDef: (() => CodeKeywordDefinition) & { | ||
transform: typeof transform; | ||
}; | ||
export default getDef; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ajv_1 = require("ajv"); | ||
const codegen_1 = require("ajv/dist/compile/codegen"); | ||
const transform = { | ||
@@ -14,3 +15,4 @@ trimStart: (s) => s.trimStart(), | ||
}; | ||
function getDef() { | ||
const getDef = Object.assign(_getDef, { transform }); | ||
function _getDef() { | ||
return { | ||
@@ -41,3 +43,6 @@ keyword: "transform", | ||
throw new Error(`transform: unknown transformation ${t}`); | ||
const func = gen.scopeValue("func", { ref: transform[t] }); | ||
const func = gen.scopeValue("func", { | ||
ref: transform[t], | ||
code: ajv_1._ `require("ajv-keywords/dist/definitions/transform").transform${codegen_1.getProperty(t)}` | ||
}); | ||
const arg = transformExpr(ts); | ||
@@ -53,3 +58,2 @@ return cfg && t === "toEnumCase" ? ajv_1._ `${func}(${arg}, ${cfg})` : ajv_1._ `${func}(${arg})`; | ||
} | ||
exports.default = getDef; | ||
function getEnumCaseCfg(parentSchema) { | ||
@@ -76,3 +80,4 @@ // build hash table to enum values | ||
} | ||
exports.default = getDef; | ||
module.exports = getDef; | ||
//# sourceMappingURL=transform.js.map |
{ | ||
"name": "ajv-keywords", | ||
"version": "4.0.0-beta.2", | ||
"version": "4.0.0-beta.3", | ||
"description": "Custom JSON-Schema keywords for Ajv validator", | ||
@@ -12,4 +12,4 @@ "main": "dist/index.js", | ||
"prettier:check": "prettier --list-different \"./**/*.{md,json,yaml,js,ts}\"", | ||
"test": "npm run build && npm run eslint && npm run test-cov", | ||
"eslint": "eslint \"src/**/*.*s\" \"spec/**/*.*s\" --ignore-pattern dotjs", | ||
"test": "npm link && npm link ajv-keywords && npm run eslint && npm run test-cov", | ||
"eslint": "eslint \"src/**/*.*s\" \"spec/**/*.*s\"", | ||
"test-spec": "jest spec/*.ts", | ||
@@ -39,3 +39,3 @@ "test-cov": "jest spec/*.ts --coverage" | ||
"peerDependencies": { | ||
"ajv": "^7.0.0-beta.6" | ||
"ajv": "^7.0.0-beta.8" | ||
}, | ||
@@ -49,3 +49,3 @@ "devDependencies": { | ||
"@typescript-eslint/parser": "^4.4.1", | ||
"ajv": "^7.0.0-beta.6", | ||
"ajv": "^7.0.0-beta.8", | ||
"ajv-formats": "^0.3.4", | ||
@@ -52,0 +52,0 @@ "chai": "^4.2.0", |
@@ -5,8 +5,7 @@ # ajv-keywords | ||
[![Build Status](https://travis-ci.org/ajv-validator/ajv-keywords.svg?branch=master)](https://travis-ci.org/ajv-validator/ajv-keywords) | ||
[![build](https://github.com/ajv-validator/ajv-keywords/workflows/build/badge.svg)](https://github.com/ajv-validator/ajv-keywords/actions?query=workflow%3Abuild) | ||
[![npm](https://img.shields.io/npm/v/ajv-keywords.svg)](https://www.npmjs.com/package/ajv-keywords) | ||
[![npm (beta)](https://img.shields.io/npm/v/ajv-keywords/beta)](https://www.npmjs.com/package/ajv-keywords/v/4.0.0-beta.1) | ||
[![npm (beta)](https://img.shields.io/npm/v/ajv-keywords/beta)](https://www.npmjs.com/package/ajv-keywords/v/4.0.0-beta.3) | ||
[![npm downloads](https://img.shields.io/npm/dm/ajv-keywords.svg)](https://www.npmjs.com/package/ajv-keywords) | ||
[![Coverage Status](https://coveralls.io/repos/github/ajv-validator/ajv-keywords/badge.svg?branch=master)](https://coveralls.io/github/ajv-validator/ajv-keywords?branch=master) | ||
[![Dependabot](https://api.dependabot.com/badges/status?host=github&repo=ajv-validator/ajv-keywords)](https://app.dependabot.com/accounts/ajv-validator/repos/60477053) | ||
[![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv) | ||
@@ -23,3 +22,3 @@ | ||
- [typeof](#typeof) | ||
- [instanceof](#instanceof) | ||
- [instanceof](#instanceof)<sup>\+</sup> | ||
- [Keywords for numbers](#keywords-for-numbers) | ||
@@ -31,3 +30,3 @@ - [range and exclusiveRange](#range-and-exclusiverange) | ||
- [Keywords for arrays](#keywords-for-arrays) | ||
- [uniqueItemProperties](#uniqueitemproperties) | ||
- [uniqueItemProperties](#uniqueitemproperties)<sup>\+</sup> | ||
- [Keywords for objects](#keywords-for-objects) | ||
@@ -41,3 +40,3 @@ - [allRequired](#allrequired) | ||
- [deepRequired](#deeprequired) | ||
- [dynamicDefaults](#dynamicdefaults)<sup>\*</sup> | ||
- [dynamicDefaults](#dynamicdefaults)<sup>\*</sup><sup>\+</sup> | ||
- [Keywords for all types](#keywords-for-all-types) | ||
@@ -50,2 +49,3 @@ - [select/selectCases/selectDefault](#selectselectcasesselectdefault) | ||
<sup>\*</sup> - keywords that modify data | ||
<sup>\+</sup> - keywords that are not supported in [standalone validation code](https://github.com/ajv-validator/ajv/blob/master/docs/standalone.md) | ||
@@ -157,2 +157,4 @@ ## Install | ||
**Please note**: currently `instanceof` is not supported in [standalone validation code](https://github.com/ajv-validator/ajv/blob/master/docs/standalone.md) - it has to be implemented as [`code` keyword](https://github.com/ajv-validator/ajv/blob/master/docs/keywords.md#define-keyword-with-code-generation-function) to support it (PR is welcome). | ||
### Keywords for numbers | ||
@@ -305,2 +307,4 @@ | ||
**Please note**: currently `uniqueItemProperties` is not supported in [standalone validation code](https://github.com/ajv-validator/ajv/blob/master/docs/standalone.md) - it has to be implemented as [`code` keyword](https://github.com/ajv-validator/ajv/blob/master/docs/keywords.md#define-keyword-with-code-generation-function) to support it (PR is welcome). | ||
### Keywords for objects | ||
@@ -731,4 +735,6 @@ | ||
**Please note**: dynamic default functions differented by the number of parameters they have (`function.length`). Functions that do not expect default must have one non-optional argument so that `function.length` > 0. | ||
**Please note**: dynamic default functions are differentiated by the number of parameters they have (`function.length`). Functions that do not expect default must have one non-optional argument so that `function.length` > 0. | ||
`dynamicDefaults` is not supported in [standalone validation code](https://github.com/ajv-validator/ajv/blob/master/docs/standalone.md). | ||
## Security contact | ||
@@ -735,0 +741,0 @@ |
import type {CodeKeywordDefinition, AnySchemaObject, KeywordCxt, Code, Name} from "ajv" | ||
import {_, stringify} from "ajv" | ||
import {getProperty} from "ajv/dist/compile/codegen" | ||
@@ -31,3 +32,7 @@ type TransformName = | ||
export default function getDef(): CodeKeywordDefinition { | ||
const getDef: (() => CodeKeywordDefinition) & { | ||
transform: typeof transform | ||
} = Object.assign(_getDef, {transform}) | ||
function _getDef(): CodeKeywordDefinition { | ||
return { | ||
@@ -56,3 +61,6 @@ keyword: "transform", | ||
if (!(t in transform)) throw new Error(`transform: unknown transformation ${t}`) | ||
const func = gen.scopeValue("func", {ref: transform[t as TransformName]}) | ||
const func = gen.scopeValue("func", { | ||
ref: transform[t as TransformName], | ||
code: _`require("ajv-keywords/dist/definitions/transform").transform${getProperty(t)}` | ||
}) | ||
const arg = transformExpr(ts) | ||
@@ -92,2 +100,3 @@ return cfg && t === "toEnumCase" ? _`${func}(${arg}, ${cfg})` : _`${func}(${arg})` | ||
export default getDef | ||
module.exports = getDef |
Sorry, the diff of this file is not supported yet
129091
1911
747