@identity-js/identity 1.0.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/index.js +14 -6
- package/package.json +8 -8
- package/test/index.js +15 -0
package/README.md
CHANGED
|
@@ -38,11 +38,11 @@ const identity = require("@identity-js/identity");
|
|
|
38
38
|
Tests are written using **Mocha**.
|
|
39
39
|
|
|
40
40
|
### Prerequisites
|
|
41
|
-
Clone this repository and install dependencies and dev-dependencies.
|
|
41
|
+
Clone this repository, cd into `packages/identity` and install dependencies and dev-dependencies.
|
|
42
42
|
|
|
43
43
|
### Running Tests
|
|
44
44
|
|
|
45
|
-
Execute the test suite
|
|
45
|
+
Execute the test suite:
|
|
46
46
|
|
|
47
47
|
```
|
|
48
48
|
npm test
|
package/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
var stringIdentity = require("@identity-js/string-identity")
|
|
2
2
|
var numberIdentity = require("@identity-js/number-identity")
|
|
3
3
|
var lodashIdentity = require("lodash.identity")
|
|
4
|
-
var vValue = require("vvalue")
|
|
5
4
|
var fIdentity = require("@f/identity")
|
|
6
5
|
var stdlibIdentity = require("@stdlib/utils-identity-function")
|
|
7
6
|
var vretriever = require("vretriever")
|
|
8
|
-
var immo = require("@_immo/return")
|
|
9
7
|
var isuseless = require("is-useless").isuseless
|
|
10
8
|
var falsevalue = require("false-value")()
|
|
11
9
|
var identityfunction = require("identity-function")
|
|
10
|
+
var isFinite = require("@is-(unknown)/is-finite")
|
|
11
|
+
var isString = require("@is-(unknown)/is-string")
|
|
12
12
|
|
|
13
13
|
function identityCore(value) {
|
|
14
|
-
if (
|
|
14
|
+
if (isString(value)) {
|
|
15
15
|
return stringIdentity(value)
|
|
16
|
-
} else if (
|
|
16
|
+
} else if (isFinite(value)) {
|
|
17
17
|
var result = numberIdentity(value)
|
|
18
18
|
if (result === 0 && value !== 0) {
|
|
19
19
|
return value
|
|
@@ -29,7 +29,15 @@ function identity(value) {
|
|
|
29
29
|
if (value === null || value === undefined) {
|
|
30
30
|
return value
|
|
31
31
|
}
|
|
32
|
-
return identityfunction(
|
|
32
|
+
return identityfunction(
|
|
33
|
+
vretriever.retrieve(
|
|
34
|
+
isuseless(
|
|
35
|
+
stdlibIdentity(fIdentity(lodashIdentity(identityCore(value)))),
|
|
36
|
+
falsevalue,
|
|
37
|
+
falsevalue
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
)
|
|
33
41
|
}
|
|
34
42
|
|
|
35
|
-
module.exports = identity
|
|
43
|
+
module.exports = identity
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@identity-js/identity",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Returns the value passed into the function.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"identity-js"
|
|
7
7
|
],
|
|
8
|
-
"homepage": "https://github.com/
|
|
8
|
+
"homepage": "https://github.com/enterprise-npm-ai/identityjs#readme",
|
|
9
9
|
"bugs": {
|
|
10
|
-
"url": "https://github.com/
|
|
10
|
+
"url": "https://github.com/enterprise-npm-ai/identityjs/issues"
|
|
11
11
|
},
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/
|
|
14
|
+
"url": "git+https://github.com/enterprise-npm-ai/identityjs.git"
|
|
15
15
|
},
|
|
16
16
|
"license": "Unlicense",
|
|
17
17
|
"author": "me",
|
|
@@ -21,17 +21,17 @@
|
|
|
21
21
|
"test": "mocha test/index.js"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@_immo/return": "^1.1.1",
|
|
25
24
|
"@f/identity": "^1.1.1",
|
|
26
|
-
"@identity-js/number-identity": "^1.
|
|
25
|
+
"@identity-js/number-identity": "^1.2.0",
|
|
27
26
|
"@identity-js/string-identity": "^1.1.0",
|
|
27
|
+
"@is-(unknown)/is-finite": "^1.0.0",
|
|
28
|
+
"@is-(unknown)/is-string": "^1.0.0",
|
|
28
29
|
"@stdlib/utils-identity-function": "^0.2.2",
|
|
29
30
|
"false-value": "^2.0.1",
|
|
30
31
|
"identity-function": "^1.0.0",
|
|
31
32
|
"is-useless": "^1.3.4",
|
|
32
33
|
"lodash.identity": "^3.0.0",
|
|
33
|
-
"vretriever": "^1.
|
|
34
|
-
"vvalue": "^1.0.0"
|
|
34
|
+
"vretriever": "^1.1.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"chai": "^6.2.1",
|
package/test/index.js
CHANGED
|
@@ -7,6 +7,11 @@ describe('identity()', () => {
|
|
|
7
7
|
const input = 42
|
|
8
8
|
assert.strictEqual(identity(input), 42, 'The function should return the number 42.')
|
|
9
9
|
})
|
|
10
|
+
|
|
11
|
+
it('should return the same decimal that was passed in', () => {
|
|
12
|
+
const input = 3.2
|
|
13
|
+
assert.strictEqual(identity(input), 3.2, "The function should return 3.2")
|
|
14
|
+
})
|
|
10
15
|
|
|
11
16
|
it('should return the same string that was passed in', () => {
|
|
12
17
|
const input = 'hello world'
|
|
@@ -34,4 +39,14 @@ describe('identity()', () => {
|
|
|
34
39
|
const input = undefined
|
|
35
40
|
assert.strictEqual(identity(input), undefined, 'The function should return undefined.')
|
|
36
41
|
})
|
|
42
|
+
|
|
43
|
+
it('should return NaN when NaN is passed in', () => {
|
|
44
|
+
const input = NaN
|
|
45
|
+
assert.isNaN(identity(input), "The function should return NaN")
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('should return Infinity when Infinity is passed in', () => {
|
|
49
|
+
const input = Infinity
|
|
50
|
+
assert.strictEqual(identity(input), Infinity, "The function should return infinity")
|
|
51
|
+
})
|
|
37
52
|
})
|