{"id":30107079,"url":"https://github.com/benignware/elopts.js","last_synced_at":"2025-08-10T01:33:03.678Z","repository":{"id":17359504,"uuid":"20131170","full_name":"benignware/elopts.js","owner":"benignware","description":"Collects parameters from a dom element and merges them with other objects","archived":false,"fork":false,"pushed_at":"2015-10-01T17:55:21.000Z","size":274,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2023-08-12T18:37:42.890Z","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/benignware.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":"2014-05-24T14:20:44.000Z","updated_at":"2023-08-12T18:37:42.890Z","dependencies_parsed_at":"2022-08-04T18:30:34.311Z","dependency_job_id":null,"html_url":"https://github.com/benignware/elopts.js","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"purl":"pkg:github/benignware/elopts.js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benignware%2Felopts.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benignware%2Felopts.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benignware%2Felopts.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benignware%2Felopts.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benignware","download_url":"https://codeload.github.com/benignware/elopts.js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benignware%2Felopts.js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269663306,"owners_count":24455801,"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","status":"online","status_checked_at":"2025-08-09T02:00:10.424Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-08-10T01:32:16.863Z","updated_at":"2025-08-10T01:33:03.621Z","avatar_url":"https://github.com/benignware.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"elopts.js\n=========\n\n\u003e Collects parameters from a dom element and merges them with other objects\n\nElopts.js is a simple javascript module that helps you in gathering information about a dom-element, such as data-attributes, the src-attribute's query-params or json from a cdata-section. \nThis is useful when implementing js-plugins or 3rd-party js-applications. \n\nSome of the tasks implemented by elopts.js could be also done with jquery or any other js-library. The benefit of elopts.js is not only that it combines all in a single method, but to serve as the entry-point of a javascript-application in the main place.\nFor example, elopts.js could be embedded in a standalone-widget or utilized to bootstrap a [requirejs](http://requirejs.org/)-application in conjuction with the [requirejs-initscript](http://github.com/benignware/requirejs-initscript) plugin .\n\nBasic Usage\n-----------\n\n```html\n\u003cscript id=\"test\" \n  src=\"a.js?param1=test4\u0026param2=test4\" \n  data-option=\"test1\" \n  data-json=\"['test2']\"\u003e\n  \u003c![CDATA[{\n    \"result\": \"test3\"\n  }]]\u003e\n\u003c/script\u003e\n```\n\n```js\nvar element = document.getElementById('test');\nvar options = elopts(element);\n// print result\nconsole.log(JSON.stringify(options, null, 2));\n```\n\nThis will print out the following:\n```js\nlog: {\n  \"param1\": \"test4\",\n  \"param2\": \"test4\",\n  \"option\": \"test1\",\n  \"json\": [\n    \"test2\"\n  ],\n  \"data\": {\n    \"result\": \"test3\"\n  }\n}\n```\n\n#### Merge default options into the result\nYou can set multiple arguments to merge objects into the result.\n```js\nvar options = elopts(element, {\n  def: 'default', \n  option: 'default'\n});\n```\n\nConfiguration\n-------------\nYou may want to disable certain features by setting up a custom config before calling elopts itself:\n```js\nelopts.options = {\n  json: false, \n  dataset: false, \n  cdata: false, \n  params: false\n};\nvar options = elopts(element);\n```\n\nIf you need multiple setups, you can create a new instance of elopts like this:\n```js\nvar options = elopts.newInstance({\n  json: false, \n  dataset: false, \n  cdata: false, \n  params: false\n})(element, {\n  // defaults go here\n});\n```\n\n### Options\n\n#### options.dataset\nType: `Boolean`\nDefault value: `true`\n\nSpecify whether data-attributes should be collected or not.\n\n#### options.json\nType: `Boolean`\nDefault value: `true`\n\nSpecify whether string values should be parsed as json or not.\n\n#### options.params\nType: `Boolean`\nDefault value: `true`\n\nSpecify whether query-params should be parsed and merged into the result if the element has a 'src'-attribute.\n\n#### options.cdata\nType: `Boolean`\nDefault value: `true`\n\nSpecify whether a single cdata-section should be parsed as json and stored as 'data'-property into the result. \n\n#### options.cdataName\nType: `String`\nDefault value: `data`\n\nSpecify the name of the property to which json from a cdata-section is stored. \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenignware%2Felopts.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenignware%2Felopts.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenignware%2Felopts.js/lists"}