Skip to content

Commit

Permalink
Merge pull request #155 from shimataro/develop
Browse files Browse the repository at this point in the history
version 0.13.0
  • Loading branch information
shimataro authored Jul 19, 2018
2 parents 771943a + 5494508 commit 92cdcc1
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 9 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [0.13.0] - 2018-07-20
### Added
* `adjuster.numberArray().eachInteger()`

### Fixed
* `adjuster.numberArray().eachIn()` in JSDoc (should be `adjuster.numberArray().eachOnly()`)
* `adjuster.stringArray().eachIn()` in JSDoc (should be `adjuster.stringArray().eachOnly()`)

## [0.12.0] - 2018-07-18
### Added
* `adjuster.STRING_PATTERN`, regular expressions for `adjuster.string().pattern()`
Expand Down Expand Up @@ -130,7 +138,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/v0.12.0...HEAD
[Unreleased]: https://github.com/shimataro/node-adjuster/compare/v0.13.0...HEAD
[0.13.0]: https://github.com/shimataro/node-adjuster/compare/v0.12.0...v0.13.0
[0.12.0]: https://github.com/shimataro/node-adjuster/compare/v0.11.0...v0.12.0
[0.11.0]: https://github.com/shimataro/node-adjuster/compare/v0.10.1...v0.11.0
[0.10.1]: https://github.com/shimataro/node-adjuster/compare/v0.10.0...v0.10.1
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ interface NumberArrayAdjuster {
eachAcceptNull(value?: number|null /* = null */): NumberArrayAdjuster;
eachAcceptEmptyString(value?: number|null /* = null */): NumberArrayAdjuster;
eachAcceptSpecialFormats(): NumberArrayAdjuster;
eachInteger(adjust?: boolean /* = false */): NumberArrayAdjuster;
eachOnly(...values: number[]): NumberArrayAdjuster;
eachMinValue(value: number, adjust?: boolean /* = false */): NumberArrayAdjuster;
eachMaxValue(value: number, adjust?: boolean /* = false */): NumberArrayAdjuster;
Expand Down
10 changes: 5 additions & 5 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion 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": "0.12.0",
"version": "0.13.0",
"author": "shimataro",
"license": "MIT",
"repository": {
Expand Down
10 changes: 9 additions & 1 deletion src/adjusters/numberArray.es
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,18 @@ class NumberArrayAdjuster extends AdjusterBase
* @return {NumberArrayAdjuster}
*/

/**
* limit value to integer for each elements
* @method
* @name NumberArrayAdjuster#eachInteger
* @param {boolean} [adjust=false] adjust to integer value is not an integer; default is ERROR
* @return {NumberArrayAdjuster}
*/

/**
* accept only specified values for each elements
* @method
* @name NumberArrayAdjuster#eachIn
* @name NumberArrayAdjuster#eachOnly
* @param {...number} values values to be accepted
* @return {NumberArrayAdjuster}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/adjusters/stringArray.es
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class StringArrayAdjuster extends AdjusterBase
/**
* accept only specified values for each elements
* @method
* @name StringArrayAdjuster#eachIn
* @name StringArrayAdjuster#eachOnly
* @param {...string} values values to be accepted
* @return {StringArrayAdjuster}
*/
Expand Down
12 changes: 12 additions & 0 deletions src/libs/decorators/numberArray/each.es
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default AdjusterBase.decoratorBuilder(_adjust)
eachAcceptNull: _featureEachAcceptNull,
eachAcceptEmptyString: _featureEachAcceptEmptyString,
eachAcceptSpecialFormats: _featureEachAcceptSpecialFormats,
eachInteger: _featureEachInteger,
eachOnly: _featureEachOnly,
eachMinValue: _featureEachMinValue,
eachMaxValue: _featureEachMaxValue,
Expand Down Expand Up @@ -80,6 +81,17 @@ function _featureEachAcceptSpecialFormats(params)
params.objAdjuster.acceptSpecialFormats();
}

/**
* limit value to integer for each elements
* @param {Object} params parameters
* @param {boolean} [adjust=false] adjust to integer value is not an integer; default is ERROR
* @return {void}
*/
function _featureEachInteger(params, adjust = false)
{
params.objAdjuster.integer(adjust);
}

/**
* accept only specified values for each elements
* @param {Object} params parameters
Expand Down
27 changes: 27 additions & 0 deletions test/adjusters/numberArray.test.es
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import adjuster from "index";
describe("eachAcceptNull", testEachAcceptNull);
describe("eachAcceptEmptyString", testEachAcceptEmptyString);
describe("eachAcceptSpecialFormats", testEachAcceptSpecialFormats);
describe("eachInteger", testEachInteger);
describe("eachOnly", testEachOnly);
describe("eachMinValue", testEachMinValue);
describe("eachMaxValue", testEachMaxValue);
Expand Down Expand Up @@ -315,6 +316,32 @@ function testEachAcceptSpecialFormats()
});
}

/**
* each elements; integer
* @return {void}
*/
function testEachInteger()
{
it("should be OK", () =>
{
expect(adjuster.numberArray().eachInteger()
.adjust([1, 2, 3])).toEqual([1, 2, 3]);
});
it("should be adjusted", () =>
{
expect(adjuster.numberArray().eachInteger(true)
.adjust([3.14, -3.14, "3.14"])).toEqual([3, -3, 3]);
});
it("should cause error(s)", () =>
{
expect(() =>
{
adjuster.numberArray().eachInteger()
.adjust([3.14]);
}).toThrow(adjuster.CAUSE.EACH_TYPE);
});
}

/**
* each elements; set
* @return {void}
Expand Down

0 comments on commit 92cdcc1

Please sign in to comment.