{"id":13426404,"url":"https://github.com/yuanqing/charming","last_synced_at":"2025-10-19T20:16:49.497Z","repository":{"id":19181242,"uuid":"22413849","full_name":"yuanqing/charming","owner":"yuanqing","description":":tophat: Lettering.js in vanilla JavaScript","archived":false,"fork":false,"pushed_at":"2021-01-30T07:39:35.000Z","size":481,"stargazers_count":1010,"open_issues_count":5,"forks_count":60,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-04-01T03:32:32.655Z","etag":null,"topics":["dom","javascript","typography"],"latest_commit_sha":null,"homepage":"https://codepen.io/lyuanqing/pen/YeYdrm","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/yuanqing.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-30T07:07:14.000Z","updated_at":"2025-03-14T02:58:09.000Z","dependencies_parsed_at":"2022-07-27T00:01:58.890Z","dependency_job_id":null,"html_url":"https://github.com/yuanqing/charming","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanqing%2Fcharming","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanqing%2Fcharming/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanqing%2Fcharming/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanqing%2Fcharming/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yuanqing","download_url":"https://codeload.github.com/yuanqing/charming/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247773719,"owners_count":20993639,"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":["dom","javascript","typography"],"created_at":"2024-07-31T00:01:33.695Z","updated_at":"2025-10-19T20:16:44.473Z","avatar_url":"https://github.com/yuanqing.png","language":"JavaScript","readme":"# charming [![npm Version](https://badgen.net/npm/v/charming)](https://www.npmjs.org/package/charming) [![Build Status](https://badgen.net/travis/yuanqing/charming?label=build)](https://travis-ci.org/yuanqing/charming) [![Coverage Status](https://badgen.net/coveralls/c/github/yuanqing/charming)](https://coveralls.io/r/yuanqing/charming) [![Bundle Size](https://badgen.net/bundlephobia/minzip/charming)](https://bundlephobia.com/result?p=charming)\n\n\u003e [Lettering.js](https://github.com/davatron5000/Lettering.js) in vanilla JavaScript\n\n- Supports changing the tag name or class name of the inserted DOM elements\n- Supports controlling how the contents of the element are wrapped\n\n## Usage\n\n\u003e [**Editable demo (CodePen)**](https://codepen.io/lyuanqing/pen/YeYdrm)\n\nHTML:\n\n```html\n\u003ch1\u003efoo\u003c/h1\u003e\n```\n\nJavaScript:\n\n```js\nconst charming = require('charming')\n\nconst element = document.querySelector('h1')\ncharming(element)\n```\n\nBoom:\n\n```html\n\u003ch1 aria-label=\"foo\"\u003e\n  \u003cspan class=\"char1\" aria-hidden=\"true\"\u003ef\u003c/span\u003e\n  \u003cspan class=\"char2\" aria-hidden=\"true\"\u003eo\u003c/span\u003e\n  \u003cspan class=\"char3\" aria-hidden=\"true\"\u003eo\u003c/span\u003e\n\u003c/h1\u003e\n```\n\n- Charming also works when the given element contains other (possibly nested) DOM elements; any character that is inside a [text node](https://developer.mozilla.org/en-US/docs/Web/API/Text) in the given element will be wrapped.\n- For accessibility, Charming adds an `aria-label` attribute on the given element and `aria-hidden` attributes on each of the inserted DOM elements.\n\n## API\n\n```js\nconst charming = require('charming')\n```\n\n### charming(element [, options])\n\n- `element` is a DOM element\n- `options` is an optional configuration object\n\nUse `options.tagName` to change the tag name of the wrapper element:\n\n```js\ncharming(element, {\n  tagName: 'b'\n})\n```\n\nUse `options.setClassName` to change the class name on each wrapper element:\n\n```js\ncharming(element, {\n  setClassName: function (index, letter) {\n    return `index-${index} letter-${letter}`\n  }\n})\n```\n\nUse `options.split` to control how the contents of the element are wrapped:\n\n```js\ncharming(element, {\n  split: function (string) {\n    return string.split(/(\\s+)/)\n  },\n  setClassName: function (index) {\n    return `word-${index}`\n  }\n})\n```\n\n## Installation\n\n```sh\n$ yarn add charming\n```\n\n## License\n\n[MIT](LICENSE.md)\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuanqing%2Fcharming","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuanqing%2Fcharming","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuanqing%2Fcharming/lists"}