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

formulr

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formulr - npm Package Compare versions

Comparing version 0.2.0-beta.26 to 0.2.0-beta.27

cmd/dev.d.ts

8

package.json
{
"name": "formulr",
"version": "0.2.0-beta.26",
"version": "0.2.0-beta.27",
"description": "Form toolkit for React",

@@ -43,3 +43,2 @@ "main": "./lib/index.js",

"rxjs": "^6.4.0",
"scheduler": "0.14.0",
"tslib": "^1.9.3",

@@ -55,3 +54,3 @@ "utility-types": "^3.5.0"

"jest": "^24.8.0",
"rimraf": "^2.6.3",
"rimraf": "^3.0.0",
"typescript": "~3.4.0",

@@ -62,3 +61,6 @@ "webpack": "^4.35.2",

"webpack-dev-server": "^3.7.2"
},
"peerDependencies": {
"scheduler": "~0.14.0 || ~0.15.0"
}
}
import { createContext, useContext } from 'react';
import { Observable } from 'rxjs';
import { FormStrategy, FormModel, FieldSetModel } from './models';
import { ValidateStrategy } from './validate';
export interface IFormContext {
validate$: Observable<ValidateStrategy>;
strategy: FormStrategy;

@@ -9,0 +6,0 @@ form: FormModel<any>;

import { useEffect } from 'react';
import { FieldSetModel, BasicModel } from './models';
import { FieldSetModel, BasicModel, ModelRef } from './models';
export function notUndefined(value: any): value is any {
return value !== undefined;
}
export function noop() {}
export function isPlainObject(value: unknown): value is object {
if (value === null || typeof value !== 'object') {
return false;
}
if (Object.getPrototypeOf(value) === null) {
return true;
}
let proto = value;
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto);
}
return Object.getPrototypeOf(value) === proto;
}
export function isPromise<T>(maybePromise: any): maybePromise is Promise<T> {

@@ -11,7 +31,11 @@ if (!maybePromise) {

export function getValueFromParentOrDefault<T>(parent: FieldSetModel, name: string, defaultValue: T | (() => T)): T {
if (parent.patchedValue !== null) {
const patchedValue = parent.patchedValue[name];
if (patchedValue) {
return patchedValue as T;
export function orElse<T>(
defaultValue: T | (() => T),
check: (value: unknown) => value is T,
...values: readonly unknown[]
): T {
for (let i = 0; i < values.length; i += 1) {
const value = values[i];
if (check(value)) {
return value;
}

@@ -26,5 +50,5 @@ }

export function removeOnUnmount(
field: string | BasicModel<any>,
field: string | BasicModel<any> | ModelRef<any, any>,
model: BasicModel<any>,
parent: FieldSetModel<unknown>,
parent: FieldSetModel,
) {

@@ -37,4 +61,4 @@ useEffect(

},
[],
[field, model, model],
);
}

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

import { Observable, Subscriber, isObservable, from, NextObserver, empty, never } from 'rxjs';
import { Observable, Subscriber, isObservable, from, NextObserver, empty, of } from 'rxjs';
import { catchError, map, concatAll, filter, take } from 'rxjs/operators';

@@ -16,11 +16,14 @@ import { BasicModel, FormModel, FieldSetModel } from './models';

export enum ValidateStrategy {
Default = 0b0000,
IncludeAsync = 0b0010,
IncludeUntouched = 0b0100,
IncludeChildren = 0b1000,
// prettier-ignore
export enum ValidateOption {
Default = 0b000000000,
IncludeAsync = 0b000000010,
IncludeUntouched = 0b000000100,
IncludeChildren = 0b000001000,
FromParent = 0b100000000,
}
export interface IValidator<Value> {
(input: Value, ctx: ValidatorContext): ValidatorResult<Value> | null;
(input: Value, ctx: ValidatorContext): ValidatorResult<Value>;
isAsync?: boolean;

@@ -30,3 +33,3 @@ $$id?: symbol;

export type ValidatorResult<T> = IMaybeError<T> | Promise<IMaybeError<T>> | Observable<IMaybeError<T>>;
export type ValidatorResult<T> = null | Observable<IMaybeError<T>> | Promise<IMaybeError<T>> | IMaybeError<T>;

@@ -108,16 +111,10 @@ function resultToSubscriber<T>(

class ValidatorExecutor<T> {
private prevValue: T | null = null;
constructor(private readonly model: BasicModel<T>, private readonly ctx: ValidatorContext) {}
call(strategy: ValidateStrategy): Observable<IMaybeError<T>> {
if (!this.model.touched && !(strategy & ValidateStrategy.IncludeUntouched)) {
return never();
call(option: ValidateOption): Observable<IMaybeError<T>> {
if (!this.model.touched() && !(option & ValidateOption.IncludeUntouched)) {
return of(null);
}
const value = this.model.getRawValue();
if (Object.is(value, this.prevValue)) {
return never();
}
this.prevValue = value;
const skipAsync = (strategy & ValidateStrategy.IncludeAsync) === 0;
const skipAsync = (option & ValidateOption.IncludeAsync) === 0;
return from(this.model.validators).pipe(

@@ -137,3 +134,3 @@ filter(validator => filterAsync(skipAsync, validator)),

const executor = new ValidatorExecutor(model, ctx);
return (strategy: ValidateStrategy) => executor.call(strategy);
return (option: ValidateOption) => executor.call(option);
}
import Decimal from 'big.js';
import { IValidator, IMaybeError } from './validate';
import { IValidator, IMaybeError, ValidatorResult } from './validate';

@@ -68,3 +68,3 @@ const EMAIL_REGEXP = /^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+(\.[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/;

export function required(message?: string): IValidator<any> {
function required(input: any) {
function required(input: any): ValidatorResult<string> {
return isEmptyInputValue(input)

@@ -71,0 +71,0 @@ ? {

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

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