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

@sumor/validator

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sumor/validator - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

2

package.json
{
"name": "@sumor/validator",
"description": "This is a lightweight validator for Node.JS. It can validate the input string or number based on the rules you defined.",
"version": "1.0.2",
"version": "1.0.3",
"license": "MIT",

@@ -6,0 +6,0 @@ "repository": "sumor-cloud/validator",

@@ -156,2 +156,6 @@ # validator

##### Trim Usage
will remove the useless space for prefix and suffix
```js

@@ -161,9 +165,42 @@ import { format } from '@sumor/validator'

const parameterInfo = {
type: 'string'
type: 'string',
trim: true // default is true for string type
}
const value1 = format(parameterInfo, ' demo ')
console.log(value1) // will print "demo", useless space will be removed
const value = format(parameterInfo, ' demo ')
console.log(value) // will print "demo", useless space will be removed
```
##### Lowercase Usage
will convert the string to lowercase
```js
import { format } from '@sumor/validator'
const parameterInfo = {
type: 'string',
lowercase: true
}
const value = format(parameterInfo, 'Demo')
console.log(value) // will print "demo", all characters will be converted to lowercase
```
##### Uppercase Usage
will convert the string to uppercase
```js
import { format } from '@sumor/validator'
const parameterInfo = {
type: 'string',
uppercase: true
}
const value = format(parameterInfo, 'Demo')
console.log(value) // will print "DEMO", all characters will be converted to uppercase
```
### Format Number Usage

@@ -170,0 +207,0 @@

export default (info, value) => {
if (value === undefined || value === null || value === '') {
return null
if (value === undefined || value === '') {
value = null
}
// default value
if (value === null) {
if (info.default) {
value = info.default
} else {
return null
}
}
// convert to number
if (typeof value !== 'number') {

@@ -7,0 +17,0 @@ value = parseFloat(value)

export default (info, value) => {
if (info.trim) {
value = value.trim()
if (value === undefined) {
value = null
}
// convert to string
if (value !== null && typeof value !== 'string') {
if (typeof value === 'object') {
value = JSON.stringify(value)
} else {
value = value.toString()
}
}
// default value
if (info.default !== undefined) {
if (value === null || value === '') {
value = info.default
}
}
if (value !== null) {
// trim value
if (info.trim) {
value = value.trim()
}
// lowerCase value
if (info.lowerCase) {
value = value.toLowerCase()
}
// upperCase value
if (info.upperCase) {
value = value.toUpperCase()
}
}
return value
}
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