{"id":15658759,"url":"https://github.com/drom/onml","last_synced_at":"2025-04-14T10:33:20.377Z","repository":{"id":57314808,"uuid":"45149293","full_name":"drom/onml","owner":"drom","description":"Object Notation for Markup Language","archived":false,"fork":false,"pushed_at":"2023-01-06T06:31:51.000Z","size":41,"stargazers_count":23,"open_issues_count":3,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-27T23:41:52.685Z","etag":null,"topics":["hacktoberfest"],"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/drom.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-10-29T00:06:02.000Z","updated_at":"2025-03-18T16:54:21.000Z","dependencies_parsed_at":"2023-02-05T13:16:45.447Z","dependency_job_id":null,"html_url":"https://github.com/drom/onml","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/drom%2Fonml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drom%2Fonml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drom%2Fonml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drom%2Fonml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drom","download_url":"https://codeload.github.com/drom/onml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248862863,"owners_count":21173897,"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":["hacktoberfest"],"created_at":"2024-10-03T13:13:54.255Z","updated_at":"2025-04-14T10:33:20.359Z","avatar_url":"https://github.com/drom.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ONML\n\n[![NPM version](https://img.shields.io/npm/v/onml.svg)](https://www.npmjs.org/package/onml)\n[![Actions Status](https://github.com/drom/onml/workflows/Tests/badge.svg)](https://github.com/drom/onml/actions)\n\n[jsonml.org](http://www.jsonml.org/) compatible tool set.\n\n## Use\n### Node.js\n\n```\nnpm i onml --save\n```\n\n```js\nvar onml = require('onml');\n```\n\n## API\n### onml.parse() --- onml.p()\nThe `onml.parse()` method parses a XML/HTML/SVG string and returns a JavaScript value.\n\n```js\nvar obj = onml.parse('\u003ctext a=\"5\"\u003eso me\u003c/text\u003e');\nconsole.log(obj);\n--\u003e\n[\"text\", {a: \"5\"}, \"so me\"]\n```\n\n### onml.stringify() --- onml.s()\nThe `onml.stringify(array, [indentation])` method converts a JavaScript value to a XML/HTML/SVG string.\n\n```js\nvar str = onml.stringify(['text', {a: 55}, 'so me'], 2);\nconsole.log(str);\n--\u003e\n\u003ctext a=\"55\"\u003e\n  so me\n\u003c/text\u003e\n```\n\n### onml.traverse() --- onml.t()\nJSONML object traversal tool. See [test/traverse.js](test/traverse.js) for more details.\n\n```js\nonml.traverse(obj, {\n    enter: function (node, parent) {\n        ...\n    },\n    leave: function (node, parent) {\n        ...\n    }\n});\n```\nInside `enter` and `leave` functions:\n\n`node` and `parent` objects have the following attributes:\n  * `.name` -- tag name\n  * `.attr` -- attributes object\n  * `.full` -- full node array\n\n`this` will hold additional methods:\n  * `this.name(string)` -- to change the node tag\n  * `this.skip()` -- to skip subtree based on the current node\n  * `this.remove()` -- to remove current node\n  * `this.replace(array)` -- to replace current node\n\n```js\n// count divs on enter\nvar count = 0;\nonml.traverse(\n    ['b',\n        ['div', {a: true},\n            ['span',\n                'div',\n                ['div',\n                    ['div', {},\n                        ['div', {a: true}]\n                    ]\n                ],\n                ['div', {},\n                    ['div']\n                ]\n            ]\n        ]\n    ],\n    {\n        enter: function (node) {\n            if (node.name === 'div') {\n                count++;\n            }\n        }\n    }\n);\nconsole.log(count);\n--\u003e\n6\n```\n\n## Testing\n`npm test`\n\n## License\nMIT [LICENSE](https://github.com/drom/onml/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrom%2Fonml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrom%2Fonml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrom%2Fonml/lists"}