https://github.com/gsuuon/simple-object-translation
Generate translator functions from an object map
https://github.com/gsuuon/simple-object-translation
object-mapping object-to-object translator
Last synced: 3 months ago
JSON representation
Generate translator functions from an object map
- Host: GitHub
- URL: https://github.com/gsuuon/simple-object-translation
- Owner: gsuuon
- Created: 2019-04-04T03:54:35.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2023-01-07T07:27:42.000Z (over 3 years ago)
- Last Synced: 2025-10-24T03:32:04.464Z (6 months ago)
- Topics: object-mapping, object-to-object, translator
- Language: JavaScript
- Size: 612 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# simple-object-translation
`parseTranslationMap` builds two translator functions from an object map. The first function takes an object from the shape implied by the map's paths to the map structure, and the second from the map structure to the implied object shape.
```js
import { parseTranslationMap } from 'simple-object-translation'
const foosToXsTranslationMap = {
foo: 'x',
bar: 'y.y',
baz: 'y.z'
}
const [toFoos, toXs] = parseTranslationMap(foosToXsTranslationMap)
const foos = {
foo: 'foo',
bar: 'bar',
baz: 'baz',
}
const xs = {
x: 'x',
y: {
y: 'y',
z: 'z'
}
}
expect(toFoos(xs)).toEqual({
foo: 'x',
bar: 'y',
baz: 'z'
})
expect(toXs(foos)).toEqual({
x: 'foo',
y: {
y: 'bar',
z: 'baz'
}
})
```
Blazingly small ~1kb unzipped (but slower than just writing these functions out)