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

calidation

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

calidation - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

20

dist/Validation.js

@@ -43,5 +43,11 @@ 'use strict';

return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Validation.__proto__ || Object.getPrototypeOf(Validation)).call.apply(_ref, [this].concat(args))), _this), _this.getInitialFieldValues = function () {
return Object.keys(_this.props.config).reduce(function (fields, field) {
return _extends({}, fields, _defineProperty({}, field, _this.props.initialValues[field] || ''));
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Validation.__proto__ || Object.getPrototypeOf(Validation)).call.apply(_ref, [this].concat(args))), _this), _this.getFieldValues = function () {
var _this$props = _this.props,
config = _this$props.config,
fields = _this$props.fields,
initialValues = _this$props.initialValues;
return Object.keys(config).reduce(function (allFields, field) {
return _extends({}, allFields, _defineProperty({}, field, fields[field] || initialValues[field] || ''));
}, {});

@@ -54,3 +60,3 @@ }, _temp), _possibleConstructorReturn(_this, _ret);

value: function componentDidMount() {
this.props.register(this.props.config, this.getInitialFieldValues());
this.props.register(this.props.config, this.getFieldValues());
}

@@ -69,3 +75,4 @@ }, {

submitted = _props.submitted,
children = _props.children;
children = _props.children,
config = _props.config;

@@ -75,5 +82,6 @@

errors: errors,
fields: fields,
fields: this.getFieldValues(),
submitted: submitted
};
return children(childrenArgs);

@@ -80,0 +88,0 @@ }

@@ -18,6 +18,4 @@ 'use strict';

var _validators = require('./validators');
var _calidators = require('calidators');
var _validators2 = _interopRequireDefault(_validators);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -31,2 +29,14 @@

var defaultValidators = {
isBlacklisted: _calidators.isBlacklisted,
isEmail: _calidators.isEmail,
isEqual: _calidators.isEqual,
isGreaterThan: _calidators.isGreaterThan,
isLessThan: _calidators.isLessThan,
isRequired: _calidators.isRequired,
isNumber: _calidators.isNumber,
isRegexMatch: _calidators.isRegexMatch,
isWhitelisted: _calidators.isWhitelisted
};
var _createContext = (0, _react.createContext)({}),

@@ -87,3 +97,3 @@ Provider = _createContext.Provider,

return _react2.default.createElement(TargetComponent, _extends({}, props, {
validators: _extends({}, _validators2.default, validators)
validators: _extends({}, defaultValidators, validators)
}));

@@ -90,0 +100,0 @@ }

{
"name": "calidation",
"version": "1.1.1",
"version": "1.2.0",
"description": "A red hot validation library for React",

@@ -22,3 +22,4 @@ "main": "dist/index.js",

"test": "jest",
"test:watch": "jest --watch",
"test:watch": "jest --watch --coverage",
"test:coverage": "jest --coverage",
"semantic-release": "semantic-release",

@@ -35,2 +36,3 @@ "travis-deploy-once": "travis-deploy-once"

"cz-conventional-changelog": "^2.1.0",
"dom-testing-library": "^1.1.0",
"husky": "^0.14.3",

@@ -42,2 +44,3 @@ "jest": "^22.4.3",

"react-dom": "^16.3.1",
"react-testing-library": "^2.0.0",
"rimraf": "^2.6.2",

@@ -61,4 +64,10 @@ "semantic-release": "^15.1.5",

"dependencies": {
"invariant": "^2.2.4"
"calidators": "^1.0.0",
"invariant": "^2.2.4",
"prop-types": "^15.6.1"
},
"jest": {
"coverageDirectory": "./coverage/",
"collectCoverage": true
}
}

@@ -5,2 +5,4 @@ # calidation

[![Build Status](https://travis-ci.org/selbekk/calidation.svg?branch=master)](https://travis-ci.org/selbekk/calidation) [![codecov](https://codecov.io/gh/selbekk/calidation/branch/master/graph/badge.svg)](https://codecov.io/gh/selbekk/calidation)
```

@@ -40,3 +42,3 @@ yarn add calidation

password: {
isRequired: 'Password is required!',
isRequired: 'Password is also required!',
},

@@ -48,3 +50,3 @@ };

You can add as many validators as you want, and they'll be run from top to
bottom.
bottom. For more about validators, go to the [validators](#validators) section!

@@ -58,14 +60,14 @@ ### Validate that form

const config = {...}; // We did this above!
const config = {...}; // See above
const MyForm = props => (
<FormValidation onSubmit={props.onSubmit} config={config}>
{({ fields, errors }) => (
{({ fields, errors, submitted }) => (
<>
<label>
Username: <input name="username" value={fields.username} />
{errors.username && <span>{errors.username}</span>}
{submitted && errors.username && <span>{errors.username}</span>}
</label>
<label>
Password: <input name="password" value={fields.password} />
{errors.password && <span>{errors.password}</span>}
{submitted && errors.password && <span>{errors.password}</span>}
</label>

@@ -128,6 +130,6 @@ <button>Log in</button>

{/* ...tons of other components and other stuff */}
<Validation config={props.config}>
<Validation config={props.anotherConfig}>
{({ fields, errors }) => (
<>
And what does he do?
What does he do?
<input name="dadWork" value={fields.dadWork} />

@@ -142,4 +144,11 @@ </>

The `onSubmit` handler will receive a merged object of all the validated fields
below it, as well as a merged object of all the errors.
below it, as well as a merged object of all the errors:
```js
const onSubmit = ({ fields, errors, isValid }) => {
// fields and errors now contain both `daddy` and `dadWork`
// isValid is true if all forms are valid, otherwise false.
};
```
## Validators

@@ -264,8 +273,30 @@

### Deluxe validators
#### `isWhitelisted`
I haven't implemented any yet, but in the future I imagine you can import some
validators that aren't used that often from `calidation/validators`. But that's
a future issue to adress.
Validates that a field is present in a provided whitelist. The whitelist must be
an array.
```js
firstName: {
isWhitelisted : {
message: 'Bros only, bro',
whitelist: ['Chad', 'Bret'],
},
},
```
#### `isBlacklisted`
Validates that a field is not present in a provided blacklist. The blacklist
must be an array.
```js
firstName: {
isBlacklisted : {
message: 'Bros are not welcome',
blacklist: ['Chad', 'Bret'],
},
},
```
### Custom validators

@@ -272,0 +303,0 @@

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