{"id":28461204,"url":"https://github.com/cryptpad/hyperjson","last_synced_at":"2025-07-20T22:07:32.049Z","repository":{"id":57269999,"uuid":"51449150","full_name":"cryptpad/hyperjson","owner":"cryptpad","description":"An abstract datatype compatible with the hyperscript API","archived":false,"fork":false,"pushed_at":"2024-02-14T14:20:31.000Z","size":34,"stargazers_count":3,"open_issues_count":2,"forks_count":3,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-07-08T07:44:20.818Z","etag":null,"topics":["cryptpad"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cryptpad.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2016-02-10T15:19:08.000Z","updated_at":"2024-05-21T13:46:52.000Z","dependencies_parsed_at":"2024-03-01T15:47:18.939Z","dependency_job_id":null,"html_url":"https://github.com/cryptpad/hyperjson","commit_stats":null,"previous_names":["xwiki-labs/hyperjson"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/cryptpad/hyperjson","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cryptpad%2Fhyperjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cryptpad%2Fhyperjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cryptpad%2Fhyperjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cryptpad%2Fhyperjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cryptpad","download_url":"https://codeload.github.com/cryptpad/hyperjson/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cryptpad%2Fhyperjson/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265567909,"owners_count":23789564,"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":["cryptpad"],"created_at":"2025-06-07T03:07:54.971Z","updated_at":"2025-07-20T22:07:32.043Z","avatar_url":"https://github.com/cryptpad.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hyperjson\n\nAn abstract datatype compatible with the [hyperscript](https://github.com/dominictarr/hyperscript \"Hyperscript on github\") API.\n\n## What's _hyperscript_?\n\nHyperscript is everything you need to know about a dom element to be able to recreate it.\nInstead of writing `\u003ch1\u003eHello!\u003c/h1\u003e` you write `h('h1', 'Hello!')`.\n\nHyperscript works clientside and serverside, and there are now several other projects adhering to the same API.\n\n## What's _hyperjson_?\n\nHyperjson is an abstraction of the data component (the arguments passed to the `h` function) from the function itself.\nIt is intended to be used clientside.\n\nIt provides two functions:\n\n### `fromDOM(domElement[, predicate, filter])`\n\nAccepts any DOM element and returns JSON (HyperJSON) representing all the relevant attributes of that DOM element and its children.\n\n`fromDOM` accepts two optional arguments, both of which are functions:\n\n#### predicate(DOMElement)\n\nIf you provide this function, `fromDOM` will call it for every element which it will attempt to serialize.\nIf the predicate returns a truthy value, it will proceed to serialize it and its children.\nIf the predicate returns a falsey value, it will terminate.\n\n```\nvar hj = Hyperjson.fromDOM(document.body, function (el) {\n    // suppose you don't want to serialize h4 elements or their children\n    return el.tagName !== 'H4';\n});\n```\n\n#### filter(hyperjson)\n\nAfter having serialized the tree, but before returning the results, `fromDOM` will run the contents through `filter`.\nAt this point, you are free to modify the hyperjson in any way, adding/removing/modifying elements as necessary for your purposes.\n\nAnything that you don't want serialized should be filtered here.\n\n```\nvar hj = Hyperjson.fromDOM(document.body, null, function (h) {\n    // suppose you want to serialize 'STRIKE' as 'S' elements\n    if (h[0] === 'STRIKE') {\n        // this will replace \u003cSTRIKE\u003e recursively\n        h[0] === 'S';\n    }\n    return h;\n});\n```\n\n### `callOn(hyperJSON, callback)`\n\nAccepts valid hyperjson and a callback which adheres to the Hyperscript API:\n\n```\nfunction myCallback (tagType, attributes, children) {\n    /* your code here */\n};\n```\n\nThe most prominent examples of callbacks are [hyperscript](https://github.com/dominictarr/hyperscript) and [virtual-hyperscript](https://github.com/Matt-Esch/virtual-dom), which produce DOM elements or virtual-DOM elements, respectively.\n\nYou can create custom plugins for filtering or modifying elements, or for producing alternative data structures that adhere to a similar structure.\n\n## License\n\nThis library is currently licensed as LGPL-2.1. Previous versions of this library (v1.4.0 and below) were licensed as AGPL-3.0.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcryptpad%2Fhyperjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcryptpad%2Fhyperjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcryptpad%2Fhyperjson/lists"}