{"id":17419844,"url":"https://github.com/bendrucker/obstruction","last_synced_at":"2025-09-11T12:36:09.166Z","repository":{"id":33378061,"uuid":"37022989","full_name":"bendrucker/obstruction","owner":"bendrucker","description":"Declarative parser for remapping object schemas and data","archived":false,"fork":false,"pushed_at":"2022-12-19T18:49:33.000Z","size":23,"stargazers_count":14,"open_issues_count":3,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-11T10:04:18.682Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bendrucker.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":"2015-06-07T16:14:48.000Z","updated_at":"2024-12-28T11:19:33.000Z","dependencies_parsed_at":"2023-01-15T00:39:53.248Z","dependency_job_id":null,"html_url":"https://github.com/bendrucker/obstruction","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/bendrucker/obstruction","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendrucker%2Fobstruction","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendrucker%2Fobstruction/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendrucker%2Fobstruction/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendrucker%2Fobstruction/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bendrucker","download_url":"https://codeload.github.com/bendrucker/obstruction/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendrucker%2Fobstruction/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260194701,"owners_count":22972638,"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":[],"created_at":"2024-10-17T02:34:20.007Z","updated_at":"2025-06-16T16:10:26.300Z","avatar_url":"https://github.com/bendrucker.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# obstruction [![Build Status](https://travis-ci.org/bendrucker/obstruction.svg?branch=master)](https://travis-ci.org/bendrucker/obstruction) [![Greenkeeper badge](https://badges.greenkeeper.io/bendrucker/obstruction.svg)](https://greenkeeper.io/)\n\n\u003e Declarative parser for remapping object schemas and data\n\n## Install\n\n```\n$ npm install --save obstruction\n```\n\n\n## Usage\n\n```js\nvar Obstruct = require('obstruction')\nvar parse = Obstruct({\n  title: 'name',\n  description: true,\n  author: 'author.login'\n})\nparse({\n  name: 'obstruction',\n  description: 'Object restructuring and parsing',\n  author: {\n    login: 'bendrucker'\n  }\n})\n```\n\nReturns:\n\n```js\n{\n  title: 'obstruction',\n  description: 'Object restructuring and parsing',\n  author: 'bendrucker'\n}\n```\n\n## API\n\n#### `Obstruct(schema, [object])` -\u003e `function` / `object`\n\nIf only a schema is passed, a function with the `schema` partially applied will be returned. You can call that function with your `object`.\n\n##### schema\n\n*Required*  \nType: `object`\n\nA schema object. See the [schema definition options](#schema-definition) for more details.\n\n##### object\n\nType: `object`  \n\nThe object to parse. If omitted, a partially applied function will be returned instead.\n\n#### `Obstruct.array(schema)` -\u003e `function`\n\nA convenience function for easily mapping arrays over a schema.\n\n##### schema\n\n*Required*  \nType: `object` / `function`\n\nThe schema used to map array items. This can be a plain object (which will be passed to `Obstruct`) or the result of calling `Obstruct(schema)` earlier. It can also any generic function for mapping values. The following are equivalent:\n\nWithout `Obstruct.array`:\n\n```js\nvar parseState = Obstruct({\n  abbrevation: 'abbrev'\n})\nObstruct({\n  states: function (states) {\n    return states.map(function (state) {\n      return parseState(state)\n    })\n  }\n})\n```\n\nWith `Obstruct.array`:\n\n```js\nObstruct({\n  states: Obstruct.array({\n    abbreviation: 'abbrev'\n  })\n})\n```\n\n#### `Obstruct.optional(schema)` -\u003e `function`\n\nA convenience function for easily mapping arrays over a schema.\n\n##### schema\n\n*Required*  \nType: `object` / `function`\n\nThe schema used to parse the value, if defined (not `undefined` or `null`). This can be a plain object (which will be passed to `Obstruct`) or the result of calling `Obstruct(schema)` earlier. It can also any generic function for transforming values.\n\nIf the source value is undefined, Obstruct will immediately return `undefined` without calling your `schema`. This allows you to cleanly handle cases where a missing value might throw.\n\n#### `Obstruct.parent(schema)` -\u003e `function`\n\nA convenience function for nested parent data within your output object.\n\n##### schema\n\n*Required*  \nType: `object` / `function`\n\nThe schema used to parse the parent object rather than the value at the specified key.\n\n## Schema Definitions\n\nA schema object represents the target object structure after parsing. You can nest schema objects to re-map nested objects. Schema nodes (the values in the schema object) control what value ultimately appears at a particular keypath in the final object.\n\nSchema nodes can be:\n\n#### `true`\n\nThe value will be copied directly from the source object:\n\n```js\nObstruct({foo: true})({foo: 'bar'})\n// =\u003e {foo: 'bar'}\n```\n\n#### a string\n\nThe value will be copied from the source object using the supplied string as the source key:\n\n```js\nObstruct({foo: 'bar'})({foo: 'bar', bar: 'baz'})\n// =\u003e {foo: 'baz'}\n```\n\nStrings can also use dot syntax to access deep properties:\n\n```js\nObstruct({foo: 'a.bar'})({a: {bar: 'baz'}})\n// =\u003e {foo: 'baz'}\n```\n\n#### a function\n\nThe value from the source object will be passed through the supplied function:\n\n```js\nfunction uppercase (string) {\n  return string.toUpperCase()\n}\nObstruct({foo: uppercase})({foo: 'bar'})\n// =\u003e {foo: 'BAR'}\n```\n\nThe function also receives the original object and the source key as additional arguments.\n\n#### an object\n\n`Obstruct` is called with the object and the source value at that keypath.\n\n```js\nObstruct({foo: {bar: uppercase}})({foo: {bar: 'baz'}})\n// =\u003e {foo: {bar: 'BAZ'}}\n```\n\n#### an array\n\nSchema nodes can be an array where:\n\n* the first value is the source key to use (dot syntax is supported)\n* the second value is any other valid schema node value (`true`, string, function, object)\n\n```js\nObstruct({a: ['foo', uppercase]})({foo: 'bar'})\n// =\u003e {a: 'BAR'}\nObstruct({b: ['foo.bar', uppercase]})({foo: {bar: 'baz'}})\n// =\u003e {b: 'BAZ'}\nObstruct({c: ['foo', {bar: uppercase}]})({foo: {bar: 'baz'}})\n// =\u003e {c: {bar: 'BAZ'}}\n```\n\n## License\n\nMIT © [Ben Drucker](http://bendrucker.me)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbendrucker%2Fobstruction","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbendrucker%2Fobstruction","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbendrucker%2Fobstruction/lists"}