pax_global_header00006660000000000000000000000064136411131460014512gustar00rootroot0000000000000052 comment=36818ec666dca5a66befa2a287cc754d09dde1e2 ist-1.1.6/000077500000000000000000000000001364111314600123165ustar00rootroot00000000000000ist-1.1.6/.gitignore000066400000000000000000000000421364111314600143020ustar00rootroot00000000000000/node_modules /ist.cjs.js .tern-* ist-1.1.6/LICENSE000066400000000000000000000020731364111314600133250ustar00rootroot00000000000000Copyright (C) 2016 by Marijn Haverbeke Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ist-1.1.6/README.md000066400000000000000000000023601364111314600135760ustar00rootroot00000000000000# ist This is a tiny assertion library (in the same space as `require("assert")`) that is only a handful of lines, and exports a simple API. ```javascript var ist = require("ist") ist([] instanceof Array) // Assert that the argument is truthy ist(1 + 1, 2) // Assert that two values are the same ist(1 + 1, 3, "<") // Assert that 2 is less than 3 ist(a, b, myCompareFunc) // Pass an arbitrary compare function ist.throws(function() { undefined.prop }) // Ensure something throws ``` **`ist`**`(value)` Throws a exception of class `ist.Failure` when `value` is falsy. **`ist`**`(a, b, compare)` Compares `a` and `b`, and throws an `ist.Failure` if the comparison fails. `compare` defaults to `==`, but you can pass a string that corresponds to a JavaScript comparison operator, or a custom function, to compare in a different way. **`ist.throws`**`(f, matches)` Ensure that calling `f` throws an exception, and optionally test whether the exception matches your expectation. `matches` may be a regexp, which is matched against the exception's `message` property, a string, which should be the same as the `message`, or a function that takes an exception and returns a boolean. ## License This software is licensed under an MIT license. ist-1.1.6/build.js000066400000000000000000000003501364111314600137510ustar00rootroot00000000000000import * as fs from "fs" import tariff from "tariff" fs.writeFileSync("ist.cjs", "// (This file is generated from ist.js. Don't edit it directly.)\n\n" + tariff(fs.readFileSync("ist.js", "utf8"))) ist-1.1.6/ist.d.ts000066400000000000000000000004261364111314600137110ustar00rootroot00000000000000declare class Failure extends Error {} declare const ist: { (a: any, b?: any, cmp?: string | ((a: any, b: any) => boolean)): void Failure: typeof Failure throws: (f: () => void, expected?: null | RegExp | string | ((error: any) => boolean)) => void } export default ist ist-1.1.6/ist.js000066400000000000000000000041661364111314600134620ustar00rootroot00000000000000var opNames = [ "==", function(a, b) { return a == b }, "!=", function(a, b) { return a != b }, "===", function(a, b) { return a === b }, "!==", function(a, b) { return a !== b }, "<", function(a, b) { return a < b }, ">=", function(a, b) { return a >= b }, ">", function(a, b) { return a > b }, "<=", function(a, b) { return a <= b } ] var ops = {} for (var i = 0; i < opNames.length; i += 2) ops[opNames[i]] = opNames[i + 1] function message(a, b, compare) { if (!compare || typeof compare == "string") { var index = opNames.indexOf(compare || "==") return a + " " + opNames[index + (index % 4 ? -2 : 2)] + " " + b } return "!" + compare.name + "(" + a + ", " + b + ")" } function ist(a, b, compare) { if (arguments.length == 1) { if (!a) throw new ist.Failure("!" + a, "ist") } else { var cmpFn = compare if (typeof compare == "string") { if (!(cmpFn = ops[compare])) throw new RangeError("Unknow operator " + compare) } else if (!compare) { cmpFn = ops["=="] } if (!cmpFn(a, b)) { var cmpName = (typeof compare == "string" ? compare : compare && compare.name) || "==" throw new ist.Failure(message(a, b, compare), "ist") } } } ist.Failure = function(message, src) { this.message = message if (Error.captureStackTrace) Error.captureStackTrace(this) else this.stack = new Error(message).stack if (this.stack) { var lines = this.stack.split("\n"), re = new RegExp("\\b" + src + "\\b") for (var i = 0; i < lines.length - 1; i++) { if (re.test(lines[i]) && !/\bFailure\b/.test(lines[i])) { this.message += " " + lines[i + 1].trim() break } } } } ist.Failure.prototype = Object.create(Error.prototype) ist.throws = function throws(f, expected) { let threw = true try { f() threw = false } catch(e) { var matches = !expected ? true : expected.test ? expected.test(e.message) : typeof expected == "string" ? e.message == expected : expected(e) if (!matches) throw e } if (!threw) throw new ist.Failure("Did not throw", "throws") } ist.default = ist export default ist ist-1.1.6/package.json000066400000000000000000000011261364111314600146040ustar00rootroot00000000000000{ "name": "ist", "version": "1.1.6", "description": "Mini assertion library", "main": "ist.cjs", "type": "module", "exports": { "import": "./ist.js", "require": "./ist.cjs" }, "module": "ist.js", "types": "ist.d.ts", "license": "MIT", "maintainers": [ { "name": "Marijn Haverbeke", "email": "marijnh@gmail.com", "web": "http://marijnhaverbeke.nl" } ], "repository": { "type": "git", "url": "git://github.com/marijnh/ist.git" }, "dependencies": { "tariff": "^0.1.0" }, "scripts": { "prepare": "node build.js" } }