Created
March 10, 2020 18:30
-
-
Save leandrojo/ae125c031a99b4c33b336eb4156341a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function translate(document: any) { | |
| if (typeof document !== 'object') return {}; | |
| return ({ raw, ...dictionary }: { raw: string[] }) => { | |
| if (Array.isArray(document)) { | |
| // @ts-ignore | |
| return document.map((v: {}) => translate(v)({ raw, ...dictionary })); | |
| } | |
| if (raw !== undefined) { | |
| // @ts-ignore | |
| const arr = raw | |
| .find((v: string) => (typeof v === 'string' ? v : '')) | |
| .split(';') | |
| .map((param) => param | |
| .split(':') | |
| .map((v) => v.trim())) | |
| .filter(([v]) => v); | |
| // @ts-ignore | |
| return arr.reduce((before, [from, to]) => ({ ...before, [to]: document[from] }), {}); | |
| } | |
| return {}; | |
| }; | |
| } | |
| export default translate; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment