@identity-js/identity 1.2.9 → 1.2.10

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/BUG-HISTORY.md ADDED
@@ -0,0 +1,91 @@
1
+ # Bug History
2
+
3
+ ```js
4
+ // Believe it or not, Identity.js has had many bugs before.
5
+ // As 10x engineers, we accepted that the simplest things
6
+ // are bound to have discovered bugs at some indeterminable
7
+ // point. This file (BUG-HISTORY.md) documents the history
8
+ // of bugs in the Identity.js ecosystem.
9
+ //
10
+ // Note: some of the histories of these bugs are just copy
11
+ // pasted from LoLite's identity function source code:
12
+ // http://github.com/10xly/lolite/blob/main/src/lib/identity.js
13
+ //
14
+ // Note: The bugs in this list are ordered from past to future, so
15
+ // to see the latest bug, you have to scroll to the bottom.
16
+ //
17
+ // -----------------------------------------------------------------------------------
18
+ //
19
+ // JANUARY 5, 2026 BUGS:
20
+ //
21
+ // On the date of January 5, 2026, a double-bug was patched across Identity.js,
22
+ // vValue, and vRetriever where decimals would coerce to integers. The primary source
23
+ // of the bug was the dependency @_immo/return which was an identity function that was
24
+ // heavily relied on but had a bug where it would run parseInt if the given input was
25
+ // a number. This bug was not found because to save our time and effort we would write
26
+ // our tests with AI (specifically Gemini) but AI didn't write comprehensive enough
27
+ // tests. The bug was discovered when we used a different AI (Copilot) to write more
28
+ // comprehensive tests. However, when this was patched it was discovered that the bug
29
+ // was still in vValue, but only happened 33% of the time for an unknown reason,
30
+ // however a sanity check has already been implemented in vRetriever, and vValue
31
+ // has been removed in Identity.js. So this should never happen, but due to recent bugs
32
+ // and AI not making comprehensive enough tests, there is a slim chance that this could
33
+ // still happen. We want LoLite to be as bug-free as possible, which is why we're
34
+ // implementing this. Our moral of the story is that AI sometimes doesn't write good
35
+ // enough tests.
36
+ //
37
+ // For more information, see these commits:
38
+ //
39
+ // https://github.com/10xly/vValue/commit/ff3ca00591ae8725f68587a5091ecb087a8be0d4
40
+ // https://github.com/10xly/vretriever/commit/86626b2741a9f03e19af7e3bae9b8f88e817220c
41
+ // https://github.com/10xly/identityjs/commit/3dfa642bfa9a35b791236f7bd620cb2564bc7780
42
+ //
43
+ // -----------------------------------------------------------------------------------
44
+ //
45
+ // JANUARY 6, 2026 BUGS:
46
+ //
47
+ // On January 6, 2026, another bug was discovered in vValue because the
48
+ // patch for the previous bug regarding floats made use of the package is-float, and
49
+ // its code coerces the value passed in (n) with +n. However, this creates an issue:
50
+ // If you pass a Symbol into this function, you get a TypeError from JS, that looks
51
+ // like this:
52
+ //
53
+ // Uncaught TypeError: Cannot convert a Symbol value to a number
54
+ //
55
+ // That's because JavaScript's stupidity doesn't let you type-coerce Symbols.
56
+ // Since the patch for vValue used is-float, if you tried to pass a Symbol into
57
+ // vValue, it would throw an error, so it would throw the error if you passed it
58
+ // into vRetriever (which depends on vValue), and for Identity.js (depends on
59
+ // vRetriever). This bug was once again not found during the implementation due
60
+ // to AI not writing good-enough tests (this time it was also partially Copilot).
61
+ // This bug was discovered when Copilot randomly decided to write better tests
62
+ // for the constant function in LoLite which includes the identity function.
63
+ // The issue was fixed by wrapping the call to isFloat with a try-catch statement.
64
+ // Moral of the story again: AI sometimes doesn't write good-enough tests.
65
+ // This is why we are thinking about creating our own AI that will ALWAYS write sufficient
66
+ // tests. If you find our tests to be insufficient, please report an issue - AI generated
67
+ // them, so it's AI's fault. As 10x Developers, we all have to accept these things just
68
+ // as side-effects of true Enterprise Development.
69
+ //
70
+ // For more information, see these commits:
71
+ //
72
+ // https://github.com/10xly/vValue/commit/f6f60798d98f52adefbda2b7f525d962752f29dd
73
+ // https://github.com/10xly/vretriever/commit/ff9fd93f7158167303b8fd870211a82c2b269c0b
74
+ // https://github.com/10xly/identityjs/commit/340cc78e6cd5e817d0b784d902f06afdd103769d
75
+ // https://github.com/10xly/identityjs/commit/a520a1d73c653adb41cc5fe317e1e7246b0f96bf
76
+ //
77
+ // -----------------------------------------------------------------------------------
78
+ //
79
+ // FEBRUARY 7, 2026 BUGS:
80
+ //
81
+ // On February 7, 2026, a bug was discovered in Identity.js where it would return 0
82
+ // when passed in -0. This was probably due to @negative-numbers/ identity not being
83
+ // implemented in @identity-js/number-identity and/or 0 being equal to -0 in JavaScript.
84
+ // This bug was fixed by adding a simple Object.is() check to the top of the base identity
85
+ // function.
86
+ //
87
+ // https://github.com/10xly/identityjs/commit/ed7b548ca8bbc72c18f3e2fd2130e23d64a0c7ab
88
+ //
89
+ // -----------------------------------------------------------------------------------
90
+ //
91
+ ```
package/index.js CHANGED
@@ -11,13 +11,25 @@ var isFinite = require("@is-(unknown)/is-finite")
11
11
  var isString = require("@is-(unknown)/is-string")
