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 1.0.0-next.12 to 1.0.0-next.13

dist/types/types-49692c2c.d.ts

77

dist/cjs/index.js

@@ -284,12 +284,35 @@ 'use strict';

return objValue;
if (!srcValue)
return objValue;
if (!objValue || !srcValue)
return;
if (!Array.isArray(objValue))
objValue = [objValue];
if (Array.isArray(objValue)) {
if (!Array.isArray(srcValue))
return [...objValue, srcValue];
const newErrors = [];
for (let i = 0; i < srcValue.length; i++) {
let obj = objValue[i];
let src = srcValue[i];
if (!_isPlainObject(obj) && !_isPlainObject(src)) {
if (!Array.isArray(obj))
obj = [obj];
if (!Array.isArray(src))
src = [src];
newErrors.push(...obj, ...src);
}
else {
newErrors.push(mergeErrors([obj !== null && obj !== void 0 ? obj : {}, src !== null && src !== void 0 ? src : {}]));
}
}
return newErrors.filter(Boolean);
}
if (!Array.isArray(srcValue))
srcValue = [srcValue];
return [...objValue, ...srcValue];
return [objValue, ...srcValue]
.reduce((acc, value) => acc.concat(value), [])
.filter(Boolean);
}
function mergeErrors(errors) {
return _mergeWith(...errors, executeCustomizer);
const merged = _mergeWith(...errors, executeCustomizer);
return merged;
}

@@ -304,35 +327,6 @@ function runValidations(values, validationOrValidations) {

}
async function executeValidation(values, validations) {
async function executeValidation(values, shape, validations) {
const errors = await Promise.all(runValidations(values, validations));
const merged = mergeErrors(errors);
return syncFieldArrays(values, merged);
return mergeErrors([shape, ...errors]);
}
function fieldArrayCustomizer(data, error) {
if (_isPlainObject(data))
return;
if (!Array.isArray(data) || !Array.isArray(error))
return error;
if (data.length === 0)
return error;
if (data.length === error.length)
return;
const newError = [];
for (let i = 0; i < error.length; i++) {
const value = error[i];
const index = i % data.length;
if (isNaN(index) || !value)
continue;
if (!Array.isArray(newError[index]))
newError[index] = [];
newError[index].push(value);
}
return newError.map((e) => {
if (e.every((o) => _isPlainObject(o)))
return mergeErrors(e);
return e;
});
}
function syncFieldArrays(shape, error) {
return _mergeWith(deepSet(shape, null), error, fieldArrayCustomizer);
}

@@ -398,2 +392,3 @@ function executeTransforms(values, transforms) {

let defaultData = {};
let defaultTouched = {};
for (const el of node.elements) {

@@ -415,11 +410,11 @@ if (isFieldSetElement(el))

defaultData = _set(defaultData, elName, el.checked);
defaultTouched = _set(defaultTouched, elName, false);
continue;
}
defaultData = _set(defaultData, elName, el.checked ? [el.value] : []);
defaultTouched = _set(defaultTouched, elName, false);
continue;
}
if (Array.isArray(_get(defaultData, elName)) && el.checked) {
defaultData = _update(defaultData, elName, (value) => {
return [...value, el.value];
});
defaultData = _update(defaultData, elName, (value) => [...value, el.value]);
}

@@ -432,2 +427,3 @@ continue;

defaultData = _set(defaultData, elName, el.checked ? el.value : undefined);
defaultTouched = _set(defaultTouched, elName, false);
continue;

@@ -437,2 +433,3 @@ }

defaultData = _set(defaultData, elName, el.multiple ? Array.from(el.files || []) : (_a = el.files) === null || _a === void 0 ? void 0 : _a[0]);
defaultTouched = _set(defaultTouched, elName, false);
continue;

@@ -443,4 +440,5 @@ }

defaultData = _set(defaultData, elName, inputValue);
defaultTouched = _set(defaultTouched, elName, false);
}
return { defaultData };
return { defaultData, defaultTouched };
}

@@ -530,3 +528,2 @@ function setControlValue(el, value) {

exports.shouldIgnore = shouldIgnore;
exports.syncFieldArrays = syncFieldArrays;
//# sourceMappingURL=index.js.map

@@ -19,5 +19,5 @@ export { _some } from './utils/some.js';

export { getValue } from './utils/getValue.js';
export { executeValidation, mergeErrors, runValidations, syncFieldArrays } from './utils/executeValidation.js';
export { executeValidation, mergeErrors, runValidations } from './utils/executeValidation.js';
export { executeTransforms } from './utils/executeTransforms.js';
export { addAttrsFromFieldset, getFormControls, getFormDefaultValues, getInputTextOrNumber, setControlValue, setForm } from './utils/domUtils.js';
//# sourceMappingURL=index.js.map

@@ -58,2 +58,3 @@ import { isFormControl, isFieldSetElement, isInputElement } from './typeGuards.js';

let defaultData = {};
let defaultTouched = {};
for (const el of node.elements) {

@@ -75,11 +76,11 @@ if (isFieldSetElement(el))

defaultData = _set(defaultData, elName, el.checked);
defaultTouched = _set(defaultTouched, elName, false);
continue;
}
defaultData = _set(defaultData, elName, el.checked ? [el.value] : []);
defaultTouched = _set(defaultTouched, elName, false);
continue;
}
if (Array.isArray(_get(defaultData, elName)) && el.checked) {
defaultData = _update(defaultData, elName, (value) => {
return [...value, el.value];
});
defaultData = _update(defaultData, elName, (value) => [...value, el.value]);
}

