{"id":16760360,"url":"https://github.com/ryanve/dope","last_synced_at":"2025-04-10T17:37:27.160Z","repository":{"id":3332880,"uuid":"4376691","full_name":"ryanve/dope","owner":"ryanve","description":"Cross-browser HTML5 dataset module","archived":false,"fork":false,"pushed_at":"2014-03-30T15:53:15.000Z","size":466,"stargazers_count":15,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T18:56:25.464Z","etag":null,"topics":["dataset","javascript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.org/package/dope","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ryanve.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-05-19T08:11:16.000Z","updated_at":"2023-08-08T21:08:26.000Z","dependencies_parsed_at":"2022-08-28T01:41:02.421Z","dependency_job_id":null,"html_url":"https://github.com/ryanve/dope","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanve%2Fdope","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanve%2Fdope/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanve%2Fdope/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanve%2Fdope/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryanve","download_url":"https://codeload.github.com/ryanve/dope/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248262036,"owners_count":21074237,"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":["dataset","javascript"],"created_at":"2024-10-13T04:23:15.324Z","updated_at":"2025-04-10T17:37:27.141Z","avatar_url":"https://github.com/ryanve.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dope\r\n\u003cb\u003edope\u003c/b\u003e is cross-browser JavaScript module for working with HTML attributes. It includes an HTML5 [dataset](http://dev.opera.com/articles/view/an-introduction-to-datasets/) API abstraction that adheres to the [specification](http://www.w3.org/TR/2010/WD-html5-20101019/elements.html#embedding-custom-non-visible-data-with-the-data-attributes). It works standalone or can integrate into jQuery-compatible hosts. It runs screamin-fast and [gzips \u003c 2k](dope.min.js). Got data? =)\r\n\r\n## API ([2.2](CHANGELOG.md))\r\nIn standalone usage, methods are available on the **dope** namespace. The docs below use `$` to denote `dope` or a host library like jQuery or ender.\r\n\r\n```js\r\ndope.dataset(document.body, 'foo', 'bar'); // standalone\r\n$.dataset(document.body, 'foo', 'bar'); // integrated\r\n```\r\n\r\n### Chain methods\r\n#### $.fn.attr()\r\n```js\r\n$(elem).attr(key) // get attribute on elem (or 1st elem in collection)\r\n$(elem).attr(key, value) // set attribute on elem (or on collection)\r\n$(elem).attr(object) // set multiple attributes via key/value pairs\r\n```\r\n\r\n#### $.fn.removeAttr()\r\n```js\r\n$(elem).removeAttr(keys) // remove 1 or more SSV attributes from elem or collection\r\n```\r\n\r\n#### $.fn.dataset()\r\n```js\r\n$(elem).dataset() // get all data-* attributes on elem (or 1st elem in collection)\r\n$(elem).dataset(key) // get data-* attribute on elem (or 1st elem in collection)\r\n$(elem).dataset(key, value) // set data-* attribute on elem (or on collection)\r\n$(elem).dataset(object) // set multiple data-* attributes via key/value pairs\r\n$(elem).dataset([key]) // get [exact] data-* attribute (primitives render to correct type)\r\n```\r\n\r\n```js\r\n$(document.body).dataset('movieName', Pulp Fiction) // set \u003cbody data-movie-name=\"Pulp Fiction\"\u003e\r\n$(document.body).dataset('movieName') // returns \"Pulp Fiction\"\r\n$('div').dataset('stars', 5) // set \u003cdiv data-stars=\"5\"\u003e on all matched divs\r\n$('div').dataset('stars') // returns \"5\"\r\n$('div').dataset(['stars']) // returns 5\r\n```\r\n\r\n#### $.fn.deletes()\r\n```js\r\n$(elem).deletes(keys) // remove 1 or more SSV data-* attributes from elem or collection\r\n```\r\n\r\n```js\r\n$(document.body).deletes('movieName') // remove [data-movie-name] from the \u003cbody\u003e element\r\n```\r\n\r\n### Static methods\r\n#### $.attr()\r\n```js\r\n$.attr(elem, key) // get attribute on elem\r\n$.attr(elem, key, value) // set attribute on elem\r\n$.attr(elem, object) // set multiple attributes via key/value pairs\r\n```\r\n\r\n#### $.removeAttr()\r\n```js\r\n$.removeAttr(elem, keys) // remove 1 or more SSV attributes from elem (or from collection)\r\n```\r\n\r\n#### $.dataset()\r\n```js\r\n$.dataset(elem) // get all data-* attrs on elem\r\n$.dataset(elem, key) // get data-* attribute on elem\r\n$.dataset(elem, key, value) // set data-* attribute on elem\r\n$.dataset(elem, object) // set multiple data-* attributes via key/value pairs\r\n$.dataset(elem, [key]) // get [exact] data-* attribute (primitives parse to correct type)\r\n```\r\n\r\n```js\r\n$.dataset(document.body, 'movieName', Pulp Fiction) // set \u003cbody data-movie-name=\"Pulp Fiction\"\u003e\r\n$.dataset(document.body, 'movieName') // returns \"Pulp Fiction\"\r\n```\r\n\r\n#### $.deletes()\r\n```js\r\n$.deletes(elem, keys) // remove 1 or more SSV data-* attributes from elem (or from collection)\r\n```\r\n\r\n```js\r\n$.deletes(document.body, 'movieName') // remove [data-movie-name] from the \u003cbody\u003e element\r\n```\r\n\r\n#### $.queryData()\r\n```js\r\n$.queryData(keys) // get elements by data key (keys can be an array or CSV or SSV string)\r\n```\r\n\r\n```js\r\n$.queryData('miaWallace vincentVega') // Delegate to $(\"[data-mia-wallace],[data-vincent-vega]\")\r\n```\r\n\r\n#### $.trim()\r\n```js\r\n$.trim(str) // Trim surrounding whitespace.\r\n```\r\n\r\n#### $.parse()\r\n```js\r\n$.parse(str) // Convert stringified primitives to correct value. Non-strings are unchanged.\r\n$.parseJSON(str) // Parse JSON. Safely wraps `JSON.parse` so that it won't throw an error.\r\n```\r\n\r\n`$.parse` and `$.parseJSON` trim `\"string\"` inputs before parsing them.\r\n\r\n```js\r\n$.parse('yo') // 'yo'\r\n$.parse('10') // 10\r\n$.parse('true') // true\r\n$.parse('null') // null\r\n$.parse('undefined') // undefined\r\n$.parse('Infinity') // Infinity\r\n$.parse('NaN') // NaN\r\n```\r\n\r\n#### $.camelize()\r\n```js\r\n$.camelize(str) // convert a dashed data- string into camelCase\r\n```\r\n\r\n```js\r\n$.camelize('data-mia-wallace') // 'miaWallace'\r\n$.camelize('mia-wallace') // 'miaWallace'\r\n$.camelize(47) // '47'\r\n```\r\n\r\n#### $.datatize()\r\n```js\r\n$.datatize(str) // convert a camelized string into a lowercase dashed data- attribute name\r\n```\r\n\r\n```js\r\n$.datatize('miaWallace') // 'data-mia-wallace'\r\n$.datatize(47) // 'data-47'\r\n$.datatize(0) // 'data-0'\r\n$.datatize(null) // ''\r\n$.datatize('') // ''\r\n$.datatize(undefined) // ''\r\n```\r\n\r\n## [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) usage\r\n\r\n```js\r\ndefine('dope', function() { \r\n  return dope; \r\n});\r\n```\r\n\r\n## Compatibility\r\nSupports all major browsers. Tested in Chrome, FF3+, IE7+, Opera, and Safari.\r\n\r\n## Related modules\r\n- [atts](https://github.com/ryanve/atts): attributes module\r\n\r\n## License\r\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanve%2Fdope","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryanve%2Fdope","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanve%2Fdope/lists"}