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

the-thing-is

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

the-thing-is - npm Package Compare versions

Comparing version 0.4.4 to 0.5.0

4

package.json
{
"name": "the-thing-is",
"version": "0.4.4",
"description": "Thoroughly measure subjects against a series of standards.",
"version": "0.5.0",
"description": "Simple tool for doing complex object validation.",
"main": "the-thing-is.js",

@@ -6,0 +6,0 @@ "scripts": {

/* jshint quotmark:false */
/* global describe, it */
/* global describe, it, before */
'use strict'

@@ -20,42 +20,103 @@

describe('the(thing).is', function() {
it('is a function', function() {
assert(typeof the('thing').is === 'function')
})
})
describe('basic checks', function(){
describe('the().is()', function(){
it('returns false', function() {
assert.equal(the().is(), false)
describe('BASIC CHECKS', function(){
describe('.is', function () {
describe('the(thing).is', function() {
it('is a function', function() {
assert(typeof the('thing').is === 'function')
})
})
})
describe("the('thing').is()", function() {
it('returns true', function() {
assert.equal(the('thing').is(), true)
describe('the.last', function(){
before(function(){
var result = the('thing').is('string')
assert(result)
})
it('stores the.last.thing', function(){
assert.equal(the.last.thing, 'thing')
})
it('creates the.last.error as an empty array', function(){
assert(the.last.error)
assert(Array.isArray(the.last.error))
assert.equal(the.last.error.length, 0)
})
it('changes the next time `the` is called', function(){
the('thing2').is('string')
assert.equal(the.last.thing, 'thing2')
assert.deepEqual(the.last.error, [])
})
})
})
describe("the(0).is('integer')", function() {
it('returns true', function() {
assert.equal(the(0).is('integer'), true)
describe('the().is()', function(){
it('returns false', function() {
assert.equal(the().is(), false)
})
})
it("doesn't set an error", function() {
assert(the.last.thing === 0)
assert(!the.last.error.length)
describe("the('thing').is()", function() {
it('returns true', function() {
assert.equal(the('thing').is(), true)
})
})
describe("the(0).is('integer')", function() {
it('returns true', function() {
assert.equal(the(0).is('integer'), true)
})
it("doesn't set an error", function() {
assert(the.last.thing === 0)
assert(!the.last.error.length)
})
})
describe("the('thing').is('gonnaGetThrown')", function() {
it('throws a TypeError', function() {
assert.throws(function(){
the('thing').is('gonnaGetThrown')
}, TypeError)
})
it("doesn't set an error", function() {
assert.equal(the.last.thing, 'thing')
assert(!the.last.error.length)
})
})
})
describe("the('thing').is('gonnaGetThrown')", function() {
it('throws a TypeError', function() {
assert.throws(function(){
the('thing').is('gonnaGetThrown')
}, TypeError)
describe('.isnt', function() {
describe('the(thing).isnt', function() {
it('is a function', function() {
assert(typeof the('thing').isnt === 'function')
})
})
it("doesn't set an error", function() {
assert.equal(the.last.thing, 'thing')
assert(!the.last.error.length)
describe('the().isnt()', function() {
it('returns true', function() {
assert.equal(the().isnt(), true)
})
})
describe("the('thing').isnt()", function() {
it('returns false', function() {
assert.equal(the('thing').isnt(), false)
})
})
describe("the(0).isnt('integer')", function() {
it('returns false', function() {
assert.equal(the(0).isnt('integer'), false)
})
})
describe("the(0).isnt(['integer'])", function() {
it('returns false', function() {
assert.equal(the(0).isnt(['integer']), false)
})
})
describe("the('thing').isnt('gonnaGetThrown')", function() {
it('throws a TypeError', function() {
assert.throws(function(){
the('thing').isnt('gonnaGetThrown')
}, TypeError)
})
it("doesn't set an error", function() {
assert.equal(the.last.thing, 'thing')
assert(!the.last.error.length)
})
})
})
})
describe("expectations array", function(){
describe("EXPECTATIONS ARRAY", function(){
describe("the(0).is(['integer'])", function() {

@@ -86,117 +147,101 @@ it('returns true', function() {

describe("expectations against a standard", function(){
describe("EXPECTATIONS AGAINST A STANDARD", function(){
describe("the('thing').is([{gonnaGetThrown:true}])", function(){
it("should throw an error", function(){
var whatIExpect = [{gonnaGetThrown:true}]
assert.throws(function(){
the('thing').is(whatIExpect)
}, TypeError)
describe("the('0')", function(){
describe(".is([{gonnaGetThrown:true}])", function(){
it("throws an error", function(){
var whatIExpect = [{gonnaGetThrown:true}]
assert.throws(function(){
the('thing').is(whatIExpect)
}, TypeError)
})
})
})
describe("the('0').is([{number:'wrong'}])", function(){
it("shouldn't throw an error", function(){
var whatIExpect = [{number:'wrong'}]
assert.doesNotThrow(function(){
the('0').is(whatIExpect)
describe(".is([{number:'wrong'}])", function(){
it("doesn't throw an error", function(){
var whatIExpect = [{number:'wrong'}]
assert.doesNotThrow(function(){
the('0').is(whatIExpect)
})
})
})
})
describe("the('0')", function(){
it(".is(['string', 'integerString', {gte: 0, lte:100}])", function(){
var whatIExpect = [
'string', 'integerString', {
gte: 0,
lte: 100
}]
assert( the('0').is(whatIExpect) )
describe(".is(['string', 'integerString', {gte: 0, lte:100}])", function() {
it('returns true', function(){
var whatIExpect = [
'string', 'integerString', {
gte: 0,
lte: 100
}]
assert( the('0').is(whatIExpect) )
})
})
it(".is([{ equal:0 }])", function(){
assert( the('0').is([{ equal: 0 }]) )
describe(".is([{ equal:0 }])", function(){
it('returns trur', function(){
assert( the('0').is([{ equal: 0 }]) )
})
})
it(".is([{ exactly: '0' }])", function(){
assert( the('0').is([{ exactly: '0' }]) )
describe(".is([{ exactly: '0' }])", function(){
it("returns true", function(){
assert( the('0').is([{ exactly: '0' }]) )
})
})
it(".isnt([{ equal: 1 }])", function(){
assert( the('0').isnt([{ equal: 1 }]) )
assert.deepEqual( the.last.error, [{equal:'1'}])
describe(".isnt([{ equal: 1 }])", function(){
it("returns true", function(){
assert(the('0').isnt([{ equal:1 }]))
})
it("sets the.last.error to [{equal:1}]", function () {
assert.deepEqual(the.last.error, [{equal:1}])
})
})
it(".isnt([{ equal: '1' }])", function(){
assert( the('0').isnt([{ equal: '1' }]) )
assert.deepEqual( the.last.error, [{equal:'1'}])
describe(".isnt([{ equal: '1' }])", function(){
it("returns true", function(){
assert( the('0').isnt([{ equal: '1' }]) )
})
it("sets the.last.error to [{equal:'1'}]", function () {
assert.deepEqual( the.last.error, [{equal:'1'}])
})
})
})
describe("the('101')", function(){
it(".isnt(['string', 'integerString', {gte: 0, lte:100}])", function(){
var whatIExpect = [
'string', 'integerString', {
gte: 0,
lte: 100
}]
assert( the('101').isnt(whatIExpect), false )
describe(".isnt(['string', 'integerString', {gte: 0, lte:100}])", function(){
it('returns true', function(){
assert(the('101').isnt(['string', 'integerString', { gte: 0, lte: 100 }]))
})
it("creates a meaningful error array", function(){
assert.deepEqual( the.last.error, [{lte:100}])
})
})
it("creates a meaningful error array", function(){
assert.deepEqual( the.last.error, [{lte:100}])
})
})
})
describe('the(thing).isnt', function() {
it('is a function', function() {
assert(typeof the('thing').isnt === 'function')
})
describe('the().isnt()', function() {
it('returns true', function() {
assert.equal(the().isnt(), true)
})
})
describe("the('thing').isnt()", function() {
it('returns false', function() {
assert.equal(the('thing').isnt(), false)
})
})
describe("the(0).isnt('integer')", function() {
it('returns false', function() {
assert.equal(the(0).isnt('integer'), false)
})
})
describe("the(0).isnt(['integer'])", function() {
it('returns false', function() {
assert.equal(the(0).isnt(['integer']), false)
})
})
describe("the('thing').isnt('gonnaGetThrown')", function() {
it('throws a TypeError', function() {
assert.throws(function(){
the('thing').isnt('gonnaGetThrown')
}, TypeError)
})
it("doesn't set an error", function() {
assert.equal(the.last.thing, 'thing')
assert(!the.last.error.length)
})
})
})
describe('testing objects', function() {
describe('TESTING OBJECTS', function() {
describe('{foo:"bar"}', function() {
describe('the({foo:"bar"})', function() {
var subject = { foo: "bar" }
it('is("plainObject")', function() {
assert.equal(the(subject).is('plainObject'), true)
describe('.is("plainObject")', function() {
it('returns true', function() {
assert.equal(the(subject).is('plainObject'), true)
})
})
it('is({ foo: "string" })', function() {
assert.equal(the(subject).is({ foo: "string" }), true)
describe('.is({ foo: "string" })', function() {
it('returns true', function() {
assert.equal(the(subject).is({ foo: "string" }), true)
})
})
it('is({foo:["string"]})', function() {
assert.equal(the(subject).is({ foo: ["string"] }), true)
describe('.is({foo:["string"]})', function() {
it('returns true', function() {
assert.equal(the(subject).is({ foo: ["string"] }), true)
})
})
it('is({bar:["string"]}) == false', function() {
assert.equal(the(subject).is({ bar:["string"] }), false)
describe('.is({bar:["string"]})', function() {
it('returns false', function() {
assert.equal(the(subject).is({ bar:["string"] }), false)
})
})
it('isnt({bar:["string"]})', function() {
assert.equal(the(subject).isnt({ bar:["string"] }), true)
describe('.isnt({bar:["string"]})', function() {
it('returns true', function() {
assert.equal(the(subject).isnt({ bar:["string"] }), true)
})
})

@@ -206,31 +251,62 @@ })

describe('{ foo:"bar", bar:"fizz", baz:666 }', function() {
describe('the({ foo:"bar", fizz:"buzz", baz:666 })', function() {
var subject = {
foo: 'bar',
bar: 'fizz',
baz: 666
fizz: 'buzz',
diablo: 666
}
it('is("plainObject")', function() {
assert.equal(the(subject).is('plainObject'), true)
describe('.is("plainObject")', function() {
it('returns true', function() {
assert.equal(the(subject).is('plainObject'), true)
})
})
it('is({ foo:"string", bar:"string", baz:["number", {greaterThan:0}, {lessThan:777}] })', function() {
assert.equal(the(subject).is({
foo: 'string',
bar: 'string',
baz: ['number', {greaterThan:0}, {lessThan:777}]
}), true)
describe('.is({ foo:"string", fizz:"string", diablo:["number", {greaterThan:0}, {lessThan:777}] })', function() {
it('returns true', function() {
assert.equal(the(subject).is({
foo: 'string',
fizz: 'string',
diablo: ['number', {greaterThan:0}, {lessThan:777}]
}), true)
})
})
it('isnt({ flop:"string", bar:"string", baz:["number", {greaterThan:0}, {lessThan:777}] })', function() {
assert.equal(the(subject).isnt({
flop: 'string',
bar: 'string',
baz: ['number', {greaterThan:0}, {lessThan:777}]
}), true)
describe('.isnt({ flop:"string", bar:"string", diablo:["number", {greaterThan:0}, {lessThan:777}] })', function() {
var result
before(function(){
result = the(subject).isnt({
flop: 'string',
bar: 'string',
diablo: ['number', {greaterThan:0}, {lessThan:777}]
})
})
it('returns true', function() {
assert(result, 'the thing returned the wrong result')
})
it('sets a useful error', function() {
assert.deepEqual(the.last.error, [
{ flop: [ 'present' ] },
{ bar: [ 'present' ] }
])
})
})
it('isnt({ foo:"string", bar:"string", baz:["number", {greaterThan:666}] })', function() {
assert.equal(the(subject).isnt({
foo: 'string',
bar: 'string',
baz: ['number', {greaterThan:666}]
}), true)
describe('.isnt({ foo:"string", bar:"string", diablo:["number", {greaterThan:666}] })', function() {
var result
before(function(){
result = the(subject).isnt({
flop: 'string',
bar: 'string',
diablo: ['number', {greaterThan:0}, {lessThan:777}]
})
})
it('returns true', function() {
assert(result, 'the thing returned the wrong result')
})
it('sets a useful error', function() {
assert.deepEqual(the.last.error, [
{ flop: [ 'present' ] },
{ bar: [ 'present' ] }
])
})
})

@@ -240,3 +316,3 @@ })

describe('{foo: {bar: {baz: {buz: "fiz"}}}}', function() {
describe('the({foo: {bar: {baz: {buz: "fiz"}}}})', function() {
var subject = {

@@ -251,19 +327,27 @@ foo: {

}
it('is("plainObject")', function() {
assert.equal(the(subject).is('plainObject'), true)
describe('.is("plainObject")', function() {
it('returns true', function() {
assert.equal(the(subject).is('plainObject'), true)
})
})
it('is({foo: {bar: {baz: {buz: ["string"]}}}})', function() {
assert.equal(the(subject).is({foo: {bar: {baz: {buz: ['string']}}}}), true)
describe('.is({foo: {bar: {baz: {buz: ["string"]}}}})', function() {
it('returns true', function() {
assert.equal(the(subject).is({foo: {bar: {baz: {buz: ['string']}}}}), true)
})
})
it('isnt({foo: {bar: {baz: {buz: ["number"]}}}}) - wrong type', function() {
assert.equal(the(subject).isnt({foo: {bar: {baz: {buz: ['number']}}}}), true)
describe('.isnt({foo: {bar: {baz: {buz: ["number"]}}}}) - wrong type', function() {
it('returns true', function() {
assert.equal(the(subject).isnt({foo: {bar: {baz: {buz: ['number']}}}}), true)
})
})
it('isnt({foo: {bar: {baz: {buz: {fiz: ["string"]}}}}}) - nested too deep', function() {
assert.throws(function(){
the(subject).isnt({foo: {bar: {baz: {buz: {fiz: ['string']}}}}})
}, TypeError)
describe('.isnt({foo: {bar: {baz: {buz: {fiz: ["string"]}}}}})', function() {
it("throws a type error because fiz doesn't exist", function() {
assert.throws(function(){
the(subject).isnt({foo: {bar: {baz: {buz: {fiz: ['string']}}}}})
}, TypeError)
})
})
})
describe('{foo: {bar: {baz: {buz: "fiz"}}}}', function() {
describe('the({foo: {bar: {baz: {buz: "fiz"}}}})', function() {
var subject = {

@@ -289,55 +373,147 @@ fo: {

it('is("plainObject")', function() {
assert.equal(the(subject).is('plainObject'), true)
describe('is("plainObject")', function() {
it('returns true', function() {
assert.equal(the(subject).is('plainObject'), true)
})
})
it('is({foo: {bar: {baz: {buz: ["string"]}}}})', function() {
var whatIExpect = {
fo: {
foo: {
fooo: 'string'
describe('is({foo: {bar: {baz: {buz: ["string"]}}}})', function() {
it('returns true', function() {
var whatIExpect = {
fo: {
foo: {
fooo: 'string'
},
oof: {
ooof: 'string'
}
},
oof: {
ooof: 'string'
bar: {
baz: {
buz: 'string'
}
}
},
bar: {
baz: {
buz: 'string'
}
}
}
assert.equal(the(subject).is(whatIExpect), true)
assert.equal(the(subject).is(whatIExpect), true)
})
})
it('isnt({foo: {bar: {baz: {buz: ["number"]}}}}) - foo not at top level', function() {
assert.equal(the(subject).isnt({foo: {bar: {baz: {buz: ['number']}}}}), true)
assert.deepEqual(the.last.error, [{'foo':['present']}])
describe('.isnt({foo: {bar: {baz: {buz: ["number"]}}}}) - foo not at top level', function() {
it('returns true', function() {
assert.equal(the(subject).isnt({foo: {bar: {baz: {buz: ['number']}}}}), true)
assert.deepEqual(the.last.error, [{'foo':['present']}])
})
})
})
})
describe('things with multiple errors', function() {
it('report multiple errors', function(){
the('thing').is(['number', {greaterThan:0}, {lessThan:1000}])
assert.deepEqual( the.last.error, ['number', {greaterThan:0}, {lessThan:1000}])
describe('THINGS WITH MULTIPLE ERRORS', function() {
describe("the('thing')", function() {
describe(".is(['number', {greaterThan:0}, {lessThan:1000}])", function() {
before(function(){
the('thing').is(['number', {greaterThan:0}, {lessThan:1000}])
})
it("reports thing isn't a number", function(){
assert.equal( the.last.error[0], 'number')
})
it("reports thing isn't greaterThan:0", function(){
assert.deepEqual( the.last.error[1], {greaterThan:0})
})
it("reports thing isn't lessThan:1000", function(){
assert.deepEqual( the.last.error[2], {lessThan:1000})
})
})
it('objects report multiple errors too', function(){
the({
foo: 1,
bar: 2,
fizz: {
buzz: 'fizzbuzz'
}
}).is({
foo: ['number'],
bar: ['string'],
fizz: {
buzz: ['number', {greaterThan:0}]
}
})
describe("the({ foo: 1, bar: 2, fizz: { buzz: 'fizzbuzz' }})", function(){
describe(".is({ foo: ['number'], bar: ['string'], fizz: { buzz: ['number', {greaterThan:0}] } })", function() {
before(function(){
the({
foo: 1,
bar: 2,
fizz: {
buzz: 'fizzbuzz'
}
}).is({
foo: ['number'],
bar: ['string'],
fizz: {
buzz: ['number', {greaterThan:0}]
}
})
})
assert.deepEqual( the.last.error, [{bar:['string']}, {'fizz.buzz': ['number', {greaterThan:0}]}] )
it("reports `bar` isn't a string", function(){
assert.deepEqual( the.last.error[0], {bar:['string']})
})
it("reports `fizz.buzz` has errors", function(){
assert.deepEqual(the.last.error[1], {
'fizz.buzz': [
'number',
{ greaterThan:0 }
]
})
})
it("reports `fizz.buzz` has isn't a number", function(){
assert.deepEqual(the.last.error[1]['fizz.buzz'][0], 'number')
})
it("reports `fizz.buzz` has isn't greaterThan:0", function(){
assert.deepEqual(the.last.error[1]['fizz.buzz'][1], {greaterThan:0})
})
})
})
})
describe('FALSY VALUES', function () {
describe("the()", function () {
describe(".is('undef')", function () {
it('returns true', function () {
assert(the().is('undef'))
})
})
describe(".is('present')", function () {
it('returns false', function () {
assert.equal(the().is('present'), false)
})
it('sets the correct error', function () {
assert(the.last.error.length)
assert.deepEqual(the.last.error, ['present'])
})
})
})
describe("the(false)", function () {
describe(".is('false')", function () {
it('returns true', function () {
assert(the(false).is('false'))
})
})
describe(".is('present')", function () {
it('returns false', function () {
assert.equal(the().is('present'), false)
})
it('sets the correct error', function () {
assert(the.last.error.length)
assert.deepEqual(the.last.error, ['present'])
})
})
})
describe('the({ foo:undefined })', function() {
describe(".is({ foo:'undef' }", function () {
it('returns true', function () {
assert(the({ foo: undefined }).is({ foo: 'undef' }))
})
})
describe(".is({ foo:'number' }", function () {
var result
before(function () {
result = the({ foo: undefined }).is({ foo: 'number' })
})
it('returns false', function () {
assert.equal(result, false)
})
it('sets the correct error', function () {
assert(the.last.error.length)
assert.deepEqual(the.last.error, [{foo:['number']}])
})
})
})
})

@@ -85,6 +85,6 @@ // The Thing Is

Object.keys(expected).forEach(function(key, i){
var nexThing = thing[key],
nexPectation = expected[key]
Object.keys(expected).forEach(function expectedKeys(key, i) {
var nexPectation, nexThing
if (i > 0)

@@ -95,10 +95,15 @@ the.path.pop()

if (!thing.hasOwnProperty(key))
return see('present', thing[key]);
nexPectation = expected[key]
nexThing = thing[key]
if ( is.present(nexPectation) && is.present(nexThing) )
return what(nexPectation, nexThing)
else
return see('present', nexThing)
return see(nexPectation, nexThing)
})
the.path = pathStash.slice();
}

@@ -116,2 +121,3 @@ else

// see if the expected thing meets the standard
function see (expected, thing, standard) {

@@ -118,0 +124,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