Socket
Socket
Sign inDemoInstall

validx

Package Overview
Dependencies
3
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 1.0.0-alpha.0

26

CHANGELOG.md
# Changelog
## 1.0.0
* Upgraded to MobX v4, breaks compatibility with MobX <= 3
## 0.2.0
- Added `clearErrors(field: string)` to the context, lets you remove errors for a particular field.
* Added `clearErrors(field: string)` to the context, lets you remove errors for a particular field.
## 0.1.4
- Added `url` pattern validator.
- Added `func` validator
- More documentation
* Added `url` pattern validator.
* Added `func` validator
* More documentation
## 0.1.3
- Skip falsy values in schema.
* Skip falsy values in schema.
## 0.1.2
- Moved mobx to peerDependencies.
* Moved mobx to peerDependencies.
## 0.1.1
- Updated npm description.
* Updated npm description.
## 0.1.0
- Added `validation.getErrors()`.
- Added `validation.getError()`.
- Removed `lodash` dependency.
* Added `validation.getErrors()`.
* Added `validation.getError()`.
* Removed `lodash` dependency.
## 0.0.4
- First official release.
* First official release.

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

import { IObservableArray } from 'mobx';
/**

@@ -33,3 +32,3 @@ * Options passed to validators.

*/
export interface IRule<T> {
export interface IRule {
msg?: string;

@@ -54,3 +53,3 @@ }

export interface IValidationErrors {
[key: string]: IObservableArray<string>;
[key: string]: Array<string>;
}

@@ -57,0 +56,0 @@ /**

@@ -12,3 +12,3 @@ "use strict";

*/
var ValidationContext = (function () {
var ValidationContext = /** @class */ (function () {
/**

@@ -18,15 +18,17 @@ * Initializes a new instance of ValidationContext.

function ValidationContext() {
var _this = this;
this.reset = mobx_1.action.bound(this.reset);
this.addErrors = mobx_1.action.bound(this.addErrors);
this.clearErrors = mobx_1.action.bound(this.clearErrors);
this.validate = mobx_1.action.bound(this.validate);
this.reset = mobx_1.action(this.reset);
this.addErrors = mobx_1.action(this.addErrors);
this.clearErrors = mobx_1.action(this.clearErrors);
this.validate = mobx_1.action(this.validate);
mobx_1.extendObservable(this, {
errorsMap: mobx_1.observable.map(),
errors: mobx_1.computed(function () {
return _this.errorsMap.toJS();
}),
isValid: mobx_1.computed(function () {
return utils_1.every(_this.errors, function (arr) { return arr.length === 0; });
})
get errors() {
return mobx_1.toJS(this.errorsMap);
},
get isValid() {
return utils_1.every(this.errors, function (arr) { return arr.length === 0; });
}
}, {
errors: mobx_1.computed,
isValid: mobx_1.computed
});

@@ -132,3 +134,3 @@ }

if (!errors) {
errors = mobx_1.observable([]);
errors = mobx_1.observable.array([]);
this.errorsMap.set(field, errors);

@@ -149,3 +151,3 @@ }

var _this = this;
var entries = this.errorsMap.entries().filter(function (_a) {
var entries = Array.from(this.errorsMap.entries()).filter(function (_a) {
var value = _a[1];

@@ -152,0 +154,0 @@ return value.length === 0;

@@ -5,3 +5,3 @@ import { IValidator, IRule } from '../validation';

*/
export interface IFuncRule extends IRule<any> {
export interface IFuncRule extends IRule {
fn: IValidator<any>;

@@ -8,0 +8,0 @@ }

@@ -10,3 +10,3 @@ import { IRule, IValidator } from '../validation';

*/
export interface IPatternRule extends IRule<any> {
export interface IPatternRule extends IRule {
pattern: Pattern;

@@ -13,0 +13,0 @@ }

@@ -16,8 +16,4 @@ "use strict";

var valid = false;
var pattern = typeof rule === 'string' || rule instanceof RegExp
? rule
: rule.pattern;
var message = typeof rule === 'string' || rule instanceof RegExp
? msg
: rule.msg;
var pattern = typeof rule === 'string' || rule instanceof RegExp ? rule : rule.pattern;
var message = typeof rule === 'string' || rule instanceof RegExp ? msg : rule.msg;
if (pattern === 'email') {

@@ -32,3 +28,6 @@ valid = emailValidator.validate(opts.value);

}
return valid || message || (typeof pattern === 'string' && PatternMessages[pattern]) || DEFAULT_MESSAGE;
return (valid ||
message ||
(typeof pattern === 'string' && PatternMessages[pattern]) ||
DEFAULT_MESSAGE);
};

@@ -35,0 +34,0 @@ return validator;

@@ -5,3 +5,3 @@ import { IValidator, IRule } from '../validation';

*/
export interface IRequiredRule extends IRule<any> {
export interface IRequiredRule extends IRule {
required?: boolean;

@@ -8,0 +8,0 @@ }

@@ -12,3 +12,5 @@ "use strict";

exports.required = function (rule) {
if (typeof rule !== 'string' && rule !== undefined && rule.required === false) {
if (typeof rule !== 'string' &&
rule !== undefined &&
rule.required === false) {
return function () { return true; };

@@ -15,0 +17,0 @@ }

{
"name": "validx",
"version": "0.2.0",
"version": "1.0.0-alpha.0",
"description": "Validation library for MobX",

@@ -12,10 +12,30 @@ "main": "lib/index.js",

"build": "rimraf lib && tsc -p src",
"test": "rimraf .test-out && tsc --skipLibCheck -p test && mocha '.test-out/test/**/*.spec.js' --require .test-out/test/index.js",
"check": "tsc -p src/tsconfig.json --noEmit --pretty",
"lint":
"npm run check && tslint --project src/tsconfig.json --fix \"{src,test,examples}/**/*.ts\" && prettier --write \"{src,test,examples}/**/*.{ts,js}\"",
"precommit": "lint-staged && npm test",
"test":
"rimraf .test-out && tsc --skipLibCheck -p test && mocha '.test-out/test/**/*.spec.js' --require .test-out/test/index.js",
"test:watch": "nodemon -e js,ts --exec npm run test",
"lint": "tslint 'src/**/*.ts' 'test/**/*.ts'",
"lint:watch": "nodemon -e ts --exec npm run lint",
"cover": "nyc npm test",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"do-publish": "npm run build && npm run lint && npm run cover && npm publish"
"publish:pre": "npm run lint && npm run build && npm run cover",
"publish:post": "npm publish && git push --follow-tags",
"release:prerelease":
"npm run publish:pre && npm version prerelease && npm run publish:post",
"release:patch":
"npm run publish:pre && npm version patch && npm run publish:post",
"release:minor":
"npm run publish:pre && npm version minor && npm run publish:post",
"release:major":
"npm run publish:pre && npm version major && npm run publish:post"
},
"prettier": {
"semi": false,
"singleQuote": true
},
"lint-staged": {
"*.ts": ["tslint --fix", "prettier --write", "git add"]
},
"repository": {

@@ -25,16 +45,7 @@ "type": "git",

},
"files": [
"lib",
"LICENSE.md",
"README.md"
],
"files": ["lib", "LICENSE.md", "README.md"],
"directories": {
"lib": "lib"
},
"keywords": [
"mobx",
"validation",
"state management",
"react"
],
"keywords": ["mobx", "validation", "state management", "react"],
"author": "Jeff Hansen <jeff@jeffijoe.com>",

@@ -47,20 +58,24 @@ "license": "MIT",

"devDependencies": {
"@types/chai": "^4.0.0",
"@types/chai": "^4.1.2",
"@types/email-validator": "^1.0.30",
"@types/is-url": "^1.2.28",
"@types/mocha": "^2.2.41",
"@types/node": "^7.0.29",
"@types/sinon-chai": "^2.7.28",
"chai": "^4.0.2",
"coveralls": "^2.13.1",
"mobx": "^3.1.15",
"mocha": "^3.4.2",
"nodemon": "^1.11.0",
"nyc": "^11.0.2",
"rimraf": "^2.6.1",
"sinon": "^2.3.4",
"sinon-chai": "^2.11.0",
"tslint": "^5.4.3",
"tslint-config-standard": "^5.0.2",
"typescript": "2.3.4"
"@types/mocha": "^2.2.48",
"@types/node": "^9.4.7",
"@types/sinon-chai": "^2.7.29",
"chai": "^4.1.2",
"coveralls": "^3.0.0",
"husky": "^0.14.3",
"lint-staged": "^7.0.0",
"mobx": "^4.0.1",
"mocha": "^5.0.4",
"nodemon": "^1.17.1",
"nyc": "^11.6.0",
"prettier": "^1.11.1",
"rimraf": "^2.6.2",
"sinon": "^4.4.4",
"sinon-chai": "^3.0.0",
"tslint": "^5.9.1",
"tslint-config-prettier": "^1.10.0",
"tslint-config-standard": "^7.0.0",
"typescript": "2.7.2"
},

@@ -71,5 +86,5 @@ "peerDependencies": {

"dependencies": {
"email-validator": "^1.0.7",
"email-validator": "^1.1.1",
"is-url": "^1.2.2"
}
}

@@ -29,8 +29,8 @@ # validx

* [`reset()`](#reset)
* [`addErrors()`](#adderrors)
* [`getErrors()`](#geterrors)
* [`getError()`](#geterror)
* [`clearErrors()`](#clearerrors)
* [`errors`](#errors)
* [`isValid`](#isvalid)
* [`addErrors()`](#adderrors)
* [`getErrors()`](#geterrors)
* [`getError()`](#geterror)
* [`clearErrors()`](#clearerrors)
* [`errors`](#errors)
* [`isValid`](#isvalid)
* [Validators](#validators)

@@ -240,3 +240,3 @@ * [Built-in validators](#built-in-validators)

## `addErrors()`
### `addErrors()`

@@ -261,3 +261,3 @@ If you at some point want to add errors without calling validate, this

## `getErrors()`
### `getErrors()`

@@ -279,3 +279,3 @@ Safer way to get errors for a field rather than using `errors.field`,

## `getError()`
### `getError()`

@@ -297,3 +297,3 @@ Convenience method for `getErrors('field')[0]`.

## `clearErrors()`
### `clearErrors()`

@@ -318,3 +318,3 @@ Clear errors for a single field, instead of reseting the whole context.

## `errors`
### `errors`

@@ -342,3 +342,3 @@ A MobX `computed` map of field -> errors. When `validate` discovers validation errors, it

## `isValid`
### `isValid`

@@ -345,0 +345,0 @@ A MobX `computed` property that determines whether the context

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc