🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

ffw

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ffw - npm Package Compare versions

Comparing version
1.1.4
to
1.1.5
+1
-1
dist/ffw.cjs

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

"use strict";var d=Object.defineProperty;var c=(r,t,e)=>t in r?d(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var i=(r,t,e)=>(c(r,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class v{constructor(){i(this,"events",new Map)}on(t,e){return this.events.has(t)?this.events.get(t).push(e):this.events.set(t,[e]),()=>this.off(t,e)}off(t,e){this.events.has(t)&&this.events.set(t,this.events.get(t).filter(s=>s!==e))}emit(t,e){this.events.has(t)&&this.events.get(t).forEach(s=>s(e)),t!=="*"&&this.events.has("*")&&this.events.get("*").forEach(s=>s(t,e))}}function l(){return new v}const m=()=>"";class n{constructor({value:t="",touched:e=!1,error:s="",test:a=m,form:o=null}={}){i(this,"form",null);i(this,"eeSync",l());i(this,"ee",l());i(this,"data",{value:"",error:"",touched:!1});i(this,"set",(t,e)=>{if(this.setData("value",t),e===!0){this.validate();return}e!==!1&&e===void 0&&this.form.options.validateOnChange&&this.validate()});i(this,"onNativeInput",t=>{this.set(t.target.value)});i(this,"onBlur",()=>{this.setTouched(!0),this.form.options.validateOnBlur&&this.validate()});this.form=o,this.test=a,this.initParams={value:t,touched:e,error:s,test:a},this.data.value=t,this.data.error=s,this.data.touched=e,o.addField(this)}notify(t,e){this.eeSync.emit(t,e),this.form.calls.add(this,t,()=>{this.ee.emit(t,e)}),this.form.calls.add(this,"global",()=>{this.ee.emit("global",[this,t,e])}),this.form.notify("global",[this,t,e])}get value(){return this.data.value}set value(t){this.set(t)}get error(){return this.data.error}set error(t){this.setError(t)}get touched(){return this.data.touched}set touched(t){this.setTouched(t)}get errorTouched(){return this.data.touched===!1?"":this.data.error}setDataPure(t,e){}setData(t,e){const s=this.data[t];if(this.form.options.checkPrevData&&s===e)return!1;const a=this.errorTouched;if(this.data[t]=e,this.notify(t,e),t==="error"){const o=s,h=e;h!==""&&o===""?(this.form._errors++,this.form._errors===1&&this.form.notify("valid",!1)):h===""&&o!==""&&(this.form._errors--,this.form._errors===0&&this.form.notify("valid",!0))}return(t==="error"||t==="touched")&&a!==this.errorTouched&&this.notify("errorTouched",this.errorTouched),!0}update(){this.form.calls.add(this,"*",()=>this.ee.emit("*")),this.form.calls.add(this.form,"*",()=>this.form.ee.emit("*"))}setError(t){this.setData("error",t)}setTouched(t){this.setData("touched",t)}async validate(){const t=await this.test(this.data.value);return this.setError(t),t}on(t,e){return this.ee.on(t,e),()=>this.ee.off(t,e)}off(t,e){return()=>this.ee.off(t,e)}reset(){this.setData("value",this.initParams.value),this.setData("touched",this.initParams.touched),this.setData("error",this.initParams.error)}}function g(){let r,t;return[new Promise((e,s)=>{r=e,t=s}),{resolve:r,reject:t}]}class F{constructor(t){i(this,"_calls",new Map);i(this,"promise",null);this.batch=t||(e=>e())}add(t,e,s){if(this._calls.has(t)||this._calls.set(t,new Map),this._calls.get(t).set(e,s),!this.promise){const[o,h]=g();this.promise=o,this.promiseConrtols=h,queueMicrotask(async()=>{await this._call(),this._calls.clear(),this.promiseConrtols.resolve(),this.promise=null})}return this.promise}_call(){return this.batch(()=>{for(const t of this._calls.values())for(const e of t.values())e()})}}class u{constructor(t={plugins:[]}){i(this,"options",{validateOnChange:!0,validateOnBlur:!0,checkPrevData:!1});i(this,"fields",{});i(this,"f",null);i(this,"onSubmit",()=>{});i(this,"calls",new F);i(this,"eeSync",l());i(this,"ee",l());i(this,"submit",async()=>{if(await this.validate())return this.onSubmit(this)});i(this,"_errors",0);i(this,"_flatFields",new Set);const e=t.plugins||[];this.f=this.fields,e.forEach(a=>a(this)),this.options={...this.options,...t.options},this.onSubmit=t.onSubmit??(()=>{}),this.initValues=t.initValues??{};for(const a in this.initValues){const o=this.initValues[a];this._getFlatFieldOrCreate(a,{value:o})}t.batch&&(this.batch=t.batch);const s=typeof t.validateSchema=="function"?t.validateSchema(this):t.validateSchema;for(const a in s){const o=s[a],h=this._getFlatFieldOrCreate(a);h.test=o}}notify(t,e){this.eeSync.emit(t,e),this.calls.add(this,t,()=>{this.ee.emit(t,e)}),t!=="global"&&this.notify("global",[this,t,e])}batch(t){t()}createField(t={}){return new n(t)}_getFlatFieldOrCreate(t,e){return this.fields[t]||(this.fields[t]=this.createField({name:t,form:this,...e})),this.fields[t]}async validate(){return(await Promise.all([...this._flatFields].map(e=>e.validate()))).every(e=>e==="")}getValid(){return this._errors===0}get valid(){return this.getValid()}reset(){for(const t of this._flatFields)t.reset()}_prepareFieldData(t){const e={};for(const s in this.fields)t(this.fields[s])!==void 0&&(e[s]=t(this.fields[s]));return e}get values(){return this._prepareFieldData(t=>t.value)}get errors(){return this._prepareFieldData(t=>t.error||void 0)}get touches(){return this._prepareFieldData(t=>t.touched||void 0)}get data(){return this._prepareFieldData(t=>({value:t.value,error:t.error,touched:t.touched}))}on(t,e){return this.ee.on(t,e),()=>this.ee.off(t,e)}off(t,e){return()=>this.ee.off(t,e)}addField(t){t.error!==""&&this._errors++,this._flatFields.add(t)}removeField(t){t.error!==""&&this._errors--,this._flatFields.delete(t)}}function f(r){return async t=>{try{return await r.validate(t),""}catch(e){return e.message}}}function p(r){const t={};for(const e in r)t[e]=f(r[e]);return t}const _=n,y=u;exports.FfwField=_;exports.FfwForm=y;exports.Field=n;exports.Form=u;exports.convertYupToTest=f;exports.prepareYup=p;
"use strict";var d=Object.defineProperty;var c=(i,t,e)=>t in i?d(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var r=(i,t,e)=>(c(i,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class v{constructor(){r(this,"events",new Map)}on(t,e){return this.events.has(t)?this.events.get(t).push(e):this.events.set(t,[e]),()=>this.off(t,e)}off(t,e){this.events.has(t)&&this.events.set(t,this.events.get(t).filter(s=>s!==e))}emit(t,e){this.events.has(t)&&this.events.get(t).forEach(s=>s(e)),t!=="*"&&this.events.has("*")&&this.events.get("*").forEach(s=>s(t,e))}}function n(){return new v}const m=()=>"";class l{constructor({value:t="",touched:e=!1,error:s="",test:a=m,form:o=null}={}){r(this,"form",null);r(this,"eeSync",n());r(this,"ee",n());r(this,"data",{value:"",error:"",touched:!1});r(this,"set",(t,e)=>{if(this.setData("value",t),e===!0){this.validate();return}e!==!1&&e===void 0&&this.form.options.validateOnChange&&this.validate()});r(this,"onNativeInput",t=>{this.set(t.target.value)});r(this,"onBlur",()=>{this.setTouched(!0),this.form.options.validateOnBlur&&this.validate()});this.form=o,this.test=a,this.initParams={value:t,touched:e,error:s,test:a},this.data.value=t,this.data.error=s,this.data.touched=e,o.addField(this)}static new(...t){return new l(...t)}notify(t,e){this.eeSync.emit(t,e),this.form.calls.add(this,t,()=>{this.ee.emit(t,e)}),this.form.calls.add(this,"global",()=>{this.ee.emit("global",[this,t,e])}),this.form.notify("global",[this,t,e])}get value(){return this.data.value}set value(t){this.set(t)}get error(){return this.data.error}set error(t){this.setError(t)}get touched(){return this.data.touched}set touched(t){this.setTouched(t)}get errorTouched(){return this.data.touched===!1?"":this.data.error}setDataPure(t,e){}setData(t,e){const s=this.data[t];if(this.form.options.checkPrevData&&s===e)return!1;const a=this.errorTouched;if(this.data[t]=e,this.notify(t,e),t==="error"){const o=s,h=e;h!==""&&o===""?(this.form._errors++,this.form._errors===1&&this.form.notify("valid",!1)):h===""&&o!==""&&(this.form._errors--,this.form._errors===0&&this.form.notify("valid",!0))}return(t==="error"||t==="touched")&&a!==this.errorTouched&&this.notify("errorTouched",this.errorTouched),!0}update(){this.form.calls.add(this,"*",()=>this.ee.emit("*")),this.form.calls.add(this.form,"*",()=>this.form.ee.emit("*"))}setError(t){this.setData("error",t)}setTouched(t){this.setData("touched",t)}async validate(){const t=await this.test(this.data.value);return this.setError(t),t}on(t,e){return this.ee.on(t,e),()=>this.ee.off(t,e)}off(t,e){return()=>this.ee.off(t,e)}reset(){this.setData("value",this.initParams.value),this.setData("touched",this.initParams.touched),this.setData("error",this.initParams.error)}}function g(){let i,t;return[new Promise((e,s)=>{i=e,t=s}),{resolve:i,reject:t}]}class p{constructor(t){r(this,"_calls",new Map);r(this,"promise",null);this.batch=t||(e=>e())}add(t,e,s){if(this._calls.has(t)||this._calls.set(t,new Map),this._calls.get(t).set(e,s),!this.promise){const[o,h]=g();this.promise=o,this.promiseConrtols=h,queueMicrotask(async()=>{await this._call(),this._calls.clear(),this.promiseConrtols.resolve(),this.promise=null})}return this.promise}_call(){return this.batch(()=>{for(const t of this._calls.values())for(const e of t.values())e()})}}class u{constructor(t={plugins:[]}){r(this,"options",{validateOnChange:!0,validateOnBlur:!0,checkPrevData:!1});r(this,"fields",{});r(this,"f",null);r(this,"onSubmit",()=>{});r(this,"calls",new p);r(this,"eeSync",n());r(this,"ee",n());r(this,"submit",async()=>{if(await this.validate())return this.onSubmit(this)});r(this,"_errors",0);r(this,"_flatFields",new Set);const e=t.plugins||[];this.f=this.fields,e.forEach(a=>a(this)),this.options={...this.options,...t.options},this.onSubmit=t.onSubmit??(()=>{}),this.initValues=t.initValues??{};for(const a in this.initValues){const o=this.initValues[a];this._getFlatFieldOrCreate(a,{value:o})}t.batch&&(this.batch=t.batch);const s=typeof t.validateSchema=="function"?t.validateSchema(this):t.validateSchema;for(const a in s){const o=s[a],h=this._getFlatFieldOrCreate(a);h.test=o}}static new(...t){return new u(...t)}notify(t,e){this.eeSync.emit(t,e),this.calls.add(this,t,()=>{this.ee.emit(t,e)}),t!=="global"&&this.notify("global",[this,t,e])}batch(t){t()}createField(t={}){return new l(t)}_getFlatFieldOrCreate(t,e){return this.fields[t]||(this.fields[t]=this.createField({name:t,form:this,...e})),this.fields[t]}async validate(){return(await Promise.all([...this._flatFields].map(e=>e.validate()))).every(e=>e==="")}getValid(){return this._errors===0}get valid(){return this.getValid()}reset(){for(const t of this._flatFields)t.reset()}_prepareFieldData(t){const e={};for(const s in this.fields)t(this.fields[s])!==void 0&&(e[s]=t(this.fields[s]));return e}get values(){return this._prepareFieldData(t=>t.value)}get errors(){return this._prepareFieldData(t=>t.error||void 0)}get touches(){return this._prepareFieldData(t=>t.touched||void 0)}get data(){return this._prepareFieldData(t=>({value:t.value,error:t.error,touched:t.touched}))}on(t,e){return this.ee.on(t,e),()=>this.ee.off(t,e)}off(t,e){return()=>this.ee.off(t,e)}addField(t){t.error!==""&&this._errors++,this._flatFields.add(t)}removeField(t){t.error!==""&&this._errors--,this._flatFields.delete(t)}}function f(i){return async t=>{try{return await i.validate(t),""}catch(e){return e.message}}}function F(i){const t={};for(const e in i)t[e]=f(i[e]);return t}const _=l,y=u;exports.FfwField=_;exports.FfwForm=y;exports.Field=l;exports.Form=u;exports.convertYupToTest=f;exports.prepareYup=F;

@@ -1,5 +0,5 @@

var u = Object.defineProperty;
var f = (r, t, e) => t in r ? u(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
var i = (r, t, e) => (f(r, typeof t != "symbol" ? t + "" : t, e), e);
class d {
var f = Object.defineProperty;
var d = (r, t, e) => t in r ? f(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
var i = (r, t, e) => (d(r, typeof t != "symbol" ? t + "" : t, e), e);
class c {
constructor() {

@@ -22,5 +22,5 @@ i(this, "events", /* @__PURE__ */ new Map());

function l() {
return new d();
return new c();
}
const c = () => "";
const v = () => "";
class n {

@@ -31,3 +31,3 @@ constructor({

error: s = "",
test: a = c,
test: a = v,
form: o = null

@@ -63,2 +63,5 @@ } = {}) {

}
static new(...t) {
return new n(...t);
}
notify(t, e) {

@@ -128,3 +131,3 @@ this.eeSync.emit(t, e), this.form.calls.add(this, t, () => {

}
function v() {
function m() {
let r, t;

@@ -135,3 +138,3 @@ return [new Promise((e, s) => {

}
class m {
class g {
constructor(t) {

@@ -144,3 +147,3 @@ i(this, "_calls", /* @__PURE__ */ new Map());

if (this._calls.has(t) || this._calls.set(t, /* @__PURE__ */ new Map()), this._calls.get(t).set(e, s), !this.promise) {
const [o, h] = v();
const [o, h] = m();
this.promise = o, this.promiseConrtols = h, queueMicrotask(async () => {

@@ -160,3 +163,3 @@ await this._call(), this._calls.clear(), this.promiseConrtols.resolve(), this.promise = null;

}
class g {
class u {
constructor(t = {

@@ -174,3 +177,3 @@ plugins: []

});
i(this, "calls", new m());
i(this, "calls", new g());
i(this, "eeSync", l());

@@ -200,2 +203,5 @@ i(this, "ee", l());

}
static new(...t) {
return new u(...t);
}
notify(t, e) {

@@ -265,3 +271,3 @@ this.eeSync.emit(t, e), this.calls.add(this, t, () => {

}
function _(r) {
function p(r) {
return async (t) => {

@@ -278,13 +284,13 @@ try {

for (const e in r)
t[e] = _(r[e]);
t[e] = p(r[e]);
return t;
}
const y = n, b = g;
const y = n, w = u;
export {
y as FfwField,
b as FfwForm,
w as FfwForm,
n as Field,
g as Form,
_ as convertYupToTest,
u as Form,
p as convertYupToTest,
F as prepareYup
};
{
"name": "ffw",
"version": "1.1.4",
"version": "1.1.5",
"type": "module",

@@ -5,0 +5,0 @@ "exports": {