New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ynn-http-assert

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ynn-http-assert - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

10

package.json
{
"name": "ynn-http-assert",
"version": "0.0.3",
"version": "0.0.4",
"description": "A more powerful http assertion library.",

@@ -48,11 +48,11 @@ "main": "src/index.js",

"devDependencies": {
"eslint": "^5.12.0",
"jest": "^23.6.0",
"eslint": "^5.16.0",
"jest": "^24.7.1",
"pre-commit": "^1.2.2"
},
"dependencies": {
"@lvchengbin/is": "0.0.25",
"@lvchengbin/is": "0.0.27",
"deep-equal": "^1.0.1",
"http-errors": "^1.7.1"
"http-errors": "^1.7.2"
}
}

@@ -46,2 +46,11 @@ const deepEqual = require( 'deep-equal' );

undefined() {
this.acceptUndefined = true;
return this;
}
required( name, code = 400, message ) {
return this.assert( this.value(), code, message || `${name} is required` );
}
value( v ) {

@@ -72,2 +81,7 @@ /**

* - url
* - @todo date
* - @todo time
* - @todo dateTime
* - @todo timestamp
* - @todo mixedTime
*/

@@ -149,3 +163,3 @@ is( type, ...args ) {

json( ...args ) {
jsonstr( ...args ) {
let res = false;

@@ -166,2 +180,29 @@ let fn;

json( ...args ) {
const value = this.value();
let res = is.plainObject( value ) || is.array( value );
if( !res ) {
try {
JSON.parse( value );
res = true;
} catch( e ) {
res = false;
}
}
return this.assert( res, ...args );
}
object( ...args ) {
const type = [ '*', '{}', '[]' ].indexOf( args[ 0 ] ) > -1 ? args[ 0 ] : '*';
const value = this.value();
if( type === '[]' ) {
return this.assert( is.array( value ), ...args );
}
if( type === '{}' ) {
return this.assert( value && is.object( value ) && !is.array( value ), ...args );
}
return this.assert( value && ( is.object( value ) || is.array( value ) ), ...args );
}
custom( fn, ...args ) {

@@ -183,2 +224,11 @@ const res = fn.call( this, this.value(), this );

mutate( value ) {
if( is.function( value ) ) {
this.value( value.call( this, this.value() ) );
return this;
}
this.value( value );
return this;
}
assert( value, ...args ) {

@@ -190,5 +240,5 @@ if( this.skip || value ) return this;

return this;
} else {
this.throw( ...args );
}
if( this.acceptUndefined && is.undefined( this.value() ) ) return this;
this.throw( ...args );
}

@@ -195,0 +245,0 @@

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