@@ -56,12 +56,11 @@ function lowerCamelCase(name: string) {
56
56
57
57
/**
58
58
* 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.
61
60
* @param obj object to traverse
62
61
* @param fn function to apply
63
62
*/
64
- export function morph (
63
+ function morph (
65
64
obj : any ,
66
65
fn : ( key : string , value : any ) => { key : string ; value : any }
67
66
) : any {
@@ -87,7 +86,8 @@ export function morph(
87
86
}
88
87
89
88
/**
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:
91
91
* - removes 'praw_' prefix from keys
92
92
* - lower first letter of keys
93
93
* - replaces empty strings with `undefined`
@@ -96,6 +96,14 @@ export function morph(
96
96
* prefix was initial partial implementation. This is inconsistent approach and
97
97
* thus marked as deprecated, left only for compatibility with legacy code.
98
98
*
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
+ *
99
107
* @param obj object to normalize
100
108
* @deprecated
101
109
*/
@@ -109,6 +117,22 @@ export function legacy(obj: any) {
109
117
}
110
118
111
119
/**
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
+ *
112
136
* @param obj object to normalize
113
137
* @beta
114
138
*/
0 commit comments