Socket
Socket
Sign inDemoInstall

@lion/validate

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lion/validate - npm Package Compare versions

Comparing version 0.6.8 to 0.7.0

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [0.7.0](https://github.com/ing-bank/lion/compare/@lion/validate@0.6.8...@lion/validate@0.7.0) (2020-03-01)
### Features
* **validate:** use static validatorName instead of instance name ([#600](https://github.com/ing-bank/lion/issues/600)) ([7c45dd6](https://github.com/ing-bank/lion/commit/7c45dd683984e88e3216fba9fcae1b6dc73835b2))
## [0.6.8](https://github.com/ing-bank/lion/compare/@lion/validate@0.6.7...@lion/validate@0.6.8) (2020-02-26)

@@ -8,0 +19,0 @@

4

package.json
{
"name": "@lion/validate",
"version": "0.6.8",
"version": "0.7.0",
"description": "Validate your form elements",

@@ -47,3 +47,3 @@ "author": "ing-bank",

},
"gitHead": "8e5cc9c14ac6706efad917cea7af548aed371e7f"
"gitHead": "04db59c9675b9e56b50dfc147201eea530b1d754"
}

@@ -53,5 +53,4 @@ # Validate

class IsInitialsExample extends Validator {
constructor(...args) {
super(...args);
this.name = 'IsExampleInitials';
static get validatorName() {
return 'IsExampleInitials';
}

@@ -58,0 +57,0 @@

@@ -326,4 +326,8 @@ /* eslint-disable class-methods-use-this, camelcase, no-param-reassign, max-classes-per-file */

);
const /** @type {Validator[]} */ syncValidators = filteredValidators.filter(v => !v.async);
const /** @type {Validator[]} */ asyncValidators = filteredValidators.filter(v => v.async);
const /** @type {Validator[]} */ syncValidators = filteredValidators.filter(
v => !v.constructor.async,
);
const /** @type {Validator[]} */ asyncValidators = filteredValidators.filter(
v => v.constructor.async,
);

@@ -382,3 +386,3 @@ /**

const resultValidators = this._allValidators.filter(
v => !v.async && v instanceof ResultValidator,
v => !v.constructor.async && v instanceof ResultValidator,
);

@@ -420,3 +424,3 @@

}
validationStates[v.type][v.name] = true;
validationStates[v.type][v.constructor.name] = true;
});

@@ -463,3 +467,3 @@ this.validationStates = validationStates;

// throws in constructor are not visible to end user so we do both
const errorMessage = `This component does not support the validator type "${v.type}" used in "${v.name}". You may change your validators type or add it to the components "static get validationTypes() {}".`;
const errorMessage = `This component does not support the validator type "${v.type}" used in "${v.constructor.validatorName}". You may change your validators type or add it to the components "static get validationTypes() {}".`;
// eslint-disable-next-line no-console

@@ -466,0 +470,0 @@ console.error(errorMessage, this);

@@ -7,4 +7,2 @@ import { fakeExtendsEventTarget } from './utils/fake-extends-event-target.js';

this.name = '';
this.async = false;
this.__param = param;

@@ -15,2 +13,10 @@ this.__config = config || {};

static get validatorName() {
return '';
}
static get async() {
return false;
}
/**

@@ -23,4 +29,6 @@ * @desc The function that returns a Boolean

execute(/* modelValue, param */) {
if (!this.name) {
throw new Error('You must provide a name like "this.name = \'IsCat\'" for your Validator');
if (!this.validatorName) {
throw new Error(
'A validator needs to have a name! Please set it via "static get validatorName() { return \'IsCat\'; }"',
);
}

@@ -58,3 +66,3 @@ }

const composedData = {
name: this.name,
name: this.constructor.validatorName,
type: this.type,

@@ -61,0 +69,0 @@ params: this.param,

@@ -12,5 +12,4 @@ /* eslint-disable max-classes-per-file */

export class IsDate extends Validator {
constructor(...args) {
super(...args);
this.name = 'IsDate';
static get validatorName() {
return 'IsDate';
}

@@ -29,5 +28,4 @@

export class MinDate extends Validator {
constructor(...args) {
super(...args);
this.name = 'MinDate';
static get validatorName() {
return 'MinDate';
}

@@ -45,5 +43,4 @@

export class MaxDate extends Validator {
constructor(...args) {
super(...args);
this.name = 'MaxDate';
static get validatorName() {
return 'MaxDate';
}

@@ -61,5 +58,4 @@

export class MinMaxDate extends Validator {
constructor(...args) {
super(...args);
this.name = 'MinMaxDate';
static get validatorName() {
return 'MinMaxDate';
}

@@ -77,5 +73,4 @@

export class IsDateDisabled extends Validator {
constructor(...args) {
super(...args);
this.name = 'IsDateDisabled';
static get validatorName() {
return 'IsDateDisabled';
}

@@ -82,0 +77,0 @@

@@ -14,5 +14,4 @@ /* eslint-disable max-classes-per-file */

export class IsNumber extends Validator {
constructor(...args) {
super(...args);
this.name = 'IsNumber';
static get validatorName() {
return 'IsNumber';
}

@@ -31,5 +30,4 @@

export class MinNumber extends Validator {
constructor(...args) {
super(...args);
this.name = 'MinNumber';
static get validatorName() {
return 'MinNumber';
}

@@ -47,5 +45,4 @@

export class MaxNumber extends Validator {
constructor(...args) {
super(...args);
this.name = 'MaxNumber';
static get validatorName() {
return 'MaxNumber';
}

@@ -63,5 +60,4 @@

export class MinMaxNumber extends Validator {
constructor(...args) {
super(...args);
this.name = 'MinMaxNumber';
static get validatorName() {
return 'MinMaxNumber';
}

@@ -68,0 +64,0 @@

import { Validator } from '../Validator.js';
export class Required extends Validator {
constructor(...args) {
super(...args);
this.name = 'Required';
static get validatorName() {
return 'Required';
}

@@ -8,0 +7,0 @@

@@ -7,5 +7,4 @@ /* eslint-disable max-classes-per-file */

export class IsString extends Validator {
constructor(...args) {
super(...args);
this.name = 'IsString';
static get validatorName() {
return 'IsString';
}

@@ -24,5 +23,4 @@

export class EqualsLength extends Validator {
constructor(...args) {
super(...args);
this.name = 'EqualsLength';
static get validatorName() {
return 'EqualsLength';
}

@@ -40,5 +38,4 @@

export class MinLength extends Validator {
constructor(...args) {
super(...args);
this.name = 'MinLength';
static get validatorName() {
return 'MinLength';
}

@@ -56,5 +53,4 @@

export class MaxLength extends Validator {
constructor(...args) {
super(...args);
this.name = 'MaxLength';
static get validatorName() {
return 'MaxLength';
}

@@ -72,5 +68,4 @@

export class MinMaxLength extends Validator {
constructor(...args) {
super(...args);
this.name = 'MinMaxLength';
static get validatorName() {
return 'MinMaxLength';
}

@@ -89,5 +84,4 @@

export class IsEmail extends Validator {
constructor(...args) {
super(...args);
this.name = 'IsEmail';
static get validatorName() {
return 'IsEmail';
}

@@ -94,0 +88,0 @@

@@ -5,5 +5,4 @@ /* eslint-disable max-classes-per-file, class-methods-use-this */

export class AlwaysInvalid extends Validator {
constructor(...args) {
super(...args);
this.name = 'AlwaysInvalid';
static get validatorName() {
return 'AlwaysInvalid';
}

@@ -18,5 +17,4 @@

export class AlwaysValid extends Validator {
constructor(...args) {
super(...args);
this.name = 'AlwaysValid';
static get validatorName() {
return 'AlwaysValid';
}

@@ -31,5 +29,4 @@

export class AsyncAlwaysValid extends AlwaysValid {
constructor(...args) {
super(...args);
this.async = true;
static get async() {
return true;
}

@@ -43,5 +40,4 @@

export class AsyncAlwaysInvalid extends AlwaysValid {
constructor(...args) {
super(...args);
this.async = true;
static get async() {
return true;
}

@@ -48,0 +44,0 @@

@@ -1,21 +0,20 @@

import { expect, fixture, html, unsafeStatic, defineCE, aTimeout } from '@open-wc/testing';
import { LitElement } from '@lion/core';
import { aTimeout, defineCE, expect, fixture, html, unsafeStatic } from '@open-wc/testing';
import sinon from 'sinon';
import { LitElement } from '@lion/core';
import {
MaxLength,
MinLength,
Required,
ResultValidator,
Unparseable,
ValidateMixin,
Validator,
} from '../index.js';
import {
AlwaysInvalid,
AlwaysValid,
AlwaysInvalid,
AsyncAlwaysInvalid,
AsyncAlwaysValid,
AsyncAlwaysInvalid,
} from '../test-helpers.js';
import {
ValidateMixin,
Unparseable,
Validator,
ResultValidator,
Required,
MinLength,
MaxLength,
} from '../index.js';
export function runValidateMixinSuite(customConfig) {

@@ -107,5 +106,8 @@ const cfg = {

super();
this.name = 'MajorValidator';
this.type = 'major error';
}
static get validatorName() {
return 'MajorValidator';
}
}

@@ -222,5 +224,4 @@ const el = await fixture(html`<${tag}></${tag}>`);

class MyResult extends ResultValidator {
constructor(...args) {
super(...args);
this.name = 'ResultValidator';
static get validatorName() {
return 'ResultValidator';
}

@@ -290,3 +291,2 @@ }

super(...args);
this.name = 'isCat';
this.execute = (modelValue, param) => {

@@ -298,2 +298,6 @@ const validateString = param && param.number ? `cat${param.number}` : 'cat';

}
static get validatorName() {
return 'isCat';
}
}

@@ -304,5 +308,8 @@

super(...args);
this.name = 'otherValidator';
this.execute = () => true;
}
static get validatorName() {
return 'otherValidator';
}
}

@@ -365,7 +372,7 @@

el.modelValue = 'cat';
expect(el.validationStates.error.isCat).to.be.undefined;
expect(el.validationStates.error.IsCat).to.be.undefined;
el.modelValue = 'dog';
expect(el.validationStates.error.isCat).to.be.true;
expect(el.validationStates.error.IsCat).to.be.true;
el.modelValue = '';
expect(el.validationStates.error.isCat).to.be.undefined;
expect(el.validationStates.error.IsCat).to.be.undefined;
});

@@ -400,8 +407,10 @@

class IsAsyncCat extends Validator {
constructor(param, config) {
super(param, config);
this.name = 'delayed-cat';
this.async = true;
static get validatorName() {
return 'delayed-cat';
}
static get async() {
return true;
}
/**

@@ -779,5 +788,8 @@ * @desc the function that determines the validator. It returns true when

super(...args);
this.name = 'ContainsLowercaseA';
this.execute = modelValue => !modelValue.includes('a');
}
static get validatorName() {
return 'ContainsLowercaseA';
}
}

@@ -788,8 +800,11 @@

super(...args);
this.name = 'containsLowercaseB';
this.execute = modelValue => !modelValue.includes('b');
}
static get validatorName() {
return 'containsLowercaseB';
}
}
it('stores validity of individual Validators in ".validationStates.error[validator.name]"', async () => {
it('stores validity of individual Validators in ".validationStates.error[validator.validatorName]"', async () => {
const el = await fixture(html`

@@ -796,0 +811,0 @@ <${tag}

@@ -44,5 +44,4 @@ import { expect, fixture, html, unsafeStatic, defineCE } from '@open-wc/testing';

ContainsLowercaseA = class extends Validator {
constructor(...args) {
super(...args);
this.name = 'ContainsLowercaseA';
static get validatorName() {
return 'ContainsLowercaseA';
}

@@ -57,5 +56,4 @@

class ContainsCat extends Validator {
constructor(...args) {
super(...args);
this.name = 'ContainsCat';
static get validatorName() {
return 'ContainsCat';
}

@@ -249,3 +247,3 @@

return html`
Custom for ${this.feedbackData[0].validator.name}
Custom for ${this.feedbackData[0].validator.constructor.name}
`;

@@ -252,0 +250,0 @@ }

@@ -16,3 +16,3 @@ import { expect } from '@open-wc/testing';

const validator = new IsDate();
expect(validator.name).to.equal('IsDate');
expect(validator.constructor.name).to.equal('IsDate');

@@ -32,3 +32,3 @@ isEnabled = validator.execute(new Date());

const validator = new MinDate(new Date('2018/02/02'));
expect(validator.name).to.equal('MinDate');
expect(validator.constructor.name).to.equal('MinDate');

@@ -51,3 +51,3 @@ isEnabled = validator.execute(new Date('2018-02-03'));

const validator = new MaxDate(new Date('2018/02/02'));
expect(validator.name).to.equal('MaxDate');
expect(validator.constructor.name).to.equal('MaxDate');

@@ -73,3 +73,3 @@ isEnabled = validator.execute(new Date('2018-02-01'));

});
expect(validator.name).to.equal('MinMaxDate');
expect(validator.constructor.name).to.equal('MinMaxDate');

@@ -95,3 +95,3 @@ isEnabled = validator.execute(new Date('2018/02/03'));

const validator = new IsDateDisabled(d => d.getDate() === 3);
expect(validator.name).to.equal('IsDateDisabled');
expect(validator.constructor.name).to.equal('IsDateDisabled');

@@ -98,0 +98,0 @@ isDisabled = validator.execute(new Date('2018/02/04'));

@@ -14,3 +14,3 @@ import { expect } from '@open-wc/testing';

const validator = new IsNumber();
expect(validator.name).to.equal('IsNumber');
expect(validator.constructor.name).to.equal('IsNumber');

@@ -30,3 +30,3 @@ isEnabled = validator.execute(4);

const validator = new MinNumber(3);
expect(validator.name).to.equal('MinNumber');
expect(validator.constructor.name).to.equal('MinNumber');

@@ -43,3 +43,3 @@ isEnabled = validator.execute(3);

const validator = new MaxNumber(3);
expect(validator.name).to.equal('MaxNumber');
expect(validator.constructor.name).to.equal('MaxNumber');

@@ -56,3 +56,3 @@ isEnabled = validator.execute(3);

const validator = new MinMaxNumber({ min: 2, max: 4 });
expect(validator.name).to.equal('MinMaxNumber');
expect(validator.constructor.name).to.equal('MinMaxNumber');

@@ -59,0 +59,0 @@ isEnabled = validator.execute(2);

@@ -16,3 +16,3 @@ import { expect } from '@open-wc/testing';

const validator = new IsString();
expect(validator.name).to.equal('IsString');
expect(validator.constructor.name).to.equal('IsString');

@@ -32,3 +32,3 @@ isEnabled = validator.execute('foo');

const validator = new EqualsLength(3);
expect(validator.name).to.equal('EqualsLength');
expect(validator.constructor.name).to.equal('EqualsLength');

@@ -48,3 +48,3 @@ isEnabled = validator.execute('foo');

const validator = new MinLength(3);
expect(validator.name).to.equal('MinLength');
expect(validator.constructor.name).to.equal('MinLength');

@@ -61,3 +61,3 @@ isEnabled = validator.execute('foo');

const validator = new MaxLength(3);
expect(validator.name).to.equal('MaxLength');
expect(validator.constructor.name).to.equal('MaxLength');

@@ -74,3 +74,3 @@ isEnabled = validator.execute('foo');

const validator = new MinMaxLength({ min: 2, max: 4 });
expect(validator.name).to.equal('MinMaxLength');
expect(validator.constructor.name).to.equal('MinMaxLength');

@@ -90,3 +90,3 @@ isEnabled = validator.execute('foo');

const validator = new IsEmail();
expect(validator.name).to.equal('IsEmail');
expect(validator.constructor.name).to.equal('IsEmail');

@@ -93,0 +93,0 @@ isEnabled = validator.execute('foo@bar.com');

@@ -35,3 +35,5 @@ import { expect, fixture, html, unsafeStatic, defineCE } from '@open-wc/testing';

new MyValidator().execute();
}).to.throw('You must provide a name like "this.name = \'IsCat\'" for your Validator');
}).to.throw(
'A validator needs to have a name! Please set it via "static get validatorName() { return \'IsCat\'; }"',
);
});

@@ -41,5 +43,4 @@

class MyValidator extends Validator {
constructor(...args) {
super(...args);
this.name = 'MyValidator';
static get validatorName() {
return 'MyValidator';
}

@@ -67,5 +68,4 @@ }

class MyValidator extends Validator {
constructor(...args) {
super(...args);
this.name = 'MyValidator';
static get validatorName() {
return 'MyValidator';
}

@@ -87,5 +87,4 @@ }

class MyValidator extends Validator {
constructor(...args) {
super(...args);
this.name = 'MyValidator';
static get validatorName() {
return 'MyValidator';
}

@@ -92,0 +91,0 @@

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