Skip to content

Commit

Permalink
Merge d83d0b2 into fdcb172
Browse files Browse the repository at this point in the history
  • Loading branch information
sttk committed Jun 30, 2019
2 parents fdcb172 + d83d0b2 commit ae40fd2
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 16 deletions.
1 change: 1 addition & 0 deletions .eslintignore
@@ -0,0 +1 @@
coverage/
5 changes: 4 additions & 1 deletion .eslintrc
@@ -1,3 +1,6 @@
{
"extends": "gulp"
"extends": "gulp",
"rules": {
"max-len": ["error", { "code": 100, "ignoreComments": true }]
}
}
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -12,6 +12,7 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
Expand Down
3 changes: 0 additions & 3 deletions .jscsrc

This file was deleted.

1 change: 1 addition & 0 deletions .npmrc
@@ -0,0 +1 @@
package-lock=false
6 changes: 5 additions & 1 deletion .travis.yml
@@ -1,10 +1,14 @@
sudo: false
language: node_js
node_js:
- '10'
- '8'
- '6'
- '5'
- '4'
- '0.12'
- '0.10'
after_script:
- npm run coveralls
os:
- linux
- osx
2 changes: 2 additions & 0 deletions appveyor.yml
Expand Up @@ -9,6 +9,8 @@ environment:
- nodejs_version: "4"
- nodejs_version: "5"
- nodejs_version: "6"
- nodejs_version: "8"
- nodejs_version: "10"

install:
- ps: Install-Product node $env:nodejs_version
Expand Down
13 changes: 13 additions & 0 deletions index.js
Expand Up @@ -17,8 +17,21 @@ function normalize(coercer, value) {
if (coercer === 'function') {
return value;
}
if (Array.isArray(coercer) && coercer.indexOf('function') >= 0) {
return value;
}
value = value.apply(this, slice(arguments, 2));
}

if (typeof value === 'object') {
if (coercer === 'object') {
return value;
}
if (Array.isArray(coercer) && coercer.indexOf('object') >= 0) {
return value;
}
}

return coerce(this, coercer, value);
}

Expand Down
18 changes: 8 additions & 10 deletions package.json
Expand Up @@ -17,22 +17,20 @@
"index.js"
],
"scripts": {
"lint": "eslint . && jscs index.js test/",
"lint": "eslint .",
"pretest": "npm run lint",
"test": "mocha --async-only",
"cover": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly",
"coveralls": "npm run cover && istanbul-coveralls"
"cover": "nyc --reporter=lcov --reporter=text-summary npm test",
"coveralls": "nyc --reporter=text-lcov npm test | coveralls"
},
"dependencies": {},
"devDependencies": {
"eslint": "^1.10.3",
"eslint-config-gulp": "^2.0.0",
"coveralls": "github:phated/node-coveralls#2.x",
"eslint": "^2.13.0",
"eslint-config-gulp": "^3.0.1",
"expect": "^1.16.0",
"istanbul": "^0.4.3",
"istanbul-coveralls": "^1.0.3",
"jscs": "^2.3.5",
"jscs-preset-gulp": "^1.0.0",
"mocha": "^2.4.5"
"mocha": "^3.5.3",
"nyc": "^10.3.2"
},
"keywords": [
"options",
Expand Down
9 changes: 9 additions & 0 deletions test/.eslintrc
@@ -0,0 +1,9 @@
{
"extends": "gulp/test",
"rules": {
"no-console": 0
},
"globals": {
"Symbol": "readonly"
}
}
75 changes: 74 additions & 1 deletion test/index.js
Expand Up @@ -30,14 +30,87 @@ describe('normalize', function() {
done();
});

it('compares each type and the type of the value', function(done) {
it('compares each type and the type of the value (string)', function(done) {
var type = ['number', 'string', 'object'];
var value = 'test string';
var result = normalize(type, value);
expect(result).toBe(value);
done();
});

it('compares each type and the type of the value (function)', function(done) {
var type = ['string', 'function'];
var value = function() {};
var result = normalize(type, value);
expect(result).toBe(value);
done();
});

it('compares each type and the type of the value (number)', function(done) {
var type = ['string', 'number'];
var value = 123;
var result = normalize(type, value);
expect(result).toBe(value);
done();
});

it('compares each type and the type of the value (boolean)', function(done) {
var type = ['string', 'boolean'];
var value = true;
var result = normalize(type, value);
expect(result).toBe(value);
done();
});

it('compares each type and the type of the value (object)', function(done) {
var type = ['string', 'object'];
var value = { a: 1 };
var result = normalize(type, value);
expect(result).toBe(value);

value = null;
result = normalize(type, value);
expect(result).toBe(value);
done();
});

it('compares each type and the type of the value (date)', function(done) {
var type = ['string', 'object'];
var value = new Date();
var result = normalize(type, value);
expect(result).toBe(value);
done();
});

it('compares each type and the type of the value (null)', function(done) {
var type = ['string', 'object'];
var value = null;
var result = normalize(type, value);
expect(result).toBe(value);
done();
});

it('compares each type and the type of the value (undefined)', function(done) {
var type = ['string', 'undefined'];
var value = undefined;
var result = normalize(type, value);
expect(result).toBe(value);
done();
});

it('compares each type and the type of the value (symbol)', function(done) {
if (!global.Symbol) {
console.log('Only available on platforms that support Symbol');
this.skip();
return;
}
var type = ['string', 'symbol'];
var value = Symbol('foo');
var result = normalize(type, value);
expect(result).toBe(value);
done();
});

it('returns undefined if value does not match any type', function(done) {
var type = ['string', 'undefined'];
var value = 1;
Expand Down

0 comments on commit ae40fd2

Please sign in to comment.