Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

proy

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

proy - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

148

dist/cjs/index.js

@@ -1,6 +0,6 @@

'use strict'
'use strict';
Object.defineProperty(exports, '__esModule', { value: true })
Object.defineProperty(exports, '__esModule', { value: true });
var lib = {}
var lib = {};

@@ -12,13 +12,13 @@ /**

const isArray$3 = (val) => Array.isArray(val)
const isArray$3 = (val) => Array.isArray(val);
const isNumber$1 = (val) => typeof val === 'number' && !isNaN(val)
const isNumber$1 = (val) => typeof val === 'number' && !isNaN(val);
const isObject$2 = (val) => typeof val === 'object' && Object.prototype.toString.call(val) === '[object Object]'
const isObject$2 = (val) => typeof val === 'object' && Object.prototype.toString.call(val) === '[object Object]';
const isString$1 = (val) => typeof val === 'string'
const isString$1 = (val) => typeof val === 'string';
const isBoolean = (val) => typeof val === 'boolean'
const isBoolean = (val) => typeof val === 'boolean';
var basicType = { isArray: isArray$3, isNumber: isNumber$1, isObject: isObject$2, isString: isString$1, isBoolean }
var basicType = { isArray: isArray$3, isNumber: isNumber$1, isObject: isObject$2, isString: isString$1, isBoolean };

@@ -29,5 +29,5 @@ /**

const { isArray: isArray$2, isObject: isObject$1, isNumber, isString } = basicType
const { isArray: isArray$2, isObject: isObject$1, isNumber, isString } = basicType;
const normalEmpty = (val) => val === undefined || val === null
const normalEmpty = (val) => val === undefined || val === null;

@@ -41,7 +41,7 @@ const beRequired$1 = (val) => {

return false
}
};
var required = {
beRequired: beRequired$1,
}
};

@@ -53,9 +53,9 @@ /**

const verify = basicType
const { beRequired } = required
const verify = basicType;
const { beRequired } = required;
const resolveVerify = (type = 'string') => {
const verifyType = 'is' + type.charAt(0).toUpperCase() + type.slice(1)
const verifyType = 'is' + type.charAt(0).toUpperCase() + type.slice(1);
return verify[verifyType]
}
};

@@ -68,15 +68,15 @@ /**

const validateAction$1 = (prop, value, rules) => {
let rule = rules.get(prop)
let rule = rules.get(prop);
// if don't set rule should pass it
if (!rule) return true
rule = verify.isArray(rule) ? rule : [rule]
rule = verify.isArray(rule) ? rule : [rule];
return rule.map((item) => {
if (!item) return true
if (verify.isObject(item)) {
const verfiyFn = resolveVerify(item.type)
const rightType = verfiyFn(value)
const required = item.required || false
const hasValidateFn = typeof item.validate === 'function'
const validateFn = hasValidateFn && item.validate
const verfiyFn = resolveVerify(item.type);
const rightType = verfiyFn(value);
const required = item.required || false;
const hasValidateFn = typeof item.validate === 'function';
const validateFn = hasValidateFn && item.validate;
// if usr set required and type

@@ -92,18 +92,18 @@ if (rightType && required) {

})
}
};
var validateAction_1 = {
validateAction: validateAction$1,
}
};
const { validateAction } = validateAction_1
const { isArray: isArray$1 } = basicType
const { validateAction } = validateAction_1;
const { isArray: isArray$1 } = basicType;
const createSetter = (rules) => {
return function (target, prop, value, receiver) {
const res = validateAction(prop, value, rules)
const res = validateAction(prop, value, rules);
if (isArray$1(res)) {
const incorrectIdx = res.indexOf(false)
if (incorrectIdx !== -1) Reflect.set(target, `__incorrect__${prop}__Idx`, incorrectIdx, receiver)
const unPassed = res.includes(false)
const incorrectIdx = res.indexOf(false);
if (incorrectIdx !== -1) Reflect.set(target, `__incorrect__${prop}__Idx`, incorrectIdx, receiver);
const unPassed = res.includes(false);
if (unPassed) return Reflect.deleteProperty(target, prop)

@@ -117,3 +117,3 @@ return Reflect.set(target, prop, value, receiver)

}
}
};

@@ -123,7 +123,7 @@ const createProxy$1 = (source, rules) =>

set: createSetter(rules),
})
});
var createProxy_1 = {
createProxy: createProxy$1,
}
};

@@ -133,8 +133,8 @@ const getProxies$2 = (draft) => {

.filter((k) => k.includes('__incorrect__'))
.map((k) => delete draft[k])
.map((k) => delete draft[k]);
return draft
}
};
var getProxies_1 = { getProxies: getProxies$2 }
var getProxies_1 = { getProxies: getProxies$2 };

@@ -146,4 +146,4 @@ /**

const { isArray } = basicType
const { getProxies: getProxies$1 } = getProxies_1
const { isArray } = basicType;
const { getProxies: getProxies$1 } = getProxies_1;

@@ -158,7 +158,6 @@ class CallbackAction$1 {

disptach(draft, source, rules, callback) {
const VerfiedKeys = Object.keys(draft)
const unVerfiedKeys = Object.keys(source).filter((key) => !VerfiedKeys.includes(key))
const VerfiedKeys = Object.keys(draft);
const unVerfiedKeys = Object.keys(source).filter((key) => !VerfiedKeys.includes(key));
const unVerfiedRules = unVerfiedKeys.map((key) => rules.get(key));
const unVerfiedRules = unVerfiedKeys.map((key) => rules.get(key))
/**

@@ -172,32 +171,32 @@ * if have unVerfieKeys mean this rule is not pass validation .

*/
if (isArray(cur) && draft[`__incorrect__${unVerfiedKeys[idx]}__Idx`] !== -1) {
cur = cur[draft[`__incorrect__${unVerfiedKeys[idx]}__Idx`]]
cur = cur[draft[`__incorrect__${unVerfiedKeys[idx]}__Idx`]];
}
const errLog = cur.message ? cur.message : `${unVerfiedKeys[idx]} is not verified`;
const emitInfo = {
field: unVerfiedKeys[idx],
fieldValue: source[unVerfiedKeys[idx]],
type: cur.type,
errLog: `${unVerfiedKeys[idx]} is not verified`,
}
acc = acc.concat(emitInfo)
type: cur.type || 'string',
errLog,
};
acc = acc.concat(emitInfo);
return acc
}, [])
}, []);
// Reflect.deleteProperty(draft, '_incorrectIdx')
callback && callback(errors, getProxies$1(draft))
callback && callback(errors, getProxies$1(draft));
}
}
var callbackAction = { CallbackAction: CallbackAction$1 }
var callbackAction = { CallbackAction: CallbackAction$1 };
const { createProxy } = createProxy_1
const { isObject } = basicType
const { CallbackAction } = callbackAction
const { getProxies } = getProxies_1
const { createProxy } = createProxy_1;
const { isObject } = basicType;
const { CallbackAction } = callbackAction;
const { getProxies } = getProxies_1;
class Proy extends CallbackAction {
constructor() {
super()
this.rules = new Map()
this.proxies = new Map()
super();
this.rules = new Map();
this.proxies = new Map();
}

@@ -208,3 +207,6 @@ /**

validate(source, callback) {
const basic = Object.create(null)
// eslint-disable-next-line quotes
if (!source) throw Error("Can't configure a empty")
if (!isObject(source)) throw new Error('source msut be a object')
const basic = Object.create(null);
/**

@@ -214,6 +216,6 @@ * draft is a proxy object when source change

*/
const draft = createProxy(basic, this.rules)
Object.assign(draft, source)
Object.entries(draft).map(([key, poxis]) => this.proxies.set(key, poxis))
this.disptach(draft, source, this.rules, callback)
const draft = createProxy(basic, this.rules);
Object.assign(draft, source);
Object.entries(draft).map(([key, poxis]) => this.proxies.set(key, poxis));
this.disptach(draft, source, this.rules, callback);
return this

@@ -227,7 +229,7 @@ }

}
Object.entries(rules).map(([key, rule]) => this.rules.set(key, rule))
Object.entries(rules).map(([key, rule]) => this.rules.set(key, rule));
return this
}
produce() {
const proxies = getProxies(Object.fromEntries(this.proxies))
const proxies = getProxies(Object.fromEntries(this.proxies));
return proxies

@@ -237,13 +239,13 @@ }

