Skip to content

Commit

Permalink
Adds metal-assertions module to packages (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
julien authored and eduardolundgren committed Mar 3, 2017
1 parent 21f5a5d commit f9c3d04
Show file tree
Hide file tree
Showing 6 changed files with 412 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/metal-assertions/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Software License Agreement (BSD License)

Copyright (c) 2017, Liferay Inc.
All rights reserved.

Redistribution and use of this software in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:

* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.

* The name of Liferay Inc. may not be used to endorse or promote products
derived from this software without specific prior
written permission of Liferay Inc.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

3 changes: 3 additions & 0 deletions packages/metal-assertions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# metal-assertions

A collection of assertion methods for metal
31 changes: 31 additions & 0 deletions packages/metal-assertions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "metal-assertions",
"version": "2.6.4",
"description": "A collection of assertion methods for metal",
"license": "BSD-3-Clause",
"repository": "https://github.com/metal/metal.js/tree/master/packages/metal-assertions",
"engines": {
"node": ">=0.10.0",
"npm": ">=3.0.0"
},
"jsnext:main": "src/assertions.js",
"main": "lib/assertions.js",
"files": [
"lib",
"src"
],
"scripts": {
"compile": "babel --presets es2015 -d lib/ src/",
"prepublish": "npm run compile"
},
"keywords": [
"metal"
],
"dependencies": {
"metal": "^2.6.4"
},
"devDependencies": {
"babel-cli": "^6.4.5",
"babel-preset-es2015": "^6.0.0"
}
}
146 changes: 146 additions & 0 deletions packages/metal-assertions/src/assertions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import {
isBoolean,
isDef,
isDefAndNotNull,
isDocument,
isDocumentFragment,
isElement,
isFunction,
isNull,
isNumber,
isObject,
isString,
isWindow,
} from 'metal';

/**
* Asserts value is a boolean.
* @param {*} value
* @param {string} errorMessage Error message
*/
export function assertBoolean(value, errorMessage) {
if (!isBoolean(value)) {
throw new Error(errorMessage);
}
}

/**
* Asserts value is defined.
* @param {Object} value
* @param {string} errorMessage Error message
*/
export function assertDef(value, errorMessage) {
if (!isDef(value)) {
throw new Error(errorMessage);
}
}

/**
* Asserts value is defined and not null.
* @param {Object} value
* @param {string} errorMessage Error message
*/
export function assertDefAndNotNull(value, errorMessage) {
if (!isDefAndNotNull(value)) {
throw new Error(errorMessage);
}
}

/**
* Asserts value is a function.
* @param {Function} value
* @param {string} errorMessage Error message
*/
export function assertFunction(value, errorMessage) {
if (!isFunction(value)) {
throw new Error(errorMessage);
}
}

/**
* Asserts value is not null.
* @param {Object} value
* @param {string} errorMessage Error message
*/
export function assertNotNull(value, errorMessage) {
if (isNull(value)) {
throw new Error(errorMessage);
}
}

/**
* Asserts value is a number.
* @param {Number} value
* @param {string} errorMessage Error message
*/
export function assertNumber(value, errorMessage) {
if (!isNumber(value)) {
throw new Error(errorMessage);
}
}

/**
* Asserts value is an object.
* @param {Object} value
* @param {string} errorMessage Error message
*/
export function assertObject(value, errorMessage) {
if (!isObject(value)) {
throw new Error(errorMessage);
}
}

/**
* Asserts value is a string.
* @param {String} value
* @param {string} errorMessage Error message
*/
export function assertString(value, errorMessage) {
if (!isString(value)) {
throw new Error(errorMessage);
}
}

/**
* Asserts value is a document.
* @param {Document} value
* @param {string} errorMessage Error message
*/
export function assertDocument(value, errorMessage) {
if (!isDocument(value)) {
throw new Error(errorMessage);
}
}

/**
* Asserts value is a document fragment.
* @param {DocumentFragment} value
* @param {string} errorMessage Error message
*/
export function assertDocumentFragment(value, errorMessage) {
if (!isDocumentFragment(value)) {
throw new Error(errorMessage);
}
}

/**
* Asserts value is an element.
* @param {Element} value
* @param {string} errorMessage Error message
*/
export function assertElement(value, errorMessage) {
if (!isElement(value)) {
throw new Error(errorMessage);
}
}

/**
* Asserts value is a window.
* @param {Window} value
* @param {string} errorMessage Error message
*/
export function assertWindow(value, errorMessage) {
if (!isWindow(value)) {
throw new Error(errorMessage);
}
}
9 changes: 9 additions & 0 deletions packages/metal-assertions/test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"env": {
"mocha": true
},
"globals": {
"assert": true,
"sinon": true
}
}
Loading

0 comments on commit f9c3d04

Please sign in to comment.