@@ -72,7 +72,7 @@ At this step, we need to create our `mapping` against our data `source`.
72
72
73
73
We will be using ` dot notation ` to create our ` final structure ` .
74
74
75
- > For more info about ` dot notation ` API, check out the [ documentation] ( https://github.com/arg-def/mapper-js )
75
+ > For more info about ` dot notation ` API, check out the [ documentation] ( https://github.com/the-cookbook/dot-notation )
76
76
77
77
With ` mapper ` , it is possible to ` get ` _ one_ or _ several_ values from our ` source `
78
78
and even ` transform ` it in the way we need.
@@ -89,11 +89,11 @@ the selected values as array in the `parameter`.
89
89
Now let's create our ` mapping ` !
90
90
91
91
``` js
92
- import mapper from ' @arg-def /mapper-js' ;
92
+ import mapper from ' @cookbook /mapper-js' ;
93
93
94
94
...
95
95
96
- const mapping = mapper . mapping ((map ) => ({
96
+ const mapping = mapper ((map ) => ({
97
97
' person.name' : map (' person.name' )
98
98
.transform (({ firstName, lastName }) => ` ${ firstName} ${ lastName} ` )
99
99
.value ,
@@ -110,10 +110,10 @@ const mapping = mapper.mapping((map) => ({
110
110
### 3) Create your mapped object
111
111
112
112
``` js
113
- import mapper from ' @arg-def /mapper-js' ;
113
+ import mapper from ' @cookbook /mapper-js' ;
114
114
...
115
115
116
- const result = mapper (source, mapping );
116
+ const result = mapping (source);
117
117
/* outputs
118
118
{
119
119
person: {
@@ -147,18 +147,42 @@ const result = mapper(source, mapping);
147
147
## mapper
148
148
149
149
** Type:** ` function() `
150
- ** Parameter:** ` source: object, mapping: IMapping, options?: IMapperOptions `
150
+ ** Parameter:** ` mapping: Mapping `
151
+ ** Return:** ` <T>(source: object | object[], options?: Options) => T extends [] ? T[] : T ` ,
152
+ ** Signature:** ` (mapping: Mapping) => <T>(source: object | object[], options?: Options) => T extends [] ? T[] : T `
151
153
152
- ** Description:**
153
154
154
- ` mapper() ` mappes your _ source data_ against your _ mapping_ .
155
+ ** Description:**
156
+
157
+ ` mapper() ` is the main method and responsible for mapping the _ values_ from your _ data source_ against the _ mapping instructions_ .
158
+ It accepts ` dot notation ` path(s) as ` key(s) ` .
159
+
160
+ Example:
161
+
162
+ ``` ts
163
+ // raw definition
164
+ const mapping = mapper ((map ) => ({
165
+ ...
166
+ }));
167
+
168
+ // with map() query
169
+ const mapping = mapper ((map ) => ({
170
+ ' employee.name' : map (' person.name.firstName' ).value ,
171
+ ' employee.age' : map (' person.name.age' ).value ,
172
+ ' employee.address' : map (' person.address' ).value ,
173
+ }));
174
+ ```
175
+
176
+ As a result from the above implementation, ` mapper() ` return a new ` function ` to map and compile your _ source data_ against your _ mapping_ .
155
177
156
178
It accepts an extra (_ optional_ ) argument defining the [ _ global mapping options_ ] ( #mapper-options ) .
157
179
158
180
Example:
159
181
160
182
``` ts
161
- mapper (source , mapping , options );
183
+ ...
184
+
185
+ mapping (source , options );
162
186
163
187
/* outputs
164
188
{
@@ -181,41 +205,13 @@ mapper(source, mapping, options);
181
205
```
182
206
___
183
207
184
- ## mapper.mapping
185
-
186
- ** Type** : ` function() `
187
- ** Parameter** : ` map `
188
- ** Signature:** ` (callback: IMapping): IMapping => callback; `
189
-
190
- ** Description:**
191
-
192
- ` mapper.mapping() ` is the method responsible for mapping the _ values_ from your _ source data_ against your _ object shape_ .
193
- It accepts ` dot notation ` path as ` key ` .
194
-
195
- Example:
196
- ``` ts
197
- // raw definition
198
- const mapping = mapper .mapping ((map ) => ({
199
- ...
200
- }));
201
-
202
- // with map() query
203
- const mapping = mapper .mapping ((map ) => ({
204
- ' employee.name' : map (' person.name.firstName' ).value ,
205
- ' employee.age' : map (' person.name.age' ).value ,
206
- ' employee.address' : map (' person.address' ).value ,
207
- }));
208
-
209
-
210
- ```
211
- ___
212
-
213
208
214
209
## map
215
210
216
211
** Type:** ` function `
217
- ** Parameter:** ` paths: string|string[], option?: IMapperOptions `
218
- ** Signature:** ` <T>(key: string | string[], options?: IMapperOptions) => IMapMethods<T>; `
212
+ ** Parameter:** ` keys: string | string[], options?: Options `
213
+ ** Return:** ` MapMethods<T> ` ,
214
+ ** Signature:** ` <T = unknown>(keys: string | string[], options?: Options) => MapMethods<T> `
219
215
220
216
** Description:**
221
217
@@ -235,7 +231,8 @@ map(['person.name.firstName', 'person.name.lastName'], options);
235
231
236
232
** Type:** ` function `
237
233
** Parameter:** ` ...unknown[] `
238
- ** Signature:** ` (callback: (...args: unknown[]) => T) => IMapMethods<T> `
234
+ ** Return:** ` unknown | unknown[] ` ,
235
+ ** Signature:** ` (...args: unknown[]) => unknown | unknown[] `
239
236
240
237
** Description:**
241
238
@@ -251,14 +248,14 @@ map('person.name.firstName')
251
248
252
249
// multiple values
253
250
map ([' person.name.firstName' , ' person.name.lastName' ])
254
- .transform ((firstName , lastName ) => ` ${firstName } ${lastName ] ` );
251
+ .transform ((firstName , lastName ) => ` ${firstName } ${lastName } ` );
255
252
```
256
253
257
254
258
255
#### ` value `
259
256
260
257
** Type:** ` readonly `
261
- ** Returns :** ` T `
258
+ ** Return :** ` T `
262
259
** Description:**
263
260
264
261
` .value ` returns the value of your ` dot notation ` query. If transformed, returns the transformed value.
@@ -272,7 +269,7 @@ map('person.name.firstName')
272
269
273
270
// multiple values
274
271
map ([' person.name.firstName' , ' person.name.lastName' ])
275
- .transform((firstName, lastName) => ` $ {firstName } $ {lastName] ` )
272
+ .transform ((firstName , lastName ) => ` ${firstName } ${lastName } ` )
276
273
.value ;
277
274
```
278
275
@@ -283,14 +280,14 @@ map(['person.name.firstName', 'person.name.lastName'])
283
280
284
281
``` js
285
282
{
286
- suppressNullUndefined : false,
287
- suppressionStrategy : () => false,
283
+ omitNullUndefined : false ,
284
+ omitStrategy : () => false ,
288
285
}
289
286
```
290
287
291
288
### Details
292
289
293
- **` suppressNullUndefined ` **
290
+ ** ` omitNullUndefined ` **
294
291
295
292
** Type:** ` boolean `
296
293
** default value:** ` false `
@@ -300,6 +297,7 @@ map(['person.name.firstName', 'person.name.lastName'])
300
297
Removes ` null ` or ` undefined ` entries from the _ mapped_ object.
301
298
302
299
Example:
300
+
303
301
``` ts
304
302
/* source object
305
303
{
@@ -310,15 +308,15 @@ Example:
310
308
},
311
309
}
312
310
*/
313
- const mapping = mapper.mapping ((map) => ({
311
+ const mapping = mapper ((map ) => ({
314
312
' name' : map (' person.name' ).value ,
315
313
' age' : map (' person.age' ).value ,
316
314
// source doesn't have property 'address',
317
315
// therefore will return "undefined"
318
316
' address' : map (' person.address' ).value ,
319
317
}));
320
318
321
- mapper (source, mapping, { suppressNullUndefined : true });
319
+ mapping (source , { omitNullUndefined : true });
322
320
/* outputs
323
321
{
324
322
name: 'John',
@@ -328,16 +326,16 @@ mapper(source, mapping, { suppressNullUndefined: true });
328
326
329
327
```
330
328
331
-
332
- ** ` suppressionStrategy ` **
329
+ ** ` omitStrategy ` **
333
330
334
331
** Type:** ` function `
335
- ** Parameter :** ` value: unknown `
336
- ** Signature :** ` (value: unknown) => boolean `
332
+ ** Parameter:** ` value: unknown | unknown[] `
333
+ ** Return:** ` boolean `
334
+ ** Signature:** ` (value: unknown | unknown[]) => boolean `
337
335
338
336
** Description:**
339
337
340
- Defines a _custom strategy_ to suppress entries from the _mapped object_ .
338
+ Defines a _ custom strategy_ to omit ( _ suppress _ ) entries from the _ mapped object_ .
341
339
342
340
Example:
343
341
``` tsx
@@ -358,15 +356,15 @@ Example:
358
356
}
359
357
*/
360
358
361
- const customSuppressionStrategy = (address: ISource ): boolean => address && address.city === 'Cupertino';
359
+ const customOmitStrategy = (address : Record < string , string > ): boolean => address && address .city === ' Cupertino' ;
362
360
363
- const mapping = mapper.mapping ((map) => ({
361
+ const mapping = mapper ((map ) => ({
364
362
' name' : map (' person.name' ).value ,
365
363
' age' : map (' person.age' ).value ,
366
364
' address' : map (' person.address' ).value ,
367
365
}));
368
366
369
- mapper (source, mapping, { suppressionStrategy: customSuppressionStrategy );
367
+ mapping (source , { omitStrategy: customOmitStrategy } );
370
368
/* outputs
371
369
{
372
370
name: 'John',
0 commit comments