{"id":16189310,"url":"https://github.com/caolan/pithy2","last_synced_at":"2025-03-19T03:30:52.109Z","repository":{"id":57324951,"uuid":"194121855","full_name":"caolan/pithy2","owner":"caolan","description":"A Typescript-friendly and human-friendly API for building DOM elements","archived":false,"fork":false,"pushed_at":"2019-07-01T13:55:26.000Z","size":9,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T09:02:34.775Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/caolan.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":"2019-06-27T15:38:52.000Z","updated_at":"2025-01-22T00:08:21.000Z","dependencies_parsed_at":"2022-09-06T06:41:23.878Z","dependency_job_id":null,"html_url":"https://github.com/caolan/pithy2","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/caolan%2Fpithy2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caolan%2Fpithy2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caolan%2Fpithy2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caolan%2Fpithy2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caolan","download_url":"https://codeload.github.com/caolan/pithy2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243847056,"owners_count":20357317,"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-10T07:35:01.191Z","updated_at":"2025-03-19T03:30:51.839Z","avatar_url":"https://github.com/caolan.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pithy 2\n\nA less painful API for generating raw DOM Elements - inspired by\n[pithy](https://github.com/caolan/pithy).\n\nIntegrates well with Typescript - checks you're setting acceptable\nproperty values for the given tag etc.\n\n## Installation\n\n```\nnpm install pithy2\n```\n\n## Usage\n\n``` javascript\nimport * as html from \"pithy2\";\n\n// Empty element.\nhtml.div();\n\n// Element with children.\nhtml.a(['click me']);\n\n// Element with custom properties.\nhtml.a({href: '#'});\n\n// Element with custom properties and children.\nhtml.a({href: '#'}, ['click me']);\n\n// Custom tagName or an element not otherwise supported by this library.\n// Props and children are optional and in the same combinations as above.\n// Typescript will still check valid tag properties when created via this API.\nhtml.makeElement('my-custom-tag', props, children);\n\n// Property names map to JS properties instead of HTML attribute names.\nhtml.span({className: 'example'});\n\n// Style properties can be set in the same way.\nhtml.span({style: {color: 'red'}});\n\n// Children can be either elements or strings.\n// Strings will be safely converted to TextNodes.\nhtml.p([\"Hello, \", html.strong(\"world\"), \"!\"]);\n\n// Normally, you can't directly set the classList property to an array,\n// but this library has a special case to handle it.\nhtml.div({classList: ['one', 'two']});\n\n// Adding event listeners.\nfunction doStuff() {\n    alert('clicked');\n}\nhtml.button({events: {click: doStuff}}, ['click me']);\n\n// For references to nested children you can use normal assignment.\nclass MyComponent {\n    updateName() {\n        this.message.textContent = `Hello, ${this.input.value}!`;\n    }\n    render() {\n        return html.div({id: 'example'}, [\n            this.message = html.span([`Hello, world!`]),\n            this.input = html.input({events: {input: () =\u003e this.updateName()}})\n        ]);\n    }\n}\n```\n\n## Typescript\n\n``` typescript\n// This will produce a type error because div has no 'src' attribute.\nhtml.div({src: 'http://example.com'});\n\n// This will produce a type error because className must be a string.\nhtml.h1({className: 123});\n\n// This will produce a type error because movementX is a property on a\n// MouseEvent and keyup produces a KeyboardEvent.\nhtml.input({\n    events: {\n        keyup: (ev) =\u003e {\n            console.log(ev.movementX)\n        }\n    }\n});\n```\n\n## Example\n\n### Before\n\n``` javascript\nfunction makeSection() {\n    const section = document.createElement('section');\n    section.id = 'mySection';\n\n    const h2 = document.createElement('h2');\n    h2.classList.add('extra');\n    h2.classList.add('special');\n    h2.textContent = 'Example';\n\n    const p = document.createElement('p');\n    p.textContent = 'Hello, world!';\n\n    const hr = document.createElement('hr');\n\n    section.appendChild(h1);\n    section.appendChild(p);\n    section.appendChild(hr);\n\n    return section;\n}\n```\n\n### After\n\n``` javascript\nimport * as html from \"pithy2\";\n\nfunction makeSection() {\n    return html.section({id: 'mySection'}, [\n        html.h2({classList: ['extra', 'special']}, [\n            'Example'\n        ]),\n        html.p(['Hello, world!']),\n        html.hr()\n    ]);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaolan%2Fpithy2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaolan%2Fpithy2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaolan%2Fpithy2/lists"}