Skip to content

Commit 278b0fd

Browse files
committed
docs
1 parent fa5386b commit 278b0fd

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/normalize.ts

+28-4
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,11 @@ function lowerCamelCase(name: string) {
5656

5757
/**
5858
* Traverse object recursively and apply provided function `fn` to each
59-
* key-value pair. Function can modify key and value or return the same. Object
60-
* is mutated in place.
59+
* key-value pair. Returns new object.
6160
* @param obj object to traverse
6261
* @param fn function to apply
6362
*/
64-
export function morph(
63+
function morph(
6564
obj: any,
6665
fn: (key: string, value: any) => { key: string; value: any }
6766
): any {
@@ -87,7 +86,8 @@ export function morph(
8786
}
8887

8988
/**
90-
* Provides compatibility with legacy version of the API. This function:
89+
* Transforms object parsed from raw API response to format compatible with
90+
* earlier versions of the API. This function:
9191
* - removes 'praw_' prefix from keys
9292
* - lower first letter of keys
9393
* - replaces empty strings with `undefined`
@@ -96,6 +96,14 @@ export function morph(
9696
* prefix was initial partial implementation. This is inconsistent approach and
9797
* thus marked as deprecated, left only for compatibility with legacy code.
9898
*
99+
* @example
100+
* ```js
101+
* import Bir from 'bir1'
102+
* import { legacy } from 'bir1/normalize'
103+
* const bir = new Bir({normalizeFn: legacy})
104+
* const result = await bir.search('010058960')
105+
* ```
106+
*
99107
* @param obj object to normalize
100108
* @deprecated
101109
*/
@@ -109,6 +117,22 @@ export function legacy(obj: any) {
109117
}
110118

111119
/**
120+
* Transforms object parsed from raw API response to convenient format commonly
121+
* used in modern JavaScript applications. This is subjective and opinionated.
122+
* This function:
123+
* - remove prefixes from keys
124+
* - lower camel case keys
125+
* - unifies some keys (e.g. `regon9` -> `regon`)
126+
* - replaces empty strings with `undefined`
127+
*
128+
* @example
129+
* ```js
130+
* import Bir from 'bir1'
131+
* import { modern } from 'bir1/normalize'
132+
* const bir = new Bir({normalizeFn: modern})
133+
* const result = await bir.search('010058960')
134+
* ```
135+
*
112136
* @param obj object to normalize
113137
* @beta
114138
*/

0 commit comments

Comments
 (0)