Skip to content

Commit

Permalink
✨ Add identity function
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMiyauci committed Apr 19, 2021
1 parent 78254b4 commit 6c57821
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/api/identity/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->



## identity variable

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
Return the parameter supplied to it.

<b>Signature:</b>

```typescript
identity: <T>(val: T) => T
```

## Example


```ts
identity(1) // 1
identity({}) // {}

```

1 change: 1 addition & 0 deletions docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
| [gte](./gte/) | Returns <code>true</code> if the first argument is greater than or equal to the second; otherwise <code>false</code> |
| [has](./has/) | <b><i>(BETA)</i></b> Returns whether or not an object has an own property with the specified name. |
| [hasPath](./haspath/) | <b><i>(BETA)</i></b> Returns whether or not a path exists in an object. Only the object's own properties are checked. |
| [identity](./identity/) | <b><i>(BETA)</i></b> Return the parameter supplied to it. |
| [inc](./inc/) | Increments its argument. |
| [isBigint](./isbigint/) | Whatever argument is type of <code>bigint</code> or not. |
| [isBoolean](./isboolean/) | Whatever argument is type of <code>boolean</code> or not. |
Expand Down
17 changes: 17 additions & 0 deletions src/identity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Return the parameter supplied to it.
*
* @param val - The value to return
* @returns The result of `val`
*
* @example
* ```ts
* identity(1) // 1
* identity({}) // {}
* ```
*
* @beta
*/
const identity = <T>(val: T): T => val

export { identity }
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export { gt } from '@/gt'
export { gte } from '@/gte'
export { has } from '@/has'
export { hasPath } from '@/hasPath'
export { identity } from '@/identity'
export { inc } from '@/inc'
export { isBigint } from '@/isBigint'
export { isBoolean } from '@/isBoolean'
Expand Down
16 changes: 16 additions & 0 deletions test/identity.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { identity } from '@/identity'

describe('identity', () => {
const table: [unknown, unknown][] = [
['', ''],
[0, 0],
[1n, 1n],
[() => 1, () => 1],
[{}, {}],
[[], []]
]

it.each(table)('identity(%s) -> %s', (val) => {
expect(identity(val)).toEqual(val)
})
})

0 comments on commit 6c57821

Please sign in to comment.