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
1
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.1.0 to 0.2.0

test/mocha.opts

4

package.json
{
"name": "the-thing-is",
"version": "0.1.0",
"version": "0.2.0",
"description": "Configuration drivin validation",

@@ -22,4 +22,4 @@ "main": "the-thing-is.js",

"dependencies": {
"is-it": "~1.0.3"
"is-it": "~1.1.0"
}
}

@@ -20,3 +20,6 @@ var assert = require('assert')

})
describe('the().is()', function() {
})
describe('basic checks', function(){
describe('the().is()', function(){
it('returns false', function() {

@@ -26,3 +29,3 @@ assert.equal(the().is(), false)

})
describe('the(thing).is()', function() {
describe("the('thing').is()", function() {
it('returns true', function() {

@@ -52,2 +55,5 @@ assert.equal(the('thing').is(), true)

})
})
describe("expectations array", function(){
describe("the(0).is(['integer'])", function() {

@@ -78,2 +84,50 @@ it('returns true', function() {

describe("expectations against a standard", function(){
describe("a test of a standard that doesn't exist", function(){
it("should throw an error", function(){
var whatIExpect = [{gonnaGetThrown:true}]
assert.throws(function(){
the(0).is(whatIExpect)
}, TypeError)
})
})
describe("an incorrect test of a standard", function(){
it("shouldn't throw an error", function(){
var whatIExpect = [{number:'wrong'}]
assert.doesNotThrow(function(){
the('0').is(whatIExpect)
})
})
})
describe("a complex expectation that passes", function(){
it('passes all the conditions', function(){
var whatIExpect = [
'string', 'aInteger',
{
// this is a trick - `number:false` is true
// because `number` isn't a check against a standard
number: false,
aInteger: true,
gte: 0,
lte: 100
}
]
assert( the('0').is(whatIExpect) )
assert( the.last.error.length )
})
})
describe("a complex expectation that's not met", function(){
it("doesn't meet the expectations", function(){
the('0').is(['string', 'aInteger', {gte:0, lte:100}])
assert( the.last.error.length )
})
it("sets a meaningful (enough) error message", function(){
assert.equal( the.last.error[0], "See, the thing is, 0 (string) isn't gte 0.")
})
})
})
describe('the(thing).isnt', function() {

@@ -103,3 +157,13 @@ it('is a function', function() {

})
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)
})
})
})
// The Thing Is
// Configuration driven validation
// with the goal of a near-english syntax
// with the goal of a near-english syntax (for consumers)

@@ -27,3 +27,6 @@ // Usage:

function the(thing) {
the.past.push({ thing:thing })
the.past.push({
thing: thing,
errors: []
})
the.last = the.past[the.past.length-1 || 0]

@@ -41,8 +44,8 @@ return comparisons

var its = true
var expectation = null
// the(thing).is()
// whatYouExpect is undefined or null -- so check mere presence of a thing
if ( is.not.present(whatYouExpect) ) {
if ( is.not.present(whatYouExpect) )
its = is.present(the.last.thing)
}

@@ -52,4 +55,5 @@ // 'present' -- single boolean check

// the(thing).is('borkborkbork') // throw
if ( is.string(whatYouExpect) )
its = booleanCheck(whatYouExpect)
else
if ( is.string(whatYouExpect) )
its = booleanCheck(whatYouExpect)

@@ -59,10 +63,15 @@

// the(thing).is(['present', 'integer'])
if ( is.array(whatYouExpect) ) {
for (var i = 0; i < whatYouExpect.length && its == true; i++) {
if (is.string(whatYouExpect[i]))
its = booleanCheck(whatYouExpect[i])
if (!its)
the.last.error = '' + the.last.thing + ' is not ' + whatYouExpect[i];
}
}
else
if ( is.array(whatYouExpect) )
for (var i = 0; i < whatYouExpect.length && its == true; i++) {
expectation = whatYouExpect[i]
if (is.string(expectation))
its = booleanCheck(expectation)
else
its = subjectCheck(expectation)
if (!its)
the.last.error = '' + the.last.thing + ' is not ' + whatYouExpect[i];
}
// {greaterThan:0} -- configuration object with single condition

@@ -88,5 +97,19 @@ // {present:true, integer:true, greaterThan:0} -- unreliable due to unreliable hash key order

// TODO: compare the thing against a standard
// function
function subjectCheck(expectation) {
the.last.error = []
// loop through the keys in the object to
Object.keys(expectation).forEach(function(key, value){
if ( !is[key] )
throw new TypeError("`"+key+"` isn't a valid comparison method.")
if ( is[key](the.last.thing, expectation[key]) ) {
the.last.error.push(['See, the thing is, ', the.last.thing, ' (', typeof the.last.thing, ') isn\'t ', key, ' ', value, '.'].join(''));
}
})
return !!the.last.error.length
}
module.exports = the
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