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

@gemsorg/modules

Package Overview
Dependencies
Maintainers
3
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gemsorg/modules - npm Package Compare versions

Comparing version 0.1.16 to 0.1.17

src/form/Form/validation/getDefaultRuleMessage.js

2

flow-typed/types.js

@@ -8,3 +8,3 @@ // @flow

validation?: {
[key: string]: string
[key: string]: string | bool
},

@@ -11,0 +11,0 @@ [key: string]: Module | Array<Module> | string | Object | number | boolean,

@@ -19,2 +19,3 @@ // @flow

formValidationRules,
getDefaultRuleMessage,
FormContext,

@@ -94,2 +95,3 @@ FormData,

formValidationRules,
getDefaultRuleMessage,
getModuleControlsMap,

@@ -96,0 +98,0 @@ PropControlTypes,

{
"name": "@gemsorg/modules",
"version": "0.1.16",
"version": "0.1.17",
"description": "gems modules",

@@ -23,9 +23,9 @@ "main": "index.js",

"dependencies": {
"@gemsorg/components": "^0.1.8",
"@gemsorg/components": "^0.1.9",
"@gemsorg/uikit": "^0.1.2",
"@gemsorg/validation": "^0.1.3",
"debounce": "^1.2.0",
"react-player": "^1.6.6"
"react-player": "^1.7.0"
},
"gitHead": "1480d8b72361b399f001d06b322c2050ad9bdf56"
"gitHead": "42b70f4b832ae17b99f9a06821e178a528a80db0"
}

@@ -5,2 +5,3 @@ // @flow

import formValidationRules from './validation/formValidationRules';
import getDefaultRuleMessage from './validation/getDefaultRuleMessage';
import { calculateVerificationScore } from './verification/verification';

@@ -26,2 +27,3 @@

formValidationRules,
getDefaultRuleMessage,
FormContext,

@@ -28,0 +30,0 @@ FormData,

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

import { validateForm } from '@gemsorg/validation';
import { validateForm, rules } from '@gemsorg/validation';

@@ -53,7 +53,7 @@ import formValidationRules from '../formValidationRules';

const rules = formValidationRules(form.modules, controls);
const formRules = formValidationRules(form.modules, controls);
describe('formValidationRules()', () => {
it('should create validation rules object', () => {
const { field1, field2 } = rules;
const { field1, field2 } = formRules;

@@ -68,2 +68,32 @@ expect(Array.isArray(field1)).toBeTruthy();

});
it('should provide default messages', () => {
const { field1 } = formValidationRules(
[
{
type: 'module1',
name: 'field1',
validation: {
isRequired: true,
isDefined,
},
},
],
{
module1: {
module: {
type: 'module1',
validation: {
isRequired: rules.isRequired,
isDefined,
},
},
},
}
);
expect(field1[0][0]).toEqual(rules.isRequired);
expect(field1[0][1]).toEqual('Is required');
expect(field1[1][0]).toEqual(isDefined);
expect(field1[1][1]).toEqual('Invalid');
});
});

@@ -78,3 +108,3 @@

},
rules
formRules
);

@@ -87,3 +117,3 @@ expect(result).toEqual({ field1: 'not zero' });

},
rules
formRules
);

@@ -90,0 +120,0 @@ expect(result2).toEqual(null);

// @flow
import getDefaultRuleMessage from './getDefaultRuleMessage';

@@ -6,4 +7,11 @@ const getFieldRules = (validation: Object, rules: Object) =>

.filter(ruleName => !!rules[ruleName])
.map(ruleName => [rules[ruleName], validation[ruleName]]);
.map(ruleName => {
const message =
typeof validation[ruleName] === 'string'
? validation[ruleName]
: getDefaultRuleMessage(ruleName);
return [rules[ruleName], message];
});
const formValidationRules = (modules: Array<Module>, controlsMap: Object) =>

@@ -10,0 +18,0 @@ modules.reduce((formRules, module) => {

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