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

formstate

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

formstate - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

3

CHANGELOG.md

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

# 1.1.1
* If a validator dies unexpectedly (throws an error/exception) the `validate` call does the same instead of silently ignoring it. Should not cause any change if your validators worked previously.
# 1.1.0

@@ -2,0 +5,0 @@ * Added support for `Map` in `FormState` class.

6

CONTRIBUTING.md
# Setup
`npm install`
# Run Demos
# Run Demos / Tests
* `npm start`
* visit http://localhost:4000/demos/
* Edit `src/scripts/demos.ts`
* Visit http://localhost:4000/demos/ Edit `src/scripts/demos.ts`
* Edit tests, see terminal for results

@@ -9,0 +9,0 @@ # Write Docs

/** A truthy string or falsy values */
export declare type ValidationResponse = string | null | undefined | false;
/** The return value of a validator */
export declare type ValidatorResponse = ValidationResponse | Promise<ValidationResponse>;
/**

@@ -8,6 +10,8 @@ * A validator simply takes a value and returns a string or Promise<string>

export interface Validator<TValue> {
(value: TValue): ValidationResponse | Promise<ValidationResponse>;
(value: TValue): ValidatorResponse;
}
/**
* Runs the value through a list of validators. As soon as a validation error is detected, the error is returned
* Runs the value through a list of validators.
* - As soon as a validation error is detected, the error is returned
* - As soon as a validator dies unexpectedly (throws an error), we throw the same error.
*/

@@ -14,0 +18,0 @@ export declare function applyValidators<TValue>(value: TValue, validators: Validator<TValue>[]): Promise<string | null | undefined>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var utils_1 = require("../internal/utils");
/**
* Runs the value through a list of validators. As soon as a validation error is detected, the error is returned
* Runs the value through a list of validators.
* - As soon as a validation error is detected, the error is returned
* - As soon as a validator dies unexpectedly (throws an error), we throw the same error.
*/
function applyValidators(value, validators) {
return new Promise(function (resolve) {
return new Promise(function (resolve, reject) {
var currentIndex = 0;

@@ -26,13 +29,15 @@ var gotoNextValidator = function () {

// some error
if (!res.then) {
if (!utils_1.isPromiseLike(res)) {
resolve(res);
return;
}
// wait for error response
// wait for validator response
res.then(function (msg) {
// no error
if (!msg)
gotoNextValidator();
// some error
else
resolve(msg);
});
}).catch(reject);
};

@@ -39,0 +44,0 @@ // kickoff

export declare function debounce<T extends Function>(func: T, milliseconds: number, immediate?: boolean): T;
export declare function isMapLike(thing: any): boolean;
export declare function isPromiseLike(arg: any): arg is Promise<any>;

@@ -41,3 +41,2 @@ "use strict";

exports.debounce = debounce;
;
function isMapLike(thing) {

@@ -48,1 +47,5 @@ return mobx_1.isObservableMap(thing)

exports.isMapLike = isMapLike;
function isPromiseLike(arg) {
return arg != null && typeof arg === "object" && typeof arg.then === "function";
}
exports.isPromiseLike = isPromiseLike;
{
"name": "formstate",
"version": "1.1.0",
"version": "1.1.1",
"description": "Painless and simple MobX form management",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

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

import * as utils from '../internal/utils';
import { isPromiseLike } from "../internal/utils"
/** A truthy string or falsy values */

@@ -11,2 +10,7 @@ export type ValidationResponse =

/** The return value of a validator */
export type ValidatorResponse =
ValidationResponse
| Promise<ValidationResponse>
/**

@@ -17,10 +21,12 @@ * A validator simply takes a value and returns a string or Promise<string>

export interface Validator<TValue> {
(value: TValue): ValidationResponse | Promise<ValidationResponse>;
(value: TValue): ValidatorResponse;
}
/**
* Runs the value through a list of validators. As soon as a validation error is detected, the error is returned
* Runs the value through a list of validators.
* - As soon as a validation error is detected, the error is returned
* - As soon as a validator dies unexpectedly (throws an error), we throw the same error.
*/
export function applyValidators<TValue>(value: TValue, validators: Validator<TValue>[]): Promise<string | null | undefined> {
return new Promise<string | null | undefined>(resolve => {
return new Promise<string | null | undefined>((resolve, reject) => {
let currentIndex = 0;

@@ -39,3 +45,3 @@

let validator = validators[currentIndex];
let res: any = validator(value);
let res = validator(value);

@@ -49,3 +55,3 @@ // no error

// some error
if (!res.then) {
if (!isPromiseLike(res)) {
resolve(res);

@@ -55,7 +61,9 @@ return;

// wait for error response
// wait for validator response
res.then((msg: any) => {
// no error
if (!msg) gotoNextValidator();
// some error
else resolve(msg);
})
}).catch(reject)
}

@@ -62,0 +70,0 @@

@@ -39,3 +39,3 @@ import { isObservableMap } from "mobx"

};
};
}

@@ -46,1 +46,5 @@ export function isMapLike(thing: any) {

}
export function isPromiseLike(arg: any): arg is Promise<any> {
return arg != null && typeof arg === "object" && typeof arg.then === "function";
}
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