You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

valyd

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

valyd - npm Package Compare versions

Comparing version
0.1.0
to
0.1.1
+1
-0
dist/index.js

@@ -30,1 +30,2 @@ "use strict";

exports.valyd = { email: exports.email, url: exports.url, json: exports.json };
exports["default"] = exports.valyd;
+3
-1

@@ -7,2 +7,4 @@ export type StringValidator = (str:string) => boolean

json: StringValidator
}
}
export default valyd;
const isEmail = require('isemail');
const isString = (val:any) => {
return typeof val === 'string';
}
export const email = (str:string) => {
return isEmail.validate(str, {errorLevel:false}) as boolean;
return isString(str) && isEmail.validate(str, {errorLevel:false}) as boolean;
}

@@ -19,3 +23,3 @@

'(\\#[-a-z\\d_]*)?$','i'); // fragment locator
return !!pattern.test(str);
return isString(str) && !!pattern.test(str);
}

@@ -25,4 +29,8 @@

try {
JSON.parse(str);
return true;
if (isString(str)){
JSON.parse(str);
return true;
} else {
return false;
}
} catch (e) {

@@ -33,2 +41,4 @@ return false;

export const valyd = { email, url, json };
export const valyd = { email, url, json };
export default valyd;
{
"name": "valyd",
"version": "0.1.0",
"version": "0.1.1",
"description": "A dead simple package for validating various types of strings.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

# valyd
A dead simple library for validating various types of strings. Ships with Typescript bindings.
## Usage
```javascript
import valyd from 'valyd';
valyd.email('example@gmail.com') // Returns true
valyd.json('"{"testObj":{"a":1,"b":2}}"') // Returns true
valyd.url('https://google.com') // Returns true
```
## API
All methods are synchronous.
- `valyd.json(str:string) => boolean`: Returns true if the provided string can be successfully JSON parsed.
- `valyd.email(str:string) => boolean`: Returns true if the provided string is a valid email, as determined by `isEmail` in its simplest configuration.
- `valyd.url(str:string) => boolean`: Returns true if the provided string is a valid URL, as determined by [the Regex from the top-rated Stack Overflow post](https://stackoverflow.com/a/5717133/2128308).