@@ -92,2 +93,3 @@ continue;

defaultData = _set(defaultData, elName, el.checked ? el.value : undefined);
defaultTouched = _set(defaultTouched, elName, false);
continue;

@@ -97,2 +99,3 @@ }

defaultData = _set(defaultData, elName, el.multiple ? Array.from(el.files || []) : (_a = el.files) === null || _a === void 0 ? void 0 : _a[0]);
defaultTouched = _set(defaultTouched, elName, false);
continue;

@@ -103,4 +106,5 @@ }

defaultData = _set(defaultData, elName, inputValue);
defaultTouched = _set(defaultTouched, elName, false);
}
return { defaultData };
return { defaultData, defaultTouched };
}

@@ -107,0 +111,0 @@ function setControlValue(el, value) {

import { _mergeWith } from './mergeWith.js';
import { _isPlainObject } from './isPlainObject.js';
import { deepSet } from './deepSet.js';

@@ -12,12 +11,35 @@ function executeCustomizer(objValue, srcValue) {

return objValue;
if (!srcValue)
return objValue;
if (!objValue || !srcValue)
return;
if (!Array.isArray(objValue))
objValue = [objValue];
if (Array.isArray(objValue)) {
if (!Array.isArray(srcValue))
return [...objValue, srcValue];
const newErrors = [];
for (let i = 0; i < srcValue.length; i++) {
let obj = objValue[i];
let src = srcValue[i];
if (!_isPlainObject(obj) && !_isPlainObject(src)) {
if (!Array.isArray(obj))
obj = [obj];
if (!Array.isArray(src))
src = [src];
newErrors.push(...obj, ...src);
}
else {
newErrors.push(mergeErrors([obj !== null && obj !== void 0 ? obj : {}, src !== null && src !== void 0 ? src : {}]));
}
}
return newErrors.filter(Boolean);
}
if (!Array.isArray(srcValue))
srcValue = [srcValue];
return [...objValue, ...srcValue];
return [objValue, ...srcValue]
.reduce((acc, value) => acc.concat(value), [])
.filter(Boolean);
}
function mergeErrors(errors) {
return _mergeWith(...errors, executeCustomizer);
const merged = _mergeWith(...errors, executeCustomizer);
return merged;
}

@@ -32,37 +54,8 @@ function runValidations(values, validationOrValidations) {

}
async function executeValidation(values, validations) {
async function executeValidation(values, shape, validations) {
const errors = await Promise.all(runValidations(values, validations));
const merged = mergeErrors(errors);
return syncFieldArrays(values, merged);
return mergeErrors([shape, ...errors]);
}
function fieldArrayCustomizer(data, error) {
if (_isPlainObject(data))
return;
if (!Array.isArray(data) || !Array.isArray(error))
return error;
if (data.length === 0)
return error;
if (data.length === error.length)
return;
const newError = [];
for (let i = 0; i < error.length; i++) {
const value = error[i];
const index = i % data.length;
if (isNaN(index) || !value)
continue;
if (!Array.isArray(newError[index]))
newError[index] = [];
newError[index].push(value);
}
return newError.map((e) => {
if (e.every((o) => _isPlainObject(o)))
return mergeErrors(e);
return e;
});
}
function syncFieldArrays(shape, error) {
return _mergeWith(deepSet(shape, null), error, fieldArrayCustomizer);
}
export { executeValidation, mergeErrors, runValidations, syncFieldArrays };
export { executeValidation, mergeErrors, runValidations };
//# sourceMappingURL=executeValidation.js.map

@@ -19,6 +19,6 @@ export { _some } from "./utils/some";

export { getValue } from "./utils/getValue";
export { executeValidation, mergeErrors, runValidations, syncFieldArrays } from "./utils/executeValidation";
export { executeValidation, mergeErrors, runValidations } from "./utils/executeValidation";
export { executeTransforms } from "./utils/executeTransforms";
export * from "./utils/domUtils";
export * from "./types-738e1202";
export * from "./types-49692c2c";
//# sourceMappingURL=index.d.ts.map

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

import { Obj } from "../types-738e1202";
import { Obj } from "../types-49692c2c";
/** @ignore */
declare function _cloneDeep<T extends Obj>(obj: T): T;
export { _cloneDeep };

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

import { Obj, DeepSetResult } from "../types-738e1202";
import { Obj, DeepSetResult } from "../types-49692c2c";
/**

@@ -3,0 +3,0 @@ * @category Helper

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

import { Obj } from "../types-738e1202";
import { Obj } from "../types-49692c2c";
/**

@@ -3,0 +3,0 @@ * @category Helper

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

import { Obj } from "../types-738e1202";
import { Obj } from "../types-49692c2c";
/** @ignore */
declare function _defaultsDeep<T extends Obj>(...args: any[]): T;
export { _defaultsDeep };

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

import { FormControl, Obj, FieldValue } from "../types-738e1202";
import { FormControl, Obj, FieldValue, Touched } from "../types-49692c2c";
/**

@@ -17,2 +17,3 @@ * @ignore

defaultData: Data;
defaultTouched: Touched<Data>;
};

@@ -19,0 +20,0 @@ declare function setControlValue(el: FormControl, value: FieldValue | FieldValue[]): void;

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

import { Obj, TransformFunction } from "../types-738e1202";
import { Obj, TransformFunction } from "../types-49692c2c";
declare function executeTransforms<Data extends Obj>(values: Obj, transforms?: TransformFunction<Data>[] | TransformFunction<Data>): ReturnType<TransformFunction<Data>>;
export { executeTransforms };

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

import { Obj, ValidationFunction, Errors, RecursivePartial } from "../types-738e1202";
import { Obj, ValidationFunction, Errors, RecursivePartial } from "../types-49692c2c";
declare function mergeErrors<Data extends Obj>(errors: (RecursivePartial<Data> | undefined)[]): Data;
declare function runValidations<Data extends Obj>(values: Data, validationOrValidations?: ValidationFunction<Data>[] | ValidationFunction<Data>): ReturnType<ValidationFunction<Data>>[];
declare function executeValidation<Data extends Obj>(values: Data, validations?: ValidationFunction<Data>[] | ValidationFunction<Data>): Promise<Errors<Data>>;
declare function syncFieldArrays<Data extends Obj>(shape: Data, error: Errors<Data>): Errors<Data>;
export { mergeErrors, runValidations, executeValidation, syncFieldArrays };
declare function executeValidation<Data extends Obj>(values: Data, shape: Errors<Data>, validations?: ValidationFunction<Data>[] | ValidationFunction<Data>): Promise<Errors<Data>>;
export { mergeErrors, runValidations, executeValidation };

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

import { Obj, FieldValue } from "../types-738e1202";
import { Obj, FieldValue } from "../types-49692c2c";
/** @ignore */
declare function _get<Data extends Obj, Default = undefined>(obj: Data, path: string, defaultValue?: Default): Default | FieldValue | FieldValue[];
export { _get };

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

import { FormControl } from "../types-738e1202";
import { FormControl } from "../types-49692c2c";
/**

@@ -3,0 +3,0 @@ * @category Helper

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

import { Paths, Traverse, Obj } from "../types-738e1202";
import { Paths, Traverse, Obj } from "../types-49692c2c";
declare function getValue<T>(storeValue: T): T;

@@ -3,0 +3,0 @@ declare function getValue<T extends Obj, R>(storeValue: T, selector: (value: T) => R): R;

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

import { FieldValue } from "../types-738e1202";
import { FieldValue } from "../types-49692c2c";
/** @category Helper */
declare function isFieldValue(value: unknown): value is FieldValue;
export { isFieldValue };

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

import { Obj } from "../types-738e1202";
import { Obj } from "../types-49692c2c";
/** @ignore */
declare function _mapValues(obj: Obj, updater: (value: unknown) => unknown): Obj;
export { _mapValues };

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

import { Obj } from "../types-738e1202";
import { Obj } from "../types-49692c2c";
/** @ignore */
declare function _merge<T extends Obj>(...args: any[]): T;
export { _merge };

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

import { Obj } from "../types-738e1202";
import { Obj } from "../types-49692c2c";
/** @ignore */
declare function _mergeWith<T extends Obj>(...args: any[]): T;
export { _mergeWith };

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

import { Obj, FieldValue } from "../types-738e1202";
import { Obj, FieldValue } from "../types-49692c2c";
/** @ignore */
declare function _set<Data extends Obj>(obj: Data | undefined, path: string | string[], value: FieldValue | FieldValue[]): Data;
export { _set };

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

import { Obj } from "../types-738e1202";
import { Obj } from "../types-49692c2c";
/** @ignore */
declare function _some(obj: Obj, pred: (value: unknown) => boolean): boolean;
export { _some };

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

import { FormControl } from "../types-738e1202";
import { FormControl } from "../types-49692c2c";
/**

@@ -3,0 +3,0 @@ * @category Helper

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

import { Obj } from "../types-738e1202";
import { Obj } from "../types-49692c2c";
/** @ignore */

@@ -3,0 +3,0 @@ declare function _unset(obj: undefined, path: string | string[]): undefined;

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

import { Obj, FieldValue } from "../types-738e1202";
import { Obj, FieldValue } from "../types-49692c2c";
/** @ignore */
declare function _update<Data extends Obj, Value = FieldValue>(obj: Data | undefined, path: string, updater: (value: Value) => Value): Data;
export { _update };
{
"name": "@felte/common",
"version": "1.0.0-next.12",
"version": "1.0.0-next.13",
"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