Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
English | 简体中文
tegund is a very simple and intuitive JavaScript type checking library. Features overview:
Basic use
const {object, string, number, integer, date, array} = require('tegund')
// basic type check
string().check('abc') // true
number().check(true) // false
// addtional condition
string().min(5).check('abc') // false
// object
object().check({}) // true
object().check([]) // false
// group
const group = object({
name: string(),
age:'integer' // use alias, equal to integer()
})
group.check({}) // false
group.check({ name:'leo', age: 18 }) // true
// array
array().check([1,'abc', true]) true
// typed array
array(string()).check(['abc', 1]) // false
// or use alias
array('string').check(['abc', 1]) // false
// a array containe string or number
array('string','number').check(['abc', 1]) // true
Below we use tegund to verify more complex scenarios. Suppose we want to create a user table and use tegund to verify the input:
const {object, string, integer, date, array} = require('tegund')
const interface = object({
name: string().min(2).max(10), // the user name must be a string and at 2-10
age: integer().positive(), // age must be a positive integer number
address: object({ // the address is a object
province: string(),
city:'string', // use alias, it is same at string()
county:'string',
addressDetail:'string',
}),
email: string().pattern( // you can add addtional pattern and error message
/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
'Please enter a correct email address'
),
pwd: string().pattern(
/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/,
'Please enter a password with more than 8 digits, including numbers and letters'
),
tag: array('string'), // tag must be a array<string>
remark: string().optional(), // this field is optional
createTime: date().forbid(), // can not provide a createTime prop
updateTime: date().forbid(),
})
// then validate the params
const args = {}
// test it, is pass, get a undefined, if not, will get a ValidateError
const err = interface.test(args)
// if pass, will get a true
const passed = interface.check(args)
// or you can use assert
// if not pass, will throw a error
interface.assert(args)
Error message:
>>>>> interface.assert()
<<<<< ValidateError: None is not a Object type
>>>>> interface.assert({})
<<<<< ValidateError: field name validate error, expected a String type, got a [object Undefined]
>>>>> interface.assert({name:''})
<<<<< ValidateError: field name validate error, expected a String, length gte than 2, but got a length: 0
>>>>> interface.assert({name:'leo'})
<<<<< ValidateError: field age validate error, expected a Integer type, got a [object Undefined]
// and so on...
For detailed usage, please check the Document
# Install tegund
npm i tegund
Copyright (c) 2021-present aim-leo
FAQs
Simple type judgment tool for js
We found that tegund demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.