@conform-to/yup
Advanced tools
Comparing version 1.1.0-pre.0 to 1.1.0
@@ -1,4 +0,4 @@ | ||
import { type Constraint, type Intent, type Submission } from '@conform-to/dom'; | ||
import { type Intent, type Submission } from '@conform-to/dom'; | ||
import * as yup from 'yup'; | ||
export declare function getYupConstraint<Source extends yup.AnyObjectSchema>(source: Source): Record<string, Constraint>; | ||
export { getYupConstraint } from './constraint'; | ||
export declare function parseWithYup<Schema extends yup.AnyObjectSchema>(payload: FormData | URLSearchParams, config: { | ||
@@ -5,0 +5,0 @@ schema: Schema | ((intent: Intent | null) => Schema); |
72
index.js
@@ -7,2 +7,3 @@ 'use strict'; | ||
var yup = require('yup'); | ||
var constraint = require('./constraint.js'); | ||
@@ -29,71 +30,2 @@ function _interopNamespace(e) { | ||
function getYupConstraint(source) { | ||
var description = source.describe(); | ||
return Object.fromEntries(Object.entries(description.fields).map(_ref => { | ||
var _test$params, _test$params3, _test$params5, _test$params6, _test$params8; | ||
var [key, def] = _ref; | ||
var constraint = {}; | ||
switch (def.type) { | ||
case 'string': | ||
{ | ||
for (var test of def.tests) { | ||
switch (test.name) { | ||
case 'required': | ||
constraint.required = true; | ||
break; | ||
case 'min': | ||
if (!constraint.minLength || constraint.minLength < Number((_test$params = test.params) === null || _test$params === void 0 ? void 0 : _test$params.min)) { | ||
var _test$params2; | ||
constraint.minLength = Number((_test$params2 = test.params) === null || _test$params2 === void 0 ? void 0 : _test$params2.min); | ||
} | ||
break; | ||
case 'max': | ||
if (!constraint.maxLength || constraint.maxLength > Number((_test$params3 = test.params) === null || _test$params3 === void 0 ? void 0 : _test$params3.max)) { | ||
var _test$params4; | ||
constraint.maxLength = Number((_test$params4 = test.params) === null || _test$params4 === void 0 ? void 0 : _test$params4.max); | ||
} | ||
break; | ||
case 'matches': | ||
if (!constraint.pattern && ((_test$params5 = test.params) === null || _test$params5 === void 0 ? void 0 : _test$params5.regex) instanceof RegExp) { | ||
constraint.pattern = test.params.regex.source; | ||
} | ||
break; | ||
} | ||
} | ||
if (!constraint.pattern && def.oneOf.length > 0) { | ||
constraint.pattern = def.oneOf.join('|'); | ||
} | ||
break; | ||
} | ||
case 'number': | ||
for (var _test of def.tests) { | ||
switch (_test.name) { | ||
case 'required': | ||
constraint.required = true; | ||
break; | ||
case 'min': | ||
if (typeof constraint.min === 'string') { | ||
throw new Error('min should not be a string'); | ||
} | ||
if (!constraint.min || constraint.min < Number((_test$params6 = _test.params) === null || _test$params6 === void 0 ? void 0 : _test$params6.min)) { | ||
var _test$params7; | ||
constraint.min = Number((_test$params7 = _test.params) === null || _test$params7 === void 0 ? void 0 : _test$params7.min); | ||
} | ||
break; | ||
case 'max': | ||
if (typeof constraint.max === 'string') { | ||
throw new Error('max should not be a number'); | ||
} | ||
if (!constraint.max || constraint.max > Number((_test$params8 = _test.params) === null || _test$params8 === void 0 ? void 0 : _test$params8.max)) { | ||
var _test$params9; | ||
constraint.max = Number((_test$params9 = _test.params) === null || _test$params9 === void 0 ? void 0 : _test$params9.max); | ||
} | ||
break; | ||
} | ||
} | ||
break; | ||
} | ||
return [key, constraint]; | ||
})); | ||
} | ||
function parseWithYup(payload, config) { | ||
@@ -136,3 +68,3 @@ return dom.parse(payload, { | ||
exports.getYupConstraint = getYupConstraint; | ||
exports.getYupConstraint = constraint.getYupConstraint; | ||
exports.parseWithYup = parseWithYup; |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "1.1.0-pre.0", | ||
"version": "1.1.0", | ||
"main": "index.js", | ||
@@ -29,3 +29,3 @@ "module": "index.mjs", | ||
"peerDependencies": { | ||
"@conform-to/dom": "1.1.0-pre.0", | ||
"@conform-to/dom": "1.1.0", | ||
"yup": ">=0.32.0" | ||
@@ -32,0 +32,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
19923
9
493
0
2