Skip to content

Commit

Permalink
chore: use babel-register and more ES2015 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
JaKXz committed Feb 18, 2017
1 parent dbd2510 commit 6291f7c
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 65 deletions.
7 changes: 6 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
"targets": {
"node": 4
}
}]]
}]],
"env": {
"test": {
"plugins": ["istanbul"]
}
}
}
21 changes: 17 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,37 @@
],
"license": "MIT",
"devDependencies": {
"ava": "^0.18.1",
"babel-cli": "^6.22.2",
"ava": "^0.18.2",
"babel-cli": "^6.23.0",
"babel-plugin-istanbul": "^4.0.0",
"babel-preset-env": "^1.1.8",
"babel-register": "^6.23.0",
"coveralls": "^2.11.16",
"cross-env": "^3.1.4",
"nyc": "^10.1.2",
"semistandard": "^9.2.1"
},
"scripts": {
"build": "babel src --out-dir lib",
"prepublish": "npm test",
"pretest": "semistandard && npm run build",
"test": "nyc ava"
"test": "cross-env NODE_ENV=test nyc ava"
},
"ava": {
"require": [
"babel-register"
]
},
"nyc": {
"require": [
"babel-register"
],
"reporter": [
"text",
"lcov"
],
"check-coverage": true
"check-coverage": true,
"sourceMap": false,
"instrument": false
}
}
6 changes: 2 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function argsert (typeConfig, ...args) {
export default function argsert (typeConfig, ...args) {
if (typeof typeConfig !== 'string' || (!isRequired(typeConfig) && !isOptional(typeConfig))) {
args = [typeConfig];
typeConfig = '';
Expand Down Expand Up @@ -41,7 +39,7 @@ module.exports = function argsert (typeConfig, ...args) {
});

return true;
};
}

function getTypes (typeConfig) {
return typeConfig.split(' ').reduce((result, str, index) => {
Expand Down
8 changes: 3 additions & 5 deletions src/promise.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use strict';
import argsert from './';

const argsert = require('./');

module.exports = function argsertPromise (...args) {
export default function argsertPromise (...args) {
return new Promise((resolve, reject) => {
try {
return resolve(argsert(...args));
} catch (err) {
return reject(err);
}
});
};
}
11 changes: 3 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import test from 'ava';
import argsert from './lib/';
import argsertPromise from './lib/promise';
import argsert from './src/';
import argsertPromise from './src/promise';

test('does not throw exception if optional argument is not provided', async t => {
test('does not throw exception if optional argument is not provided', t => {
t.true(argsert('[object]'));
t.true(await argsertPromise('[object]'));
});

test('throws exception if wrong type is provided for optional argument', t => {
t.throws(
() => argsert('[object|number]', 'hello'),
/Invalid first argument. Expected object or number or undefined but received string./
);
t.throws(
argsertPromise('[object|number]', 'hello'),
/Invalid first argument. Expected object or number or undefined but received string./
Expand Down
Loading

0 comments on commit 6291f7c

Please sign in to comment.