Skip to content

Commit

Permalink
Merge pull request #240 from shimataro/develop
Browse files Browse the repository at this point in the history
version 1.0.0-rc.4
  • Loading branch information
shimataro authored Aug 30, 2018
2 parents e845aa3 + 7a01941 commit f70ffa3
Show file tree
Hide file tree
Showing 7 changed files with 463 additions and 594 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [1.0.0-rc.4] - 2018-08-30
### Changed
* `adjuster.number().adjust([])` causes `adjuster.CAUSE.TYPE`

## [1.0.0-rc.3] - 2018-08-28
### Others
* documents proofreading
Expand Down Expand Up @@ -201,7 +205,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [0.1.0] - 2018-04-18
* First release.

[Unreleased]: https://github.com/shimataro/node-adjuster/compare/v1.0.0-rc.3...HEAD
[Unreleased]: https://github.com/shimataro/node-adjuster/compare/v1.0.0-rc.4...HEAD
[1.0.0-rc.4]: https://github.com/shimataro/node-adjuster/compare/v1.0.0-rc.3...v1.0.0-rc.4
[1.0.0-rc.3]: https://github.com/shimataro/node-adjuster/compare/v1.0.0-rc.2...v1.0.0-rc.3
[1.0.0-rc.2]: https://github.com/shimataro/node-adjuster/compare/v1.0.0-rc.1...v1.0.0-rc.2
[1.0.0-rc.1]: https://github.com/shimataro/node-adjuster/compare/v0.16.0...v1.0.0-rc.1
Expand Down
989 changes: 415 additions & 574 deletions npm-shrinkwrap.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "adjuster",
"description": "validate and adjust input values",
"version": "1.0.0-rc.3",
"version": "1.0.0-rc.4",
"author": "shimataro",
"license": "MIT",
"repository": {
Expand Down Expand Up @@ -47,19 +47,19 @@
"devDependencies": {
"@types/core-js": "2.5.0",
"@types/jest": "23.3.1",
"@types/node": "10.9.2",
"babel-eslint": "8.2.6",
"@types/node": "10.9.3",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "9.0.0",
"eslint": "5.4.0",
"eslint-plugin-import": "2.14.0",
"jest": "23.5.0",
"npm-check-updates": "2.14.2"
},
"dependencies": {
"@babel/cli": "7.0.0-rc.4",
"@babel/core": "7.0.0-rc.4",
"@babel/plugin-proposal-decorators": "7.0.0-rc.4",
"@babel/preset-env": "7.0.0-rc.4",
"babel-core": "7.0.0-bridge.0",
"@babel/cli": "7.0.0",
"@babel/core": "7.0.0",
"@babel/plugin-proposal-decorators": "7.0.0",
"@babel/preset-env": "7.0.0",
"babel-plugin-add-module-exports": "0.3.3",
"cross-env": "5.2.0",
"npm-run-all": "4.1.3"
Expand Down
8 changes: 7 additions & 1 deletion src/decorators/number/type.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {CAUSE} from "../../libs/constants";
import {isNumber, isInteger, isString} from "../../libs/types";
import {isScalar, isNumber, isInteger, isString} from "../../libs/types";
import AdjusterBase from "../../libs/AdjusterBase";
import AdjusterError from "../../libs/AdjusterError";

Expand Down Expand Up @@ -148,6 +148,12 @@ function _toNumber(params, value)
return false;
}

if(!isScalar(value))
{
// not a scalar value
return false;
}

const adjustedValue = Number(value);
if(isNaN(adjustedValue))
{
Expand Down
6 changes: 3 additions & 3 deletions src/decorators/string/type.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {CAUSE} from "../../libs/constants";
import {isString, isArray, isObject} from "../../libs/types";
import {isScalar, isString} from "../../libs/types";
import AdjusterBase from "../../libs/AdjusterBase";
import AdjusterError from "../../libs/AdjusterError";

Expand Down Expand Up @@ -57,8 +57,8 @@ function _adjust(params, values, keyStack)
AdjusterError.raise(CAUSE.TYPE, values, keyStack);
}

// array or object cannot be convert to string
if(isArray(values.adjusted) || isObject(values.adjusted))
// non-scalar value cannot be convert to string
if(!isScalar(values.adjusted))
{
AdjusterError.raise(CAUSE.TYPE, values, keyStack);
}
Expand Down
19 changes: 12 additions & 7 deletions src/libs/types.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
export {isBoolean, isNumber, isInteger, isString, isArray, isObject};
export {isScalar, isBoolean, isNumber, isInteger, isString, isArray, isObject};

/**
* check whether given value is a scalar or not
* @param {*} value value to check
* @returns {boolean} Yes/No
*/
function isScalar(value)
{
return value === null || typeof value !== "object";
}

/**
* check whether given value is a boolean or not
Expand Down Expand Up @@ -67,10 +77,6 @@ function isArray(value)
*/
function isObject(value)
{
if(typeof value !== "object")
{
return false;
}
if(value === null)
{
return false;
Expand All @@ -80,6 +86,5 @@ function isObject(value)
return false;
}

// true otherwise
return true;
return typeof value === "object";
}
12 changes: 12 additions & 0 deletions test/adjusters/number.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ function testType()
.adjust("false");
}).toThrow(adjuster.CAUSE.TYPE);

expect(() =>
{
adjuster.number().acceptSpecialFormats()
.adjust("true");
}).toThrow(adjuster.CAUSE.TYPE);

expect(() =>
{
adjuster.number().integer()
Expand Down Expand Up @@ -127,6 +133,12 @@ function testType()
.adjust("0b100");
}).toThrow(adjuster.CAUSE.TYPE);

expect(() =>
{
adjuster.number()
.adjust([]);
}).toThrow(adjuster.CAUSE.TYPE);

expect(() =>
{
adjuster.number()
Expand Down

0 comments on commit f70ffa3

Please sign in to comment.