Skip to content

Commit 7eb6a7e

Browse files
authored
feat: logFn (#308)
* feat: logFn * chore: jsdoc explanation
1 parent 7126aa7 commit 7eb6a7e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ export * from './nodash';
1414
export * from './collections';
1515
export * from './throttledPromiseAll';
1616
export * from './settleAll';
17+
export { logFn } from './log';

src/log.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2023, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
/**
9+
* A wrapper for console.log that returns the input value unmodified
10+
*
11+
* ``` ts
12+
* // peek inside a chain of map functions
13+
* [1,2,3,4,5].map(logFn).map(yourNextFunction)
14+
*
15+
* // wrap a returned function call to see what it returns
16+
* return logFn(otherFunction())
17+
* ```
18+
*/
19+
export const logFn = <T>(x: T): T => {
20+
// eslint-disable-next-line no-console
21+
console.log(typeof x === 'object' ? JSON.stringify(x, null, 2) : x);
22+
return x;
23+
};

0 commit comments

Comments
 (0)