{"id":25714102,"url":"https://github.com/diffcunha/object-dsl","last_synced_at":"2025-05-01T12:21:40.374Z","repository":{"id":57157864,"uuid":"86491327","full_name":"diffcunha/object-dsl","owner":"diffcunha","description":"µ functional library to transverse objects using a extendable DSL-like syntax","archived":false,"fork":false,"pushed_at":"2017-04-05T23:59:50.000Z","size":14,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-30T21:14:56.705Z","etag":null,"topics":["dsl","javascript","object","transformations","transverse-objects"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/diffcunha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-28T18:02:59.000Z","updated_at":"2019-04-08T21:50:09.000Z","dependencies_parsed_at":"2022-08-31T22:00:46.598Z","dependency_job_id":null,"html_url":"https://github.com/diffcunha/object-dsl","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diffcunha%2Fobject-dsl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diffcunha%2Fobject-dsl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diffcunha%2Fobject-dsl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diffcunha%2Fobject-dsl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/diffcunha","download_url":"https://codeload.github.com/diffcunha/object-dsl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251872375,"owners_count":21657633,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dsl","javascript","object","transformations","transverse-objects"],"created_at":"2025-02-25T12:33:48.312Z","updated_at":"2025-05-01T12:21:40.355Z","avatar_url":"https://github.com/diffcunha.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# object-dsl\nµ functional library to transverse objects using an extendable DSL-like syntax\n\n## Installation\n\n```shell\n$ npm i --save object-dsl\n```\n\n## Examples\n\n### Simple transformations\n\n```js\nimport compile from 'object-dsl'\n\n// Operators\nconst replace = text =\u003e next =\u003e node =\u003e node.replace('%placeholder%', text)\nconst toUpper = next =\u003e node =\u003e node.toUpperCase()\n\n// DSL spec\nconst dsl = {\n  foo: replace('world'),\n  obj: {\n    name: toUpper\n  }\n}\n\n// Compile DSL\nconst compiled = compile(dsl)\n\n// Run with object\nconst result = compiled({\n  foo: 'hello %placeholder%',\n  obj: {\n    name: 'foobar'\n  }\n})\n\nconsole.log(result) // { foo: 'hello world', obj: { name: 'FOOBAR' } }\n```\n\n### Composition\n\n```js\nimport compile from 'object-dsl'\n\n// Operators\nconst replace = text =\u003e next =\u003e node =\u003e node.replace('%placeholder%', text)\nconst toUpper = next =\u003e node =\u003e node.toUpperCase()\n\n// DSL spec\nconst obj = {\n  name: toUpper\n}\n\nconst dsl = {\n  foo: replace('world'),\n  obj\n}\n\n// Compile DSL\nconst compiled = compile(dsl)\n\n// Run with object\nconst result = compiled({\n  foo: 'hello %placeholder%',\n  obj: {\n    name: 'foobar'\n  }\n})\n\nconsole.log(result) // { foo: 'hello world', obj: { name: 'FOOBAR' } }\n```\n\n### `array` and `map` operators \n\n```js\nimport compile, { array, map } from 'object-dsl'\n\n// Operators\nconst replace = (placeholder, text) =\u003e next =\u003e node =\u003e node.replace(`%${placeholder}%`, text)\nconst photo = next =\u003e node =\u003e `http://image-server.com/files/${node}`\n\n// DSL spec\nconst dsl = {\n  names: (\n    array(\n      replace('title', 'Mr.')\n    )\n  ),\n  images: (\n    map(\n      photo\n    )\n  )\n}\n\n// Compile DSL\nconst compiled = compile(dsl)\n\n// Run with object\nconst result = compiled({\n  names: [\n    '%title% John Doe',\n    '%title% John Smith'\n  ],\n  images: {\n    cover: 'cover.png',\n    back: 'back.png',\n    other: 'other.png'\n  }\n})\n\nconsole.log(result)\n\n/*\n{\n  names: [\n    'Mr. John Doe',\n    'Mr. John Smith'\n  ],\n  images: {\n    cover: 'http://image-server.com/files/cover.png',\n    back: 'http://image-server.com/files/back.png',\n    other: 'http://image-server.com/files/other.png'\n  }\n }\n*/\n```\n\n### Passing state\n\n```js\nimport compile, { array, map } from 'object-dsl'\n\n// Operators\nconst item = next =\u003e (node, state) =\u003e ({ path: state.path })\n\n// DSL spec\nconst dsl = {\n  types: (\n    map(\n      array(\n        item\n      )\n    )\n  )\n}\n\n// Compile DSL\nconst reducer = (state, { key }) =\u003e ({ path: [...state.path, key] })\nconst initState = { path: ['root'] }\nconst compiled = compile(dsl, reducer, initState)\n\n// Run with object\nconst obj = {\n  types: {\n    type1: [\n      { id: 'type1_1' },\n      { id: 'type1_2' }\n    ],\n    type2: [\n      { id: 'type2_1' }\n    ]\n  }\n}\n\nconst result = compiled(obj)\nconsole.log(result)\n\n/*\n{\n  types: {\n    type1: [\n      { path: [\"root\", \"types\", \"type1\", 0] },\n      { path: [\"root\", \"types\", \"type1\", 1] }\n    ],\n    type2: [\n      { path: [\"root\", \"types\", \"type2\", 0] }\n    ]\n  }\n}\n*/\n\n// ---------\n// withMerge\n// ---------\n\nimport { withMerge } from 'object-dsl'\n\n// Run with object\nconst result = withMerge(compiled)(obj)\nconsole.log(result)\n\n/*\n{\n  types: {\n    type1: [\n      { id: 'type1_1', path: [\"root\", \"types\", \"type1\", 0] },\n      { id: 'type1_2', path: [\"root\", \"types\", \"type1\", 1] }\n    ],\n    type2: [\n      { id: 'type2_1', path: [\"root\", \"types\", \"type2\", 0] }\n    ]\n  }\n}\n*/\n```\n\n## API\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiffcunha%2Fobject-dsl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiffcunha%2Fobject-dsl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiffcunha%2Fobject-dsl/lists"}