const proy$1 = () => new Proy()
const proy$1 = () => new Proy();
var core = {
proy: proy$1,
}
};
const { proy } = core
const { proy } = core;
var proy_1 = (lib.proy = proy)
var proy_1 = lib.proy = proy;
exports['default'] = lib
exports.proy = proy_1
exports["default"] = lib;
exports.proy = proy_1;

@@ -146,3 +146,2 @@ var lib = {};

const unVerfiedKeys = Object.keys(source).filter((key) => !VerfiedKeys.includes(key));
const unVerfiedRules = unVerfiedKeys.map((key) => rules.get(key));

@@ -158,11 +157,11 @@

*/
if (isArray(cur) && draft[`__incorrect__${unVerfiedKeys[idx]}__Idx`] !== -1) {
cur = cur[draft[`__incorrect__${unVerfiedKeys[idx]}__Idx`]];
}
const errLog = cur.message ? cur.message : `${unVerfiedKeys[idx]} is not verified`;
const emitInfo = {
field: unVerfiedKeys[idx],
fieldValue: source[unVerfiedKeys[idx]],
type: cur.type,
errLog: `${unVerfiedKeys[idx]} is not verified`,
type: cur.type || 'string',
errLog,
};

@@ -194,2 +193,5 @@ acc = acc.concat(emitInfo);

validate(source, callback) {
// eslint-disable-next-line quotes
if (!source) throw Error("Can't configure a empty")
if (!isObject(source)) throw new Error('source msut be a object')
const basic = Object.create(null);

@@ -196,0 +198,0 @@ /**

{
"name": "proy",
"version": "0.0.2",
"version": "0.0.3",
"description": "A streamlined form validation library",

@@ -25,2 +25,7 @@ "main": "dist/cjs/index.js",

"license": "MIT",
"homepage": "https://github.com/fay-org/validator",
"repository": {
"type": "git",
"url": "https://github.com/fay-org/validator"
},
"devDependencies": {

@@ -27,0 +32,0 @@ "@rollup/plugin-commonjs": "^21.0.1",

@@ -5,2 +5,3 @@ export type ValidateType = 'array' | 'number' | 'object' | 'string' | 'boolean'

required?: boolean
message?: string
validate?: (val) => boolean

@@ -24,2 +25,2 @@ }

export type ValidateCallBack = (err?: CallbackErrors[], fields?: Record<string, any>) => void
export type ValidateCallBack = (err: [] | CallbackErrors[], fields: Record<string, any>) => void
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc