From fc1ad88b4ee395d3cc9ccb41ee1c41a4ba4af7b8 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 30 Jun 2019 16:14:11 +0900 Subject: [PATCH 1/6] Bugfix: Return incorrect result when type array contains "function" or "object". --- index.js | 13 +++++++++ test/index.js | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 1be06dc..c5a302d 100644 --- a/index.js +++ b/index.js @@ -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); } diff --git a/test/index.js b/test/index.js index 6ff9923..44cab0e 100644 --- a/test/index.js +++ b/test/index.js @@ -30,7 +30,7 @@ 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); @@ -38,6 +38,79 @@ describe('normalize', function() { 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; From d90f2a2cd25189ab8e93d4c7e2c10a98643c2f72 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 30 Jun 2019 16:51:43 +0900 Subject: [PATCH 2/6] Update: Upgrade eslint and drop jscs in devDependencies --- .eslintrc | 5 ++++- .jscsrc | 3 --- package.json | 8 +++----- test/.eslintrc | 9 +++++++++ 4 files changed, 16 insertions(+), 9 deletions(-) delete mode 100644 .jscsrc create mode 100644 test/.eslintrc diff --git a/.eslintrc b/.eslintrc index a5a4a17..39a588a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,3 +1,6 @@ { - "extends": "gulp" + "extends": "gulp", + "rules": { + "max-len": ["error", { "code": 100, "ignoreComments": true }] + } } diff --git a/.jscsrc b/.jscsrc deleted file mode 100644 index 703b33f..0000000 --- a/.jscsrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "preset": "gulp" -} diff --git a/package.json b/package.json index adbcf83..5c5cd5d 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "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", @@ -25,13 +25,11 @@ }, "dependencies": {}, "devDependencies": { - "eslint": "^1.10.3", - "eslint-config-gulp": "^2.0.0", + "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" }, "keywords": [ diff --git a/test/.eslintrc b/test/.eslintrc new file mode 100644 index 0000000..b989220 --- /dev/null +++ b/test/.eslintrc @@ -0,0 +1,9 @@ +{ + "extends": "gulp/test", + "rules": { + "no-console": 0 + }, + "globals": { + "Symbol": "readonly" + } +} From 8f5af8f206eb7d2a6cfa62ad473aea854f3f9985 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 30 Jun 2019 16:53:44 +0900 Subject: [PATCH 3/6] Update: Upgrade mocha in devDependencies --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5c5cd5d..3159e02 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "expect": "^1.16.0", "istanbul": "^0.4.3", "istanbul-coveralls": "^1.0.3", - "mocha": "^2.4.5" + "mocha": "^3.5.3" }, "keywords": [ "options", From fa54a0e950f2b3455ad5e748545081ac8be377fb Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 30 Jun 2019 17:00:54 +0900 Subject: [PATCH 4/6] Update: Switch coverage tool to nyc and coveralls --- .eslintignore | 1 + .gitignore | 1 + package.json | 10 +++++----- 3 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..404abb2 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +coverage/ diff --git a/.gitignore b/.gitignore index 123ae94..eebf6ac 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/package.json b/package.json index 3159e02..dc6969c 100644 --- a/package.json +++ b/package.json @@ -20,17 +20,17 @@ "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": { + "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", - "mocha": "^3.5.3" + "mocha": "^3.5.3", + "nyc": "^10.3.2" }, "keywords": [ "options", From e88d0582b48384d25cfafec9226aea4bf86cac7b Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 30 Jun 2019 17:03:48 +0900 Subject: [PATCH 5/6] Scaffold: Disable npm package-lock.json with .npmrc --- .npmrc | 1 + 1 file changed, 1 insertion(+) create mode 100644 .npmrc diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false From d83d0b2b87e29fb646c8e7d9e22908d6d0f797f4 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 30 Jun 2019 17:24:11 +0900 Subject: [PATCH 6/6] Build: Improve AppVeyor & Travis config --- .travis.yml | 6 +++++- appveyor.yml | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0d50ecf..62e8f9d 100644 --- a/.travis.yml +++ b/.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 diff --git a/appveyor.yml b/appveyor.yml index 625fc10..e416994 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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