@chantouchsek/validatorjs
Advanced tools
Comparing version 1.0.5 to 1.1.0
@@ -5,2 +5,18 @@ # Changelog | ||
## [1.1.0](https://github.com/chantouchsek/validator-js/compare/v1.0.5...v1.1.0) (2022-07-06) | ||
### Features | ||
* :beers: added validate on numeric max and min ([e3e27d1](https://github.com/chantouchsek/validator-js/commit/e3e27d14c688d03122d7e364de969baecd9b1f7f)) | ||
### Bug Fixes | ||
* :fire: min and max value, also update readme ([27a56e6](https://github.com/chantouchsek/validator-js/commit/27a56e6a0f0a119ad1257c0260bb843a1623844d)) | ||
* cast the type ([3f6835e](https://github.com/chantouchsek/validator-js/commit/3f6835e4e3486fadbbcdd07414be4281d37bb16c)) | ||
* **deps:** bump actions/setup-node from 3.2.0 to 3.3.0 ([4b9def6](https://github.com/chantouchsek/validator-js/commit/4b9def6f7de1ec70a06aff9efbf75ae18c08eb80)) | ||
* initial optimized ([f61e73e](https://github.com/chantouchsek/validator-js/commit/f61e73e1120673c81ee54ba7eebdb22017536425)) | ||
* removed unusd import ([43a7925](https://github.com/chantouchsek/validator-js/commit/43a7925499a316e8805cdbb3c81ff6221f1c305a)) | ||
### [1.0.5](https://github.com/chantouchsek/validator-js/compare/v1.0.4...v1.0.5) (2022-05-27) | ||
@@ -7,0 +23,0 @@ |
@@ -27,4 +27,3 @@ "use strict"; | ||
rawMessage = require(`./lang/${lang}`); | ||
rawMessage = rawMessage.default || rawMessage; | ||
this._set(lang, rawMessage); | ||
this._set(lang, rawMessage.default); | ||
} | ||
@@ -31,0 +30,0 @@ catch (e) { |
@@ -83,3 +83,2 @@ "use strict"; | ||
getSize(value) { | ||
var _a; | ||
const input = value || this.input; | ||
@@ -92,11 +91,10 @@ if (input instanceof Array) { | ||
} | ||
if ((_a = this.validator) === null || _a === void 0 ? void 0 : _a._hasNumericRule(this.attribute)) { | ||
if (this.validator._hasNumericRule(this.attribute)) { | ||
return parseFloat(input); | ||
} | ||
return input === null || input === void 0 ? void 0 : input.length; | ||
return input.length; | ||
} | ||
_getValueType() { | ||
var _a; | ||
if (typeof this.input === 'number' || | ||
((_a = this.validator) === null || _a === void 0 ? void 0 : _a._hasNumericRule(this.attribute))) { | ||
this.validator._hasNumericRule(this.attribute)) { | ||
return 'numeric'; | ||
@@ -121,2 +119,3 @@ } | ||
static _setRules() { | ||
const numericRules = ['numeric']; | ||
Rule.rules = { | ||
@@ -140,6 +139,2 @@ ...this.rules, | ||
}, | ||
min(value, req) { | ||
const size = this.getSize(value); | ||
return size >= req; | ||
}, | ||
required_if(val, req) { | ||
@@ -196,4 +191,18 @@ req = this.getParameters(); | ||
}, | ||
min(val, req) { | ||
const size = this.getSize(val); | ||
const numericRule = this.validator.getRule('numeric'); | ||
const hasNumeric = this.validator._hasRule(this.attribute, numericRules); | ||
if (numericRule.validate(val, {}) && hasNumeric && !(0, utils_1.isFloat)(val)) { | ||
return String(val).trim().length >= parseInt(req); | ||
} | ||
return size >= req; | ||
}, | ||
max(val, req) { | ||
const size = this.getSize(); | ||
const size = this.getSize(val); | ||
const numericRule = this.validator.getRule('numeric'); | ||
const hasNumeric = this.validator._hasRule(this.attribute, numericRules); | ||
if (numericRule.validate(val, {}) && hasNumeric && !(0, utils_1.isFloat)(val)) { | ||
return String(val).trim().length <= parseInt(req); | ||
} | ||
return size <= req; | ||
@@ -266,3 +275,3 @@ }, | ||
return !!(numericRule.validate(val, {}) && | ||
String(val.trim()).length === parseInt(req)); | ||
String(val).trim().length === parseInt(req)); | ||
}, | ||
@@ -269,0 +278,0 @@ digits_between(val) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.onlyDigits = exports.toSnakeCase = exports.toCamelCase = exports.formatter = void 0; | ||
exports.isFloat = exports.onlyDigits = exports.toSnakeCase = exports.toCamelCase = exports.formatter = void 0; | ||
const formatter = (attribute) => { | ||
@@ -23,1 +23,10 @@ return attribute.replace(/[_.\[]/g, ' ').replace(/]/g, ''); | ||
exports.onlyDigits = onlyDigits; | ||
function isFloat(n, shouldCoerce = true) { | ||
if (shouldCoerce) { | ||
if (typeof n === 'string') { | ||
n = parseFloat(n); | ||
} | ||
} | ||
return n === +n && n !== (n | 0); | ||
} | ||
exports.isFloat = isFloat; |
{ | ||
"name": "@chantouchsek/validatorjs", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"description": "The validator-js library makes data validation in JavaScript very easy in both the browser and Node.js.", | ||
@@ -55,3 +55,3 @@ "main": "dist/main.js", | ||
"@types/jest": "^27.4.0", | ||
"@types/node": "^17.0.5", | ||
"@types/node": "^18.0.0", | ||
"@typescript-eslint/eslint-plugin": "^5.8.1", | ||
@@ -66,3 +66,3 @@ "@typescript-eslint/parser": "^5.8.1", | ||
"jest": "^27.5.1", | ||
"lint-staged": "^12.1.4", | ||
"lint-staged": "^13.0.0", | ||
"node-notifier": "^10.0.0", | ||
@@ -69,0 +69,0 @@ "prettier": "^2.6.2", |
@@ -287,2 +287,26 @@ # ValidatorJs | ||
#### Example 1 - Max validation | ||
```js | ||
let rules = { | ||
phone: 'required|numeric|max:11', | ||
} | ||
let input = { | ||
phone: '01234567890', | ||
} | ||
// passes: true | ||
``` | ||
#### Example 2 - Max validation | ||
```js | ||
let rules = { | ||
phone: 'integer|max:16', | ||
} | ||
let input = { | ||
phone: '18', | ||
} | ||
// passes: false | ||
``` | ||
#### min:value | ||
@@ -294,2 +318,26 @@ | ||
#### Example 1 - Min validation | ||
```js | ||
let rules = { | ||
phone: 'required|numeric|min:11', | ||
} | ||
let input = { | ||
phone: '01234567890', | ||
} | ||
// passes: true | ||
``` | ||
#### Example 2 - Min validation | ||
```js | ||
let rules = { | ||
phone: 'integer|min:11', | ||
} | ||
let input = { | ||
phone: '18', | ||
} | ||
// passes: false | ||
``` | ||
#### not_in:foo,bar,... | ||
@@ -296,0 +344,0 @@ |
@@ -12,3 +12,3 @@ import Validator from './main'; | ||
private rule; | ||
private validator?; | ||
private validator; | ||
static rules: any; | ||
@@ -20,3 +20,3 @@ constructor(name: string, fn: VoidFunction, async: boolean); | ||
getParameters(): any[]; | ||
getSize(value?: string | number | Array<string | number>): any; | ||
getSize(value?: string | number | Array<string | number>): string | number; | ||
_getValueType(): "numeric" | "string"; | ||
@@ -23,0 +23,0 @@ response(passes: boolean | undefined, message?: string): void; |
@@ -5,1 +5,2 @@ export declare const formatter: (attribute: string) => string; | ||
export declare function onlyDigits(str: string | boolean | number): boolean; | ||
export declare function isFloat(n: string | number, shouldCoerce?: boolean): boolean; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
391877
9145
796