@identity-js/identity 1.3.0 → 1.3.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/unstable.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- declare function identity<T>(x: T): T
2
-
1
+ declare function identity<T>(x: T): T
2
+
3
3
  export = identity
package/test/index.js DELETED
@@ -1,192 +0,0 @@
1
- const assert = require("chai").assert
2
- const identityStable = require("../index")
3
- const identityUnstable = require("../unstable")
4
-
5
- function testIdentity(identity) {
6
- describe("identity()", () => {
7
- it("should return the same number that was passed in", () => {
8
- const input = 42
9
- assert.strictEqual(
10
- identity(input),
11
- 42,
12
- "The function should return the number 42.",
13
- )
14
- })
15
-
16
- it("should return the same decimal that was passed in", () => {
17
- const input = 3.2
18
- assert.strictEqual(identity(input), 3.2, "The function should return 3.2")
19
- })
20
-
21
- it("should return the same negative number that was passed in", () => {
22
- const input = -5
23
- assert.strictEqual(
24
- identity(input),
25
- -5,
26
- "The function should return the number -5.",
27
- )
28
- })
29
-
30
- it("should return -0 when -0 is passed in", () => {
31
- const input = -0
32
- const result = identity(input)
33
- assert.strictEqual(result, -0, "The function should return -0.")
34
- assert.isTrue(
35
- Object.is(result, -0),
36
- "The function should return the exact value of -0.",
37
- )
38
- })
39
-
40
- it("should return the same string that was passed in", () => {
41
- const input = "hello world"
42
- assert.strictEqual(
43
- identity(input),
44
- "hello world",
45
- 'The function should return the string "hello world".',
46
- )
47
- })
48
-
49
- it("should return an empty string", () => {
50
- assert.strictEqual(identity(""), "")
51
- })
52
-
53
- it("should return the same object reference that was passed in", () => {
54
- const inputObject = { a: 1, b: "test" }
55
- const result = identity(inputObject)
56
- assert.strictEqual(
57
- result,
58
- inputObject,
59
- "The function should return the exact same object reference.",
60
- )
61
- assert.deepEqual(
62
- result,
63
- { a: 1, b: "test" },
64
- "The object content should be the same.",
65
- )
66
- })
67
-
68
- it("should return the same boolean value (true)", () => {
69
- const input = true
70
- assert.strictEqual(
71
- identity(input),
72
- true,
73
- "The function should return the boolean true.",
74
- )
75
- })
76
-
77
- it("should return the same boolean value (false)", () => {
78
- assert.strictEqual(identity(false), false)
79
- })
80
-
81
- it("should return null when null is passed in", () => {
82
- const input = null
83
- assert.strictEqual(
84
- identity(input),
85
- null,
86
- "The function should return null.",
87
- )
88
- })
89
-
90
- it("should return undefined when undefined is passed in", () => {
91
- const input = undefined
92
- assert.strictEqual(
93
- identity(input),
94
- undefined,
95
- "The function should return undefined.",
96
- )
97
- })
98
-
99
- it("should return NaN when NaN is passed in", () => {
100
- const input = NaN
101
- assert.isNaN(identity(input), "The function should return NaN")
102
- })
103
-
104
- it("should return Infinity when Infinity is passed in", () => {
105
- const input = Infinity
106
- assert.strictEqual(
107
- identity(input),
108
- Infinity,
109
- "The function should return infinity",
110
- )
111
- })
112
-
113
- it("should return -Infinity", () => {
114
- assert.strictEqual(identity(-Infinity), -Infinity)
115
- })
116
-
117
- it("should return the same BigInt", () => {
118
- const input = BigInt(9007199254740991)
119
- assert.strictEqual(identity(input), input)
120
- })
121
-
122
- it("should return the same Symbol", () => {
123
- const sym = Symbol("foo")
124
- assert.strictEqual(identity(sym), sym)
125
- })
126
-
127
- it("should return the same array reference", () => {
128
- const arr = [1, 2, 3]
129
- assert.strictEqual(identity(arr), arr)
130
- })
131
-
132
- it("should return the same function reference", () => {
133
- const fn = (x) => x
134
- assert.strictEqual(identity(fn), fn)
135
- })
136
-
137
- it("should return the same Date object reference", () => {
138
- const date = new Date()
139
- assert.strictEqual(identity(date), date)
140
- })
141
-
142
- it("should return the same RegExp object reference", () => {
143
- const re = /abc/g
144
- assert.strictEqual(identity(re), re)
145
- })
146
-
147
- it("should return the same Map reference", () => {
148
- const map = new Map()
149
- assert.strictEqual(identity(map), map)
150
- })
151
-
152
- it("should return the same Set reference", () => {
153
- const set = new Set()
154
- assert.strictEqual(identity(set), set)
155
- })
156
-
157
- it("should return the same TypedArray reference", () => {
158
- const buffer = new Int8Array(8)
159
- assert.strictEqual(identity(buffer), buffer)
160
- })
161
-
162
- it("should return the same error object", () => {
163
- const err = new Error("fail")
164
- assert.strictEqual(identity(err), err)
165
- })
166
-
167
- it("should return the same arguments object", function () {
168
- assert.strictEqual(identity(arguments), arguments)
169
- })
170
-
171
- it("should return the same class reference", () => {
172
- class Test {}
173
- assert.strictEqual(identity(Test), Test)
174
- })
175
-
176
- it("should handle objects with custom valueOf or toString", () => {
177
- const obj = {
178
- valueOf: () => 10,
179
- toString: () => "custom",
180
- }
181
- assert.strictEqual(identity(obj), obj)
182
- })
183
-
184
- it("should return a promise reference without resolving it", () => {
185
- const promise = Promise.resolve(true)
186
- assert.strictEqual(identity(promise), promise)
187
- })
188
- })
189
- }
190
-
191
- testIdentity(identityStable)
192
- testIdentity(identityUnstable)