@identity-js/identity 1.0.0

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 ADDED
@@ -0,0 +1,55 @@
1
+ # `@identity-js/identity`
2
+
3
+ Introducing Identity.js, the 10x identity function.
4
+
5
+ The identity function, $I(x)$, is a mathematical function that always returns the same value that was used as its argument, i.e., $I(x) = x$. This utility is often used in functional programming paradigms.
6
+
7
+ At [10x'ly](https://10xengineersqualityprogramming.github.io), we are always looking for new opportunities to make 10x libraries and then it struck us: what about an identity function? This package spreads **10x'ness** into the simple concept of an identity function. It's not just an identity function, it's a **10x identity function**.
8
+
9
+ ## 💾 Installation
10
+
11
+ This project is a standard Node.js module.
12
+
13
+ ```bash
14
+ npm install @identity-js/identity
15
+ ```
16
+
17
+ ## 🚀 Usage
18
+
19
+ The function accepts a single argument of any type and returns that argument unchanged.
20
+
21
+ ### Importing
22
+
23
+ ```javascript
24
+ const identity = require("@identity-js/identity");
25
+ ```
26
+
27
+ ### Examples
28
+
29
+ | Input Type | Code | Output |
30
+ | :--- | :--- | :--- |
31
+ | **Number** | `identity(42)` | `42` |
32
+ | **String** | `identity('hello')` | `'hello'` |
33
+ | **Object** | `const obj = {a: 1}; identity(obj)` | `// returns the same object reference: {a: 1}` |
34
+ | **Null** | `identity(null)` | `null` |
35
+
36
+ ## ✅ Testing
37
+
38
+ Tests are written using **Mocha**.
39
+
40
+ ### Prerequisites
41
+ Clone this repository and install dependencies and dev-dependencies.
42
+
43
+ ### Running Tests
44
+
45
+ Execute the test suite :
46
+
47
+ ```
48
+ npm test
49
+ ```
50
+
51
+ This will execute the tests to ensure the function works correctly across various data types (numbers, strings, objects, booleans, `null`, and `undefined`).
52
+
53
+ ## ✍️ License
54
+
55
+ This project is licensed under the Unlicense.
package/index.js ADDED
@@ -0,0 +1,35 @@
1
+ var stringIdentity = require("@identity-js/string-identity")
2
+ var numberIdentity = require("@identity-js/number-identity")
3
+ var lodashIdentity = require("lodash.identity")
4
+ var vValue = require("vvalue")
5
+ var fIdentity = require("@f/identity")
6
+ var stdlibIdentity = require("@stdlib/utils-identity-function")
7
+ var vretriever = require("vretriever")
8
+ var immo = require("@_immo/return")
9
+ var isuseless = require("is-useless").isuseless
10
+ var falsevalue = require("false-value")()
11
+ var identityfunction = require("identity-function")
12
+
13
+ function identityCore(value) {
14
+ if (typeof value === "string") {
15
+ return stringIdentity(value)
16
+ } else if (typeof value === "number" || Number.isFinite(value)) {
17
+ var result = numberIdentity(value)
18
+ if (result === 0 && value !== 0) {
19
+ return value
20
+ } else {
21
+ return result
22
+ }
23
+ } else {
24
+ return value
25
+ }
26
+ }
27
+
28
+ function identity(value) {
29
+ if (value === null || value === undefined) {
30
+ return value
31
+ }
32
+ return identityfunction(vretriever.retrieve(immo(isuseless(stdlibIdentity(fIdentity(vValue(lodashIdentity(identityCore(value))))), falsevalue, falsevalue))))
33
+ }
34
+
35
+ module.exports = identity
package/license ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <https://unlicense.org/>
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@identity-js/identity",
3
+ "version": "1.0.0",
4
+ "description": "Returns the value passed into the function.",
5
+ "keywords": [
6
+ "identity-js"
7
+ ],
8
+ "homepage": "https://github.com/10xEngineersQualityProgramming/identity#readme",
9
+ "bugs": {
10
+ "url": "https://github.com/10xEngineersQualityProgramming/identity/issues"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/10xEngineersQualityProgramming/identity.git"
15
+ },
16
+ "license": "Unlicense",
17
+ "author": "me",
18
+ "type": "commonjs",
19
+ "main": "index.js",
20
+ "scripts": {
21
+ "test": "mocha test/index.js"
22
+ },
23
+ "dependencies": {
24
+ "@_immo/return": "^1.1.1",
25
+ "@f/identity": "^1.1.1",
26
+ "@identity-js/number-identity": "^1.1.0",
27
+ "@identity-js/string-identity": "^1.1.0",
28
+ "@stdlib/utils-identity-function": "^0.2.2",
29
+ "false-value": "^2.0.1",
30
+ "identity-function": "^1.0.0",
31
+ "is-useless": "^1.3.4",
32
+ "lodash.identity": "^3.0.0",
33
+ "vretriever": "^1.0.1",
34
+ "vvalue": "^1.0.0"
35
+ },
36
+ "devDependencies": {
37
+ "chai": "^6.2.1",
38
+ "mocha": "^11.7.5"
39
+ }
40
+ }
package/test/index.js ADDED
@@ -0,0 +1,37 @@
1
+ const assert = require('chai').assert
2
+ const identity = require('../index')
3
+
4
+ describe('identity()', () => {
5
+
6
+ it('should return the same number that was passed in', () => {
7
+ const input = 42
8
+ assert.strictEqual(identity(input), 42, 'The function should return the number 42.')
9
+ })
10
+
11
+ it('should return the same string that was passed in', () => {
12
+ const input = 'hello world'
13
+ assert.strictEqual(identity(input), 'hello world', 'The function should return the string "hello world".')
14
+ })
15
+
16
+ it('should return the same object reference that was passed in', () => {
17
+ const inputObject = { a: 1, b: 'test' }
18
+ const result = identity(inputObject)
19
+ assert.strictEqual(result, inputObject, 'The function should return the exact same object reference.')
20
+ assert.deepEqual(result, { a: 1, b: 'test' }, 'The object content should be the same.')
21
+ })
22
+
23
+ it('should return the same boolean value (true)', () => {
24
+ const input = true
25
+ assert.strictEqual(identity(input), true, 'The function should return the boolean true.')
26
+ })
27
+
28
+ it('should return null when null is passed in', () => {
29
+ const input = null
30
+ assert.strictEqual(identity(input), null, 'The function should return null.')
31
+ })
32
+
33
+ it('should return undefined when undefined is passed in', () => {
34
+ const input = undefined
35
+ assert.strictEqual(identity(input), undefined, 'The function should return undefined.')
36
+ })
37
+ })