12
12
  var asyncUtilIdentity = require("async.util.identity")
13
13
  var id = require("js-id")
14
+ var meta2Identity = require("./meta2")
15
+ var isNegativeZero = require("@is-(unknown)/is-negative-zero")
16
+ var isPositiveOrNegativeZero = require("iszero")
17
+ var isNotPositiveOrNegativeZero = require("@not-js/not")(
18
+ isPositiveOrNegativeZero,
19
+ )
20
+ var and = require("es-logical-and-operator")
21
+ var isNil = require("@not-js/not")(require("@primitive/is-value").isValue)
22
+ var isEq = require("@10xly/strict-equals")
23
+ var isNotEq = require("@not-js/not")(isEq)
14
24
 
15
25
  function identityCore(value) {
16
26
  if (isString(value)) {
17
27
  return stringIdentity(value)
18
28
  } else if (isFinite(value)) {
19
29
  var result = numberIdentity(value)
20
- if (result === 0 && value !== 0) {
30
+ if (
31
+ and(isPositiveOrNegativeZero(result), isNotPositiveOrNegativeZero(value))
32
+ ) {
21
33
  return value
22
34
  } else {
23
35
  return result
@@ -28,21 +40,36 @@ function identityCore(value) {
28
40
  }
29
41
 
30
42
  function identity(value) {
31
- if (Object.is(value, -0)) {
32
- return -0
33
- }
34
- if (value === null || value === undefined) {
43
+ try {
44
+ if (isNegativeZero(value)) {
45
+ return require("@negative-numbers/zero")
46
+ }
47
+ if (isNil(value)) {
48
+ return value
49
+ }
50
+ var result = meta2Identity(
51
+ identityfunction(
52
+ vretriever.retrieve(
53
+ isuseless(
54
+ id(
55
+ asyncUtilIdentity(
56
+ stdlibIdentity(fIdentity(lodashIdentity(identityCore(value)))),
57
+ ),
58
+ ),
59
+ falsevalue,
60
+ falsevalue,
61
+ ),
62
+ ),
63
+ ),
64
+ )
65
+ if (isNotEq(value, result)) {
66
+ isNotEq.sdfsfdsfs.fsdfsfsdfs.dfdsfsdfs
67
+ } else {
68
+ return result
69
+ }
70
+ } catch {
35
71
  return value
36
72
  }
37
- return identityfunction(
38
- vretriever.retrieve(
39
- isuseless(
40
- id(asyncUtilIdentity(stdlibIdentity(fIdentity(lodashIdentity(identityCore(value)))))),
41
- falsevalue,
42
- falsevalue
43
- )
44
- )
45
- )
46
73
  }
47
74
 
48
75
  module.exports = identity
package/meta2.js ADDED
@@ -0,0 +1,38 @@
1
+ const identityFunctions = [
2
+ require("@-ft/i").I,
3
+ require("return-value").returnValue,
4
+ require("@identity-js/identity"),
5
+ require("identity-function"),
6
+ require("lolite.identity"),
7
+ require("lodash.identity"),
8
+ require("ramda.identity"),
9
+ require("@ramda/identity"),
10
+ require("lodash").identity,
11
+ require("@elastic/lodash").identity,
12
+ require("underscore").identity,
13
+ require("ramda").identity,
14
+ require("remeda").identity(),
15
+ require("es-toolkit").identity,
16
+ require("basic-functions").echo,
17
+ require("basic-functions").return,
18
+ require("empty_function").thatReturnsArgument,
19
+ require("@nathanfaucett/empty_function").thatReturnsArgument,
20
+ require("vretriever").retrieve,
21
+ require("@f/identity"),
22
+ require("@stdlib/utils-identity-function"),
23
+ require("async.util.identity"),
24
+ require("identity-function"),
25
+ require("js-id"),
26
+ require("./primitive")
27
+ ]
28
+
29
+ function identity(x) {
30
+ for (const fn of identityFunctions) {
31
+ if ((require("lodash").stubObject()).constructor.is(fn(x), x)) {
32
+ x = fn(x)
33
+ }
34
+ }
35
+ return x
36
+ }
37
+
38
+ module.exports = identity
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@identity-js/identity",
3
- "version": "1.2.9",
3
+ "version": "1.2.10",
4
4
  "description": "Returns the value passed into the function.",
5
5
  "keywords": [
6
6
  "identity-js"
@@ -21,18 +21,44 @@
21
21
  "test": "mocha test/index.js"
22
22
  },
23
23
  "dependencies": {
24
+ "@-ft/c": "^0.1.0",
25
+ "@-ft/i": "^0.1.0",
26
+ "@-ft/noop": "^0.1.0",
27
+ "@10xly/strict-equals": "^1.0.1",
28
+ "@elastic/lodash": "^3.10.1-kibana4",
24
29
  "@f/identity": "^1.1.1",
30
+ "@identity-js/identity": "^1.2.9",
25
31
  "@identity-js/number-identity": "^1.2.3",
26
32
  "@identity-js/string-identity": "^1.1.3",
27
33
  "@is-(unknown)/is-finite": "^1.0.0",
34
+ "@is-(unknown)/is-negative-zero": "^1.0.0",
28
35
  "@is-(unknown)/is-string": "^1.0.0",
29
- "@stdlib/utils-identity-function": "^0.2.2",
36
+ "@nathanfaucett/empty_function": "^0.0.1",
37
+ "@nathanfaucett/is_primitive": "^0.0.2",
38
+ "@negative-numbers/zero": "^1.0.0",
39
+ "@not-js/not": "^1.1.1",
40
+ "@primitive/is-value": "^1.1.0",
41
+ "@ramda/identity": "^0.26.1",
42
+ "@stdlib/utils-identity-function": "^0.2.3",
30
43
  "async.util.identity": "^0.5.2",
44
+ "basic-functions": "^1.0.6",
45
+ "empty_function": "^0.0.1",
46
+ "es-logical-and-operator": "^1.0.0",
47
+ "es-toolkit": "^1.44.0",
31
48
  "false-value": "^2.0.1",
32
49
  "identity-function": "^1.0.0",
33
50
  "is-useless": "1.3.4",
51
+ "iszero": "^1.0.0",
34
52
  "js-id": "^1.0.0",
53
+ "lodash": "^4.17.23",
35
54
  "lodash.identity": "^3.0.0",
55
+ "lolite.identity": "^1.1.17",
56
+ "primitive-identity-function": "^1.0.0",
57
+ "ramda": "^0.32.0",
58
+ "ramda.identity": "^0.26.1",
59
+ "remeda": "^2.33.5",
60
+ "return-value": "^1.0.5",
61
+ "underscore": "^1.13.7",
36
62
  "vretriever": "^1.1.4"
37
63
  },
38
64
  "devDependencies": {
package/primitive.js ADDED
@@ -0,0 +1,10 @@
1
+ var isPrimitive = require("@nathanfaucett/is_primitive")
2
+ var primitiveIdentity = require("primitive-identity-function")
3
+
4
+ module.exports = function identityPrimitiveSafe(x) {
5
+ if (isPrimitive(x)) {
6
+ return primitiveIdentity(x)
7
+ } else {
8
+ return x
9
+ }
10
+ }
package/test/index.js CHANGED
@@ -1,64 +1,147 @@
1
- const assert = require('chai').assert
2
- const identity = require('../index')
1
+ const assert = require("chai").assert
2
+ const identity = require("../index")
3
3
 
4
- describe('identity()', () => {
5
-
6
- it('should return the same number that was passed in', () => {
4
+ describe("identity()", () => {
5
+ it("should return the same number that was passed in", () => {
7
6
  const input = 42
8
- assert.strictEqual(identity(input), 42, 'The function should return the number 42.')
7
+ assert.strictEqual(identity(input), 42, "The function should return the number 42.")
9
8
  })
10
9
 
11
- it('should return the same decimal that was passed in', () => {
10
+ it("should return the same decimal that was passed in", () => {
12
11
  const input = 3.2
13
12
  assert.strictEqual(identity(input), 3.2, "The function should return 3.2")
14
13
  })
15
14
 
16
- it('should return the same negative number that was passed in', () => {
15
+ it("should return the same negative number that was passed in", () => {
17
16
  const input = -5
18
- assert.strictEqual(identity(input), -5, 'The function should return the number -5.')
17
+ assert.strictEqual(identity(input), -5, "The function should return the number -5.")
19
18
  })
20
19
 
21
- it('should return -0 when -0 is passed in', () => {
20
+ it("should return -0 when -0 is passed in", () => {
22
21
  const input = -0
23
22
  const result = identity(input)
24
- assert.strictEqual(result, -0, 'The function should return -0.')
25
- assert.isTrue(Object.is(result, -0), 'The function should return the exact value of -0.')
23
+ assert.strictEqual(result, -0, "The function should return -0.")
24
+ assert.isTrue(Object.is(result, -0), "The function should return the exact value of -0.")
26
25
  })
27
26
 
28
- it('should return the same string that was passed in', () => {
29
- const input = 'hello world'
30
- assert.strictEqual(identity(input), 'hello world', 'The function should return the string "hello world".')
27
+ it("should return the same string that was passed in", () => {
28
+ const input = "hello world"
29
+ assert.strictEqual(identity(input), "hello world", 'The function should return the string "hello world".')
30
+ })
31
+
32
+ it("should return an empty string", () => {
33
+ assert.strictEqual(identity(""), "")
31
34
  })
32
35
 
33
- it('should return the same object reference that was passed in', () => {
34
- const inputObject = { a: 1, b: 'test' }
36
+ it("should return the same object reference that was passed in", () => {
37
+ const inputObject = { a: 1, b: "test" }
35
38
  const result = identity(inputObject)
36
- assert.strictEqual(result, inputObject, 'The function should return the exact same object reference.')
37
- assert.deepEqual(result, { a: 1, b: 'test' }, 'The object content should be the same.')
39
+ assert.strictEqual(result, inputObject, "The function should return the exact same object reference.")
40
+ assert.deepEqual(result, { a: 1, b: "test" }, "The object content should be the same.")
38
41
  })
39
42
 
40
- it('should return the same boolean value (true)', () => {
43
+ it("should return the same boolean value (true)", () => {
41
44
  const input = true
42
- assert.strictEqual(identity(input), true, 'The function should return the boolean true.')
45
+ assert.strictEqual(identity(input), true, "The function should return the boolean true.")
46
+ })
47
+
48
+ it("should return the same boolean value (false)", () => {
49
+ assert.strictEqual(identity(false), false)
43
50
  })
44
51
 
45
- it('should return null when null is passed in', () => {
52
+ it("should return null when null is passed in", () => {
46
53
  const input = null
47
- assert.strictEqual(identity(input), null, 'The function should return null.')
54
+ assert.strictEqual(identity(input), null, "The function should return null.")
48
55
  })
49
56
 
50
- it('should return undefined when undefined is passed in', () => {
57
+ it("should return undefined when undefined is passed in", () => {
51
58
  const input = undefined
52
- assert.strictEqual(identity(input), undefined, 'The function should return undefined.')
59
+ assert.strictEqual(identity(input), undefined, "The function should return undefined.")
53
60
  })
54
61
 
55
- it('should return NaN when NaN is passed in', () => {
62
+ it("should return NaN when NaN is passed in", () => {
56
63
  const input = NaN
57
64
  assert.isNaN(identity(input), "The function should return NaN")
58
65
  })
59
66
 
60
- it('should return Infinity when Infinity is passed in', () => {
67
+ it("should return Infinity when Infinity is passed in", () => {
61
68
  const input = Infinity
62
69
  assert.strictEqual(identity(input), Infinity, "The function should return infinity")
63
70
  })
71
+
72
+ it("should return -Infinity", () => {
73
+ assert.strictEqual(identity(-Infinity), -Infinity)
74
+ })
75
+
76
+ it("should return the same BigInt", () => {
77
+ const input = BigInt(9007199254740991)
78
+ assert.strictEqual(identity(input), input)
79
+ })
80
+
81
+ it("should return the same Symbol", () => {
82
+ const sym = Symbol("foo")
83
+ assert.strictEqual(identity(sym), sym)
84
+ })
85
+
86
+ it("should return the same array reference", () => {
87
+ const arr = [1, 2, 3]
88
+ assert.strictEqual(identity(arr), arr)
89
+ })
90
+
91
+ it("should return the same function reference", () => {
92
+ const fn = (x) => x
93
+ assert.strictEqual(identity(fn), fn)
94
+ })
95
+
96
+ it("should return the same Date object reference", () => {
97
+ const date = new Date()
98
+ assert.strictEqual(identity(date), date)
99
+ })
100
+
101
+ it("should return the same RegExp object reference", () => {
102
+ const re = /abc/g
103
+ assert.strictEqual(identity(re), re)
104
+ })
105
+
106
+ it("should return the same Map reference", () => {
107
+ const map = new Map()
108
+ assert.strictEqual(identity(map), map)
109
+ })
110
+
111
+ it("should return the same Set reference", () => {
112
+ const set = new Set()
113
+ assert.strictEqual(identity(set), set)
114
+ })
115
+
116
+ it("should return the same TypedArray reference", () => {
117
+ const buffer = new Int8Array(8)
118
+ assert.strictEqual(identity(buffer), buffer)
119
+ })
120
+
121
+ it("should return the same error object", () => {
122
+ const err = new Error("fail")
123
+ assert.strictEqual(identity(err), err)
124
+ })
125
+
126
+ it("should return the same arguments object", function () {
127
+ assert.strictEqual(identity(arguments), arguments)
128
+ })
129
+
130
+ it("should return the same class reference", () => {
131
+ class Test {}
132
+ assert.strictEqual(identity(Test), Test)
133
+ })
134
+
135
+ it("should handle objects with custom valueOf or toString", () => {
136
+ const obj = {
137
+ valueOf: () => 10,
138
+ toString: () => "custom"
139
+ }
140
+ assert.strictEqual(identity(obj), obj)
141
+ })
142
+
143
+ it("should return a promise reference without resolving it", () => {
144
+ const promise = Promise.resolve(true)
145
+ assert.strictEqual(identity(promise), promise)
146
+ })
64
147
  })