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

@felte/common

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@felte/common - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

7

CHANGELOG.md
# @felte/common
## 0.1.5
### Patch Changes
- 1c6017f: Add `reset` helper function that resets the whole form to its original values
- 8a50ad7: Add a `validate` helper function to force validation of the whole form
## 0.1.4

@@ -4,0 +11,0 @@

9

dist/index.d.ts

@@ -15,3 +15,2 @@ import { Readable, Writable } from "svelte/store";

destroy?: () => void;
reportValidity?: () => void;
onSubmitError?: (state: OnSubmitErrorState<Data>) => void;

@@ -74,2 +73,4 @@ };

handleSubmit: (e: Event) => void;
/** Function that resets the form to its initial values */
reset: () => void;
/** Readable store containing only a boolean that represents if the form is valid. */

@@ -85,2 +86,4 @@ isValid: Readable<boolean>;

setField: (path: string, value?: FieldValue, touch?: boolean) => void;
/** Helper function that validates every fields and touches all of them. It updates the `errors` store. */
validate: () => Promise<Errors<Data> | void>;
}

@@ -155,3 +158,5 @@ type DeepSetResult<Data extends Obj, Value> = {

};
export { _some, _mapValues, _get, _set, _unset, _update, _isPlainObject, deepSet, deepSome, isInputElement, isTextAreaElement, isSelectElement, isFieldSetElement, isFormControl, isElement, getPath, getFormControls, addAttrsFromFieldset, getFormDefaultValues, CurrentForm, OnSubmitErrorState, ReporterHandler, Reporter, Obj, FieldValue, FormControl, FormConfigWithoutInitialValues, FormConfigWithInitialValues, FormConfig, Errors, Touched, FormAction, Form };
/** Sets the form inputs value to match the data object provided. */
declare function setForm<Data extends Obj>(node: HTMLFormElement, data: Data): void;
export { _some, _mapValues, _get, _set, _unset, _update, _isPlainObject, deepSet, deepSome, isInputElement, isTextAreaElement, isSelectElement, isFieldSetElement, isFormControl, isElement, getPath, getFormControls, addAttrsFromFieldset, getFormDefaultValues, setForm, CurrentForm, OnSubmitErrorState, ReporterHandler, Reporter, Obj, FieldValue, FormControl, FormConfigWithoutInitialValues, FormConfigWithInitialValues, FormConfig, Errors, Touched, FormAction, Form };
//# sourceMappingURL=index.d.ts.map

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Common={})}(this,(function(e){"use strict";function t(e,t){return Object.keys(e).some((n=>t(e[n])))}function n(e,t){return Object.keys(e).reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:t(e[o])})),{})}function o(e,t,n){const o=t.split(".");let i=e;try{for(const e of o)i=i[e]}catch(e){return n}return function(e){return Array.isArray(e)?0===e.length||e.some((e=>e instanceof File||"string"==typeof e)):"string"==typeof e||"number"==typeof e||"boolean"==typeof e||e instanceof File}(i)?i:n}function i(e,t,n){const o=t.split(".");let i=e;for(;o.length-1;){const e=o.shift();e&&(e in i||(i[e]={}),i=i[e])}return i[o[0]]=n,e}function r(e,t,n){const o=t.split(".");let i=e;for(;o.length-1;){const e=o.shift();e&&(e in i||(i[e]={}),i=i[e])}return i[o[0]]=n(i[o[0]]),e}function u(e){return"[object Object]"===Object.prototype.toString.call(e)}function l(e){var t;return"INPUT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function s(e){var t;return"TEXTAREA"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function f(e){var t;return"SELECT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function c(e){var t;return"FIELDSET"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function a(e){return l(e)||s(e)||f(e)}function d(e){const t=e.dataset.felteFieldset;return t?`${t}.${e.name}`:e.name}function m(e){for(const t of e.elements)(a(t)||c(t))&&(e.name&&t.name&&(t.dataset.felteFieldset=e.dataset.felteFieldset?`${e.dataset.felteFieldset}.${e.name}`:e.name),"true"!==e.dataset.felteUnsetOnRemove||t.hasAttribute("data-felte-unset-on-remove")||(t.dataset.felteUnsetOnRemove="true"))}e._get=o,e._isPlainObject=u,e._mapValues=n,e._set=i,e._some=t,e._unset=function(e,t){const n=t.split(".");let o=e;for(;n.length-1;){const e=n.shift();e&&(e in o||(o[e]={}),o=o[e])}return delete o[n[0]],e},e._update=r,e.addAttrsFromFieldset=m,e.deepSet=function e(t,o){return n(t,(t=>u(t)?e(t,o):o))},e.deepSome=function e(n,o){return t(n,(t=>u(t)?e(t,o):o(t)))},e.getFormControls=function e(t){if(a(t))return[t];if(0===t.childElementCount)return[];const n=[];for(const o of t.children){if(a(o)&&n.push(o),c(o))for(const e of o.elements)a(e)&&n.push(e);o.childElementCount>0&&n.push(...e(o))}return n},e.getFormDefaultValues=function(e){var t;const n={},u={};for(const s of e.elements){if(c(s)&&m(s),!a(s)||!s.name)continue;const f=d(s);if(i(u,f,!1),l(s)&&"checkbox"===s.type){if(void 0===o(n,f)){if(1===e.querySelectorAll(`[name="${s.name}"]`).length){i(n,f,s.checked);continue}i(n,f,s.checked?[s.value]:[]);continue}Array.isArray(o(n,f))&&s.checked&&r(n,f,(e=>[...e,s.value]))}else if(l(s)&&"radio"===s.type){if(o(n,f))continue;i(n,f,s.checked?s.value:void 0)}else l(s)&&"file"===s.type?i(n,f,s.multiple?Array.from(s.files||[]):null===(t=s.files)||void 0===t?void 0:t[0]):i(n,f,s.type.match(/^(number|range)$/)?+s.value:s.value)}return{defaultData:n,defaultTouched:u}},e.getPath=d,e.isElement=function(e){return e.nodeType===Node.ELEMENT_NODE},e.isFieldSetElement=c,e.isFormControl=a,e.isInputElement=l,e.isSelectElement=f,e.isTextAreaElement=s,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Common={})}(this,(function(e){"use strict";function t(e,t){return Object.keys(e).some((n=>t(e[n])))}function n(e,t){return Object.keys(e).reduce(((n,o)=>Object.assign(Object.assign({},n),{[o]:t(e[o])})),{})}function o(e,t,n){const o=t.split(".");let i=e;try{for(const e of o)i=i[e]}catch(e){return n}return function(e){return Array.isArray(e)?0===e.length||e.some((e=>e instanceof File||"string"==typeof e)):"string"==typeof e||"number"==typeof e||"boolean"==typeof e||e instanceof File}(i)?i:n}function i(e,t,n){const o=t.split(".");let i=e;for(;o.length-1;){const e=o.shift();e&&(e in i||(i[e]={}),i=i[e])}return i[o[0]]=n,e}function r(e,t,n){const o=t.split(".");let i=e;for(;o.length-1;){const e=o.shift();e&&(e in i||(i[e]={}),i=i[e])}return i[o[0]]=n(i[o[0]]),e}function l(e){return"[object Object]"===Object.prototype.toString.call(e)}function c(e){var t;return"INPUT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function s(e){var t;return"TEXTAREA"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function u(e){var t;return"SELECT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function f(e){var t;return"FIELDSET"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function a(e){return c(e)||s(e)||u(e)}function d(e){const t=e.dataset.felteFieldset;return t?`${t}.${e.name}`:e.name}function m(e){for(const t of e.elements)(a(t)||f(t))&&(e.name&&t.name&&(t.dataset.felteFieldset=e.dataset.felteFieldset?`${e.dataset.felteFieldset}.${e.name}`:e.name),"true"!==e.dataset.felteUnsetOnRemove||t.hasAttribute("data-felte-unset-on-remove")||(t.dataset.felteUnsetOnRemove="true"))}e._get=o,e._isPlainObject=l,e._mapValues=n,e._set=i,e._some=t,e._unset=function(e,t){const n=t.split(".");let o=e;for(;n.length-1;){const e=n.shift();e&&(e in o||(o[e]={}),o=o[e])}return delete o[n[0]],e},e._update=r,e.addAttrsFromFieldset=m,e.deepSet=function e(t,o){return n(t,(t=>l(t)?e(t,o):o))},e.deepSome=function e(n,o){return t(n,(t=>l(t)?e(t,o):o(t)))},e.getFormControls=function e(t){if(a(t))return[t];if(0===t.childElementCount)return[];const n=[];for(const o of t.children){if(a(o)&&n.push(o),f(o))for(const e of o.elements)a(e)&&n.push(e);o.childElementCount>0&&n.push(...e(o))}return n},e.getFormDefaultValues=function(e){var t;const n={},l={};for(const s of e.elements){if(f(s)&&m(s),!a(s)||!s.name)continue;const u=d(s);if(i(l,u,!1),c(s)&&"checkbox"===s.type){if(void 0===o(n,u)){if(1===e.querySelectorAll(`[name="${s.name}"]`).length){i(n,u,s.checked);continue}i(n,u,s.checked?[s.value]:[]);continue}Array.isArray(o(n,u))&&s.checked&&r(n,u,(e=>[...e,s.value]))}else if(c(s)&&"radio"===s.type){if(o(n,u))continue;i(n,u,s.checked?s.value:void 0)}else c(s)&&"file"===s.type?i(n,u,s.multiple?Array.from(s.files||[]):null===(t=s.files)||void 0===t?void 0:t[0]):i(n,u,s.type.match(/^(number|range)$/)?+s.value:s.value)}return{defaultData:n,defaultTouched:l}},e.getPath=d,e.isElement=function(e){return e.nodeType===Node.ELEMENT_NODE},e.isFieldSetElement=f,e.isFormControl=a,e.isInputElement=c,e.isSelectElement=u,e.isTextAreaElement=s,e.setForm=function(e,t){for(const n of e.elements){if(f(n)&&m(n),!a(n)||!n.name)continue;const e=d(n);if(c(n)&&"checkbox"===n.type){const i=o(t,e);if(void 0===i||"boolean"==typeof i){n.checked=!!i;continue}Array.isArray(i)&&(i.includes(n.value)?n.checked=!0:n.checked=!1)}else if(c(n)&&"radio"===n.type){const i=o(t,e);n.value===i?n.checked=!0:n.checked=!1}else c(n)&&"file"===n.type?(n.files=null,n.value=""):n.value=String(o(t,e,""))}},Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.js.map
{
"name": "@felte/common",
"version": "0.1.4",
"version": "0.1.5",
"description": "Common utilities for Felte packages",

@@ -5,0 +5,0 @@ "author": "Pablo Berganza <pablo@berganza.dev>",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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