
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
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
The npm package tegund receives a total of 4 weekly downloads. As such, tegund popularity was classified as not popular.
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 researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.