@ngha/transform-object
v0.2.5
Published
New object is transformed by object pattern
Downloads
39
Maintainers
Readme
transform object
This library transform a new object from an object pattern
Usage
Import TransformObjectModule
to your module
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app';
import { TransformObjectModule } from '@ngha/transform-object'
@NgModule({
imports: [TransformObjectModule],
})
export class AppModule {}
dataProvider = [
{
'id': '005564a8-2b3d-4f87-9e19-290526ac5e26',
'username': '[email protected]',
'emailAddress': '[email protected]',
'fullName': 'John',
'status': 'ACTIVE',
'roleId': '09323760-ba53-42e2-a961-840c75726f93',
'role': {
'id': '09323760-ba53-42e2-a961-840c75726f93',
'code': 'USER'
},
'createdDate': '2020-09-07T03:01:15.587Z'
},
{
'id': '91458c99-271b-408d-b0bc-9e23384e5c5f',
'username': '[email protected]',
'emailAddress': '[email protected]',
'fullName': 'test2',
'status': 'PENDING',
'roleId': 'f34ebf72-f55d-4ad4-b7ea-72f2711bf7f8',
'role': {
'id': 'f34ebf72-f55d-4ad4-b7ea-72f2711bf7f8',
'code': 'PARTNER'
},
'createdDate': '2020-09-01T08:27:47.237Z'
},
{
'id': '13d8b6a7-d7da-49b0-8a98-0bad8e6117cc',
'username': '[email protected]',
'emailAddress': '[email protected]',
'fullName': 'test111',
'status': 'PENDING',
'roleId': '09323760-ba53-42e2-a961-840c75726f93',
'role': {
'id': '09323760-ba53-42e2-a961-840c75726f93',
'code': 'USER'
},
'createdDate': '2020-09-01T08:27:04.553Z'
}
];
objectPattern = {
index: 'id',
name: 'fullName',
title: 'role.code'
}
transform-object
Transform object to new object
Usage: object | transformObject: objectPattern
<pre>
{{dataProvider[0] | transformObject: objectPattern}}
</pre>
<!-- Output:
{
"index": "005564a8-2b3d-4f87-9e19-290526ac5e26",
"name": "John",
"title": "USER"
}
-->
transform-objects
Transform array object to new array object
Usage: object | transformObject: objectPattern
<pre *ngFor="let item of dataProvider | transformObjects: objectPattern">
{{item | json}}
</pre>
<!-- Output:
{
"index": "005564a8-2b3d-4f87-9e19-290526ac5e26",
"name": "John",
"title": "USER"
}
{
"index": "91458c99-271b-408d-b0bc-9e23384e5c5f",
"name": "test2",
"title": "PARTNER"
}
{
"index": "13d8b6a7-d7da-49b0-8a98-0bad8e6117cc",
"name": "test111",
"title": "USER"
}
-->
transform-objects with default value
Transform array object to new array object with default value
Usage: object | transformObject: objectPattern : objectDefault
objectPattern = {
index: 'id',
name: 'fullName',
password: 'defaultPassword',
title: 'role.code'
};
objectDefault = { password: '****' };
<pre *ngFor="let item of dataProvider | transformObjects: objectPattern : objectDefault">
{{item | json}}
</pre>
<!-- Output:
{
"index": "005564a8-2b3d-4f87-9e19-290526ac5e26",
"name": "John",
"password": "****",
"title": "USER"
}
{
"index": "91458c99-271b-408d-b0bc-9e23384e5c5f",
"name": "test2",
"password": "****",
"title": "PARTNER"
}
{
"index": "13d8b6a7-d7da-49b0-8a98-0bad8e6117cc",
"name": "test111",
"password": "****",
"title": "USER"
}
-->