{"id":16189284,"url":"https://github.com/caolan/pithy","last_synced_at":"2025-04-06T23:17:02.199Z","repository":{"id":7699387,"uuid":"9063745","full_name":"caolan/pithy","owner":"caolan","description":"An internal DSL for generating HTML in JavaScript","archived":false,"fork":false,"pushed_at":"2016-07-19T19:14:26.000Z","size":137,"stargazers_count":436,"open_issues_count":4,"forks_count":22,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-30T21:10:00.548Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/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":"2013-03-27T21:11:25.000Z","updated_at":"2025-02-21T11:30:42.000Z","dependencies_parsed_at":"2022-09-06T21:11:03.395Z","dependency_job_id":null,"html_url":"https://github.com/caolan/pithy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caolan%2Fpithy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caolan%2Fpithy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caolan%2Fpithy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caolan%2Fpithy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caolan","download_url":"https://codeload.github.com/caolan/pithy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247563936,"owners_count":20958971,"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:34:49.929Z","updated_at":"2025-04-06T23:17:02.169Z","avatar_url":"https://github.com/caolan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pithy.js\n\nAn internal DSL for generating HTML in JavaScript.\n\n\n## Examples\n\n#### Basic elements\n\n```javascript\nhtml.div('#main', [\n    html.h1(null, 'Hello, world!'),\n    html.img({src: 'foo.jpg'})\n]);\n```\n\n```html\n\u003cdiv id=\"main\"\u003e\n    \u003ch1\u003eHello, world!\u003c/h1\u003e\n    \u003cimg src=\"foo.jpg\"/\u003e\n\u003c/div\u003e\n```\n\n#### Loops etc.\n\nUsing [Underscore.js](http://underscorejs.org) or similar:\n\n```javascript\nfunction todoItem(item) {\n    return html.li({rel: item.id}, [\n        html.div('.title', item.title),\n        html.button('.destroy', 'delete')\n    ]);\n}\n\nfunction todoList(list) {\n    return html.ul('.todo-list', _.map(list, todoItem));\n}\n\ntodoList([\n    {id: 1, title: 'item one'},\n    {id: 2, title: 'item two'},\n    {id: 3, title: 'item three'}\n]);\n```\n\n```html\n\u003cul class=\"todo-list\"\u003e\n    \u003cli rel=\"1\"\u003e\n        \u003cdiv class=\"title\"\u003eitem one\u003c/div\u003e\n        \u003cbutton class=\"destroy\"\u003edelete\u003c/button\u003e\n    \u003c/li\u003e\n    \u003cli rel=\"2\"\u003e\n        \u003cdiv class=\"title\"\u003eitem two\u003c/div\u003e\n        \u003cbutton class=\"destroy\"\u003edelete\u003c/button\u003e\n    \u003c/li\u003e\n    \u003cli rel=\"3\"\u003e\n        \u003cdiv class=\"title\"\u003eitem three\u003c/div\u003e\n        \u003cbutton class=\"destroy\"\u003edelete\u003c/button\u003e\n    \u003c/li\u003e\n\u003c/div\u003e\n```\n\n\n## Why use an internal DSL?\n\n- It's a more convenient and safer alternative to string contatenation\n- Very flexible, you can use all the power of JavaScript functions and\n  control structures\n- For small bits of HTML you might not want to switch contexts from code\n  to a template\n- Easier to debug than a templating engine\n- You get full tool-chain support:\n    - editor support: syntax highlighting, code tools etc etc\n    - code analyzers: jslint, jshint\n    - testing/coverage tools\n\n## When to use?\n\n- Consider using where you might currently use string concatenation\n- Avoid using for large HTML documents or in places where speed is critical\n- Good for small snippets used for client-side page updates\n- Bad for generating huge amounts of HTML on the server\n\n\n## Usage\n\nI like to alias the 'pithy' library as 'html':\n\n```javascript\nvar html = require('pithy');\n```\n\nYou can then just use html.`tagname` as a function to create the\nappropriate element. Please note, you actually get a html.SafeString\nobject back, not a native JavaScript String. This *might* mess up your\nisString() tests. If you have a workaround please send a pull-request.\n\nThere is also a html.escape() function for escaping HTML (returns a\nhtml.SafeString). It will not escape a value that is already a\nhtml.SafeString object.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaolan%2Fpithy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaolan%2Fpithy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaolan%2Fpithy/lists"}