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

joi-plus

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

joi-plus - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

4

CHANGELOG.md
## Changelog
### 1.2.2
Add decimal string validation
### 1.2.1

@@ -4,0 +8,0 @@

@@ -28,2 +28,3 @@ 'use strict';

'string.numeric': '{{#label}} must only contain numeric characters',
'string.decimal': '{{#label}} must be a decimal number of maximum {{#digit}} digits and {{#decimal}} decimal places',
'string.base32': '{{#label}} must be a valid base32 string',

@@ -121,2 +122,33 @@ 'string.countryCode': '{{#label}} must be a valid ISO {{#type}} country code',

},
decimal: {
method(digit, decimal) {
return this.$_addRule({ name: 'decimal', args: { digit, decimal } });
},
args: [
{
ref: true,
name: 'digit',
assert: (value) => typeof value === 'number',
message: `must be a number`
},
{
ref: true,
name: 'decimal',
assert: (value) => typeof value === 'number',
message: `must be a number`
}
],
validate: (value, helpers, args, options) => {
let digit = args.digit;
let decimal = args.decimal;
let pattern = `^(0(\\.\\d{1,${decimal}})?|([1-9]\\d{0,${digit - decimal - 1}}(\\.\\d{1,${decimal}})?))$`;
let regex = new RegExp(pattern);
if (regex.test(value)) {
return value;
}
return helpers.error('string.decimal', { digit, decimal });
}
},
base32: {

@@ -123,0 +155,0 @@ validate: (value, helpers, args, options) => {

3

package.json
{
"name": "joi-plus",
"version": "1.2.1",
"version": "1.2.2",
"description": "Joi with extra rules for string and array.",

@@ -20,2 +20,3 @@ "repository": "git://github.com/flamehamster/joi-plus",

"numeric",
"decimal",
"base32",

@@ -22,0 +23,0 @@ "password",

@@ -26,2 +26,5 @@ # Joi-Plus

* Joi.string().decimal(digit, decimal)
* Requires the string value to be a valid decimal number.
* Joi.string().base32()

@@ -109,2 +112,6 @@ * Requires the value to be a valid base32 string.

.required()
salary: Joi.string()
.decimal(11,2)
.required()
});

@@ -145,2 +152,6 @@ ```

* `salary`
* a required string
* must be a valid decimal number with up to 11 digits with 2 decimal places
#### Sanitize

@@ -147,0 +158,0 @@ Using Joi.string().sanitize() with sanitization libraries such as [sanitize-html](https://www.npmjs.com/package/sanitize-html)

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