Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
argsy
Advanced tools
Readme
awesome argument assertion
Made with ❤ at @outlandish
Argument-oriented assertions...
function hello (name, message) {
if (typeof name !== 'string' || !name.length) {
throw new Error('expecting name to be non-empty string')
} else if (message && typeof message !== 'string') {
throw new Error('expecting message to be string')
}
console.log('hello', name, message)
}
hello() //=> Error: expecting name to be non-empty string
function hello (name, message) {
assert('hello')
.nonEmptyStr(name)
.optional.str(message)
console.log('hello', name, message)
}
hello()
//=> Error: Failed argument assertions in call to "hello" at C:/hello.js:1:
// - expecting name to be non-empty string
npm install --save argsy
yarn add argsy
// ES2015
import assert from 'argsy'
// CommonJS
var assert = require('argsy')
assert.{method}(val[, subject][, name[, name2]])
Assert val
is of type indicated by method
(see below).
No return value.
AssertionInstance
assert([name]) : AssertionInstance
Create a new assertion instance.
Returns an AssertionInstance
.
AssertionInstance.{method}(val[, subject][, name[, name2]])
Assert val
is of type indicated by method
(see below).
Returns the AssertionInstance
.
ok
notOk
str
obj
nonEmptyStr
num
sym
int
bool
undef
null
nan
elem (use subject arg)
key (use subject arg)
AssertionInstance.optional.{method}()
Assert an optional value.
Shares the same API as AssertionInstance.method
(see above).
Returns the AssertionInstance
.
AssertionInstance.$eval()
Assert the arguments.
This should be called last in the chain of assertion declarations.
examples/report.js
Evaluates all assertions, groups them, and reports all failures.
Note call to $eval
at the end.
function add (a, b) {
assert('add')
.num(a, 'a')
.num(b, 'b')
.$eval()
return a + b
}
const a = Number(process.argv[1])
const b = Number(process.argv[2])
const result = add(a, b)
console.log(a, '+', b, '=', result)
$ node examples/add.js 1 2
1+2=3
$ node add.js
Error: Failed argument assertions in call to "add" at C:/argsy/examples/report.js:10:
- expecting a to be number
- expecting b to be number
at Function.evaluate (C:/argsy/src/index.js:63:13)
at add (C:/argsy/examples/report.js:10:6)
at Object.<anonymous> (C:/argsy/examples/report.js:18:16)
examples/spongebob.js
Stops and throws at first failed assertion.
import assert from 'argsy'
function person (name, occupation) {
assert
.nonEmptyStr(name, 'name')
.optional.nonEmptyStr(occupation, 'occupation')
console.log(name + ' is a ' + (occupation || 'sponge'))
}
person('Spongebob')
//=> Spongebob is a sponge
person(['Spongebob'], 'crabby patty flipper')
//=> Error: Expecting name to be a non-empty string
person('Spongebob', 'crabby patty flipper')
//=> Spongebob is a crabby patty flipper
All pull requests and issues welcome!
If you're not sure how, check out the great video tutorials on egghead.io!
MIT © Sam Gluck
FAQs
awesome argument assertion
The npm package argsy receives a total of 8 weekly downloads. As such, argsy popularity was classified as not popular.
We found that argsy 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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.