{"id":37904367,"url":"https://github.com/loadingio/ldquery","last_synced_at":"2026-01-16T17:08:19.992Z","repository":{"id":42979981,"uuid":"161597596","full_name":"loadingio/ldquery","owner":"loadingio","description":"lightweight DOM Helpers in vanillaJS.","archived":false,"fork":false,"pushed_at":"2025-07-12T08:16:56.000Z","size":449,"stargazers_count":4,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-02T12:14:59.949Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"LiveScript","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/loadingio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-13T07:02:18.000Z","updated_at":"2025-07-12T08:16:59.000Z","dependencies_parsed_at":"2024-06-20T23:25:59.545Z","dependency_job_id":"65396e4b-6221-44dc-bab4-e3c67a21d343","html_url":"https://github.com/loadingio/ldquery","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/loadingio/ldquery","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadingio%2Fldquery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadingio%2Fldquery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadingio%2Fldquery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadingio%2Fldquery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loadingio","download_url":"https://codeload.github.com/loadingio/ldquery/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadingio%2Fldquery/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28480081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":"2026-01-16T17:08:19.929Z","updated_at":"2026-01-16T17:08:19.985Z","avatar_url":"https://github.com/loadingio.png","language":"LiveScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @loadingio/ldquery\n\nlightweight DOM Helpers in Vanilla JS.\n\n\n## Installation\n\ninstall via npm:\n\n    npm install @loadingio/ldquery\n\nor, download it from github:\n\n    https://github.com/loadingio/ldquery/releases/latest/download/ldq.js\n    https://github.com/loadingio/ldquery/releases/latest/download/ldq.min.js\n\nor use it directly via CDN:\n\n    https://cdn.jsdelivr.net/gh/loadingio/ldquery@v1.1.3/dist/ldq.js\n    https://cdn.jsdelivr.net/gh/loadingio/ldquery@v1.1.3/dist/ldq.min.js\n\n\nin you html, include it directly with `\u003cscript\u003e` tag:\n\n    \u003cscript src=\"https://cdn.jsdelivr.net/gh/loadingio/ldquery@v1.1.3/dist/ldq.min.js\"\u003e\u003c/script\u003e\n\n\n## Usage\n\nldquery provides following functions:\n\n * find(node, selector, index):\n   shorthand for querySelector and querySelectorAll. return array when index is omitted.\n * index(node): index of node in childNodes of its parent.\n * child(node): children of node, in Array.\n * parent(node, selector, endNode):\n   search parent(including node) for which matching the selector, until endNode is reached. return null if not found.\n * attr(node, name, value): get attribute \"name\" if value is omitted. set attribute if value is provided.\n * on(node, name, callback): addEventListener on event name.\n * remove(node): remove node from parent.\n * insertAfter(node, newNode, oldNode): insert newNode after oldNode under node.\n * fetch: fetch API helper. \n * xhr: XMLHttpRequest API helper.\n * json(data): handy function to convert things to object.\n * cls(o,p,n): handy function for setting classes.\n   - o: either object or value. \n     - object: class name / on,off pair\n     - value: true to toggle classes in p on, and classes in n off. vice versa.\n   - p: positive class list ( toggled when o is true )\n   - n: negative class list ( toggled when o is false )\ninvoke these functions with ld$, e.g., \n\n    ld$.find(document.body, '.btn', 0) \n\nor ignore the first parameter if it's document:\n\n    ld$.find('.btn', 0)  /* equivalent to ld$.find(document, '.btn', 0) */\n\n\nIt also provides in wrapper style:\n\n    ld$(document.body).find('.btn', 0)\n\n\nWhile it's not a good idea but you can pollute the native DOM for a more intuitive way to use these functions:\n\n    # in livescript syntax\n    HTMLElement.prototype \u003c\u003c\u003c ld$obj.prototype\n\nThis could be enabled by remove the comment mark in corresponding line inside ldq.ls.\n\n\n## Fetch\n\nldquery wraps fetch api with promise-based error handling and some additional parameter.\n\n    ld$.fetch(\u003cURL\u003e, \u003cRAWOPTION\u003e, \u003cLDQOPTION\u003e)\n      .then -\u003e  ...\n      .catch (e) -\u003e # use e.data to get raw response from fetch\n\nCommon raw options:\n\n * method: HTTP method. e.g., \"POST\"\n * body: things to send to server. pass JSON by stringify it.\n   - `ld$.fetch \"url\", {body: JSON.stringify({data: 1})}`\n * headers: header hash. customize your own header here.\n\nCommon ldquery Options:\n\n * type: indicate the response data type. could be `text` or `json`.\n * json: json object to pass. shorthand for manually setting headers and stringify object.\n   - this:\n     `ld$.fetch(\"url\", {}, {json: {data: 1}})`\n   - is the same with this:\n     `ld$.fetch(\"url\", {body: \"{data: 1}\", headers: {'Content-Type': 'application/json; charset=UTF-8'}})`\n * params: shorthand for setting get params. expect an object with key/value pair. will convert it to querystring.\n   - this:\n     `ld$.fetch(\"url\", {}, {params: {qs: \"some text\"}}\n   - is the same with this:\n     `ld$.fetch(\"url?qs=some%20text\", {}, {})\n * timeout: elapsed time ( in milliseconds ) for a timeout error to be fired. default 40s\n * no-default-headers: default null. set this to true to bypass default headers in ld$.fetch.headers.\n\n\nYou can also config global headers by updating values in ld$.fetch.headers:\n\n    ld$.fetch.headers[\"X-CSRF-TOKEN\"] = ...\n\n\n## XMLHttpRequest\n\nWhile `fetch` is newer than XMLHttpRequest, for now XMLHttpRequest does better in handling progress information. Thus you can use `ld$.xhr` instead of `ld$.fetch` if such information is needed.\n\nUsing `xhr` is almost identical with using `fetch`:\n\n    ld$.xhr(\u003cURL\u003e, \u003cRAWOPTION\u003e, \u003cLDQOPTION\u003e)\n      .then -\u003e  ...\n      .catch (e) -\u003e # use e.data to get raw response from fetch\n\nYet it accepts one additional ldquery option:\n\n * progress({percent, val, len}): a callback function accepting progress information as an object\n   - percent: 0 ~ 1, 1 = finished.\n   - val: current progress.\n   - len: expected total progress.\n   - this function has no expected return value.\n\n\n### Error Handling\n\nld$.fetch doesn't depend on ldError, but it indeed returns ldError compatible errors, with following fields:\n\n * name: ldError\n * id: error code\n * code: http code. ( optional )\n * data: returned data\n * json: parsed json from returned data, if any ( optional )\n\nWhen request failed, ld$.fetch will try to parse returned data as json, and check if there is a field \"name\" with value \"ldError\". If \"ldError\" name field exists, this object will be used directly to construct the Error object.\n\n\n## Compatibility\n\nldquery uses following modern web features:\n\n * fetch api - not support in IE, Older Edge ( \u003c= 13). Use polyfill to support to IE \u003e= 11\n * classList - not support well in IE. Use Polyfill to fix this.\n * Array.from - not supported in IE. Use Polyfill to fix this.\n\n\n## License\n\nMIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floadingio%2Fldquery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floadingio%2Fldquery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floadingio%2Fldquery/lists"}