@unction/append
Advanced tools
Comparing version 2.0.0 to 2.1.0
{ | ||
"name": "@unction/append", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Takes a value and puts it at the end of the given list", | ||
@@ -57,3 +57,6 @@ "keywords": [ | ||
"instrument": false | ||
}, | ||
"dependencies": { | ||
"@unction/type": "2.0.0" | ||
} | ||
} |
# @unction/append | ||
![Tests][BADGE_TRAVIS] | ||
@@ -8,13 +7,16 @@ ![Stability][BADGE_STABILITY] | ||
> any -> Array<any> -> Array<any> | ||
> mixed -> (ArrayType | string) -> (ArrayType | string) | ||
Takes a value and puts it at the end of the given list | ||
Takes a value and puts it at the end of the given list. | ||
``` javascript | ||
append(4)([5]) // => [5, 4] | ||
append("c")("ab") // => "abc" | ||
``` | ||
> NOTE: While there is a type annotation in the README, this function cannot have type annotations due to a bug in flow. | ||
[BADGE_TRAVIS]: https://img.shields.io/travis/unctionjs/append.svg?maxAge=2592000&style=flat-square | ||
[BADGE_STABILITY]: https://img.shields.io/badge/stability-strong-green.svg?maxAge=2592000&style=flat-square | ||
[BADGE_DEPENDENCY]: https://img.shields.io/david/unctionjs/append.svg?maxAge=2592000&style=flat-square |
@@ -1,5 +0,19 @@ | ||
export default function append (left: any): Function { | ||
return function appendLeft (right: Array<any>): Array<any> { | ||
return [...right, left] | ||
/* eslint-disable no-extra-parens, no-unused-expressions */ | ||
import type from "@unction/type" | ||
export default function append (value: any): Function { | ||
return function appendLeft (orderedList: any): any { | ||
switch (type(orderedList)) { | ||
case "String": { | ||
return `${orderedList}${value}` | ||
} | ||
case "Array": { | ||
return [...orderedList, value] | ||
} | ||
default: { | ||
throw new Error(`append doesn't know how to deal with ${type(orderedList)}`) | ||
} | ||
} | ||
} | ||
} |
12
test.js
@@ -11,1 +11,13 @@ /* eslint-disable flowtype/require-parameter-type, flowtype/require-return-type */ | ||
}) | ||
test(({same, end}) => { | ||
same(append("c")("ab"), "abc") | ||
end() | ||
}) | ||
test(({throws, end}) => { | ||
throws(() => append("c")({})) | ||
end() | ||
}) |
@@ -8,8 +8,27 @@ "use strict"; | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
var _type = require("@unction/type"); | ||
function append(left) { | ||
return function appendLeft(right) { | ||
return [].concat(_toConsumableArray(right), [left]); | ||
var _type2 = _interopRequireDefault(_type); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } /* eslint-disable no-extra-parens, no-unused-expressions */ | ||
function append(value) { | ||
return function appendLeft(orderedList) { | ||
switch ((0, _type2.default)(orderedList)) { | ||
case "String": | ||
{ | ||
return "" + orderedList + value; | ||
} | ||
case "Array": | ||
{ | ||
return [].concat(_toConsumableArray(orderedList), [value]); | ||
} | ||
default: | ||
{ | ||
throw new Error("append doesn't know how to deal with " + (0, _type2.default)(orderedList)); | ||
} | ||
} | ||
}; | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
178834
68
4639
22
0
1
+ Added@unction/type@2.0.0
+ Added@unction/type@2.0.0(transitive)