Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aaronhuggins/field-mapper
A field-mapping engine for managing field-to-property relationships and mapping objects.
https://github.com/aaronhuggins/field-mapper
Last synced: 9 days ago
JSON representation
A field-mapping engine for managing field-to-property relationships and mapping objects.
- Host: GitHub
- URL: https://github.com/aaronhuggins/field-mapper
- Owner: aaronhuggins
- Created: 2020-08-18T15:59:16.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-04-22T20:31:17.000Z (over 3 years ago)
- Last Synced: 2024-10-12T19:48:58.169Z (about 1 month ago)
- Language: TypeScript
- Homepage: https://ahuggins-nhs.github.io/field-mapper/
- Size: 272 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# field-mapper
A field-mapping engine for managing field-to-property relationships and mapping objects. Provides a simple dictionary based on `Map` to take an array of field-map-like objects, and supports output of modified field-maps as an Azure-like table row. Full support for Typescript included.
## Usage
Install via [NPM](https://www.npmjs.com/package/field-mapper) and require in your project. There is also an ESM export, for use with browser or Deno.
```js
const { FieldMapper } = require('field-mapper')
const fieldData = [{ fieldName: 'foo', propertyName: 'bar', objectName: 'FooBar' }]
const myMapper = new FieldMapper(fieldData)
const unmappedObj = { foo: 'hello, world!' }
const mappedObj = Object.create(null)for (const [key, value] of Object.entries(unmappedObj)) {
mappedObj[myMapper.getObjectMap('FooBar').getPropertyName(key)] = value
}console.log(mappedObj.bar) // Expected output: hello, world!
```