{"id":13472486,"url":"https://github.com/Mikhus/domurl","last_synced_at":"2025-03-26T17:30:33.629Z","repository":{"id":56473023,"uuid":"9532162","full_name":"Mikhus/domurl","owner":"Mikhus","description":"Lightweight URL manipulation with JavaScript","archived":false,"fork":false,"pushed_at":"2020-11-05T11:23:14.000Z","size":168,"stargazers_count":541,"open_issues_count":9,"forks_count":98,"subscribers_count":22,"default_branch":"master","last_synced_at":"2024-10-30T04:53:58.731Z","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/Mikhus.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-04-18T21:19:46.000Z","updated_at":"2024-07-22T07:02:13.000Z","dependencies_parsed_at":"2022-08-15T19:20:55.141Z","dependency_job_id":null,"html_url":"https://github.com/Mikhus/domurl","commit_stats":null,"previous_names":["mikhus/jsurl"],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mikhus%2Fdomurl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mikhus%2Fdomurl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mikhus%2Fdomurl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mikhus%2Fdomurl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mikhus","download_url":"https://codeload.github.com/Mikhus/domurl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245372209,"owners_count":20604487,"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-07-31T16:00:55.069Z","updated_at":"2025-03-26T17:30:33.603Z","avatar_url":"https://github.com/Mikhus.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","String","String [🔝](#readme)"],"sub_categories":["Runner"],"readme":"# domurl 2.x (former jsurl) \n[![Build Status](https://travis-ci.org/Mikhus/domurl.svg?branch=master)](https://travis-ci.org/Mikhus/domurl) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/Mikhus/domurl/master/LICENSE)\n\nLightweight URL manipulation with JavaScript for both DOM and server JavaScript.\n\n## Goal\n\nTo have a convenient way working with URLs in JavaScript. From time to time there are usual tasks \nwhen it is required to add or remove some parameters to some basic URL or change some other URL\nparts.\n\nThere is no easy standard way to do it in JavaScript.\n\nThis small library intended to fix that problem\n\n## Supported Browsers\n\nThis library was tested under:\n - IE 7+\n - Chrome 25+\n - Opera 12.15+\n - Firefox 20+\n - Android browser 2.3+\n - NodeJS 0.10+\n\nTheoretically it should work fine with newer or older versions of these browsers, but\nit was not fully tested yet. If you'll find any compatibility issues, please, let me know by\nleaving a bug report here: https://github.com/Mikhus/domurl/issues\n\nYou can run basic tests for your browser here: https://rawgit.com/Mikhus/domurl/master/test/url.html or\nrun test.html from this repository locally. If any test has not been passed, please,\nopen a bug report as described above providing browser and OS version on each test\nwhich has been failed.\n\n## How To Use\n\nFirst of all it is required to include Url class on the page. It can be simply done as\n\n    \u003cscript src=\"url.min.js\"\u003e\u003c/script\u003e\n\nThen any time it's required to do some work over the URL string, it's just required to\ninstantiate the Url object and work with that object instead of initial string. See API\ndescription below to get a clue.\n\n## Install with JAM\n\nIt is possible also to install domurl via JAM repository (http://jamjs.org/).\nCould be simply done as:\n\n    $ jam install domurl\n\n## Install with Bower\n\nIt is also possible now to install domurl using Bower package repository.\nCould be done simply as:\n\n    $ bower install domurl\n    \n## Install with NPM\n\nDomurl is available on NPM and is now works well for both server and browser:\n\n    $ npm install domurl\n\n## API\n\n### Methods:\n\n**Url({string} [url], {boolean} [noTransform]) -\u003e {Url}**\n\nConstructor. If url argument is not passed, current document URL will be used.\nIf second argument bypassed as true value it will try to do no transforms\non a given source URL to keep it form as it was initially given. Otherwise,\nby default, it will try to resolve given URL to an absolute form.\n\n**Url.toString() -\u003e {string}**\n\nConverts URL to string representation. As far as it's special method, any time string\noperations is performed over Url objects this method is automatically called\n\n**Url.paths({Array} [pathStrings])**\n\nReturns Url.path representation as array or sets it via array representation\nif optional array of pathStrings was provided.\n\n**Url.encode({string} urlPart) -\u003e {string}**\n\nPerforms URI-compatible encoding of the given urlPart component. It works **not**\nthe same as native encodeURIComponent()!\n\n**Url.decode({string} encUrlPart) -\u003e {string}**\n\nPerforms decoding of URI-encoded component. It works **not** the same as native\ndecodeURIComponent()!\n\n**Url.clearQuery() -\u003e {Url}**\n\nRemoves all query string parameters from the URL\n\n**Url.queryLength() -\u003e {Number}**\n\nReturns total count of the query string parameters.\n\n**Url.isEmptyQuery() -\u003e {boolean}**\n\nReturns true if query string contains no parameters, false otherwise.\n\n### Properties:\n\n**Url.protocol** - protocol part of URL, everything between the beginning of the URL string \nand \"://\" delimiter (if specified)\n\n**Url.user** - auth user name (if specified)\n\n**Url.pass** - auth user password (if specified)\n\n**Url.host** - host name (if specified)\n\n**Url.port** - port number (if specified)\n\n**Url.path** - document path\n\n**Url.query** - QueryString object. It's a simple Javascript object with automatic string\nmapping. String representation contains everything after \"?\" and to the end of QueryString\n\n**Url.hash** - Anchor part of the URL. Everything after \"#\" and to the end of anchor\n\n## Usage Examples\n\n```javascript\nvar u  = new Url; // current document URL will be used\n// or we can instantiate as\nvar u2 = new Url( \"http://example.com/some/path?a=b\u0026c=d#someAnchor\");\n// it should support relative URLs also\nvar u3 = new Url( \"/my/site/doc/path?foo=bar#baz\");\n\n// get the value of some query string parameter\nalert( u2.query.a);\n// or\nalert( u3.query[\"foo\"]);\n\n// Manupulating query string parameters\nu.query.a = [1, 2, 3]; // adds/replaces in query string params a=1\u0026a=2\u0026a=3\nu.query.b = 'woohoo';  // adds/replaces in query string param b=woohoo\n\nif (u.query.a instanceof Array) { // the way to add a parameter\n  u.query.a.push(4); // now it's \"a=1\u0026a=2\u0026a=3\u0026a=4\u0026b=woohoo\"\n}\n\nelse { // if not an array but scalar value here is a way how to convert to array\n  u.query.a = [u.query.a];\n  u.query.a.push(8)\n}\n\n// The way to remove the parameter:\ndelete u.query.a\n// or:\ndelete u.query[\"a\"]\n\n// If you need to remove all query string params:\nu.clearQuery();\nalert( u);\n\n// Lookup URL parts:\nalert(\n    'protocol = ' + u.protocol + '\\n' +\n    'user = ' + u.user + '\\n' +\n    'pass = ' + u.pass + '\\n' +\n    'host = ' + u.host + '\\n' +\n    'port = ' + u.port + '\\n' +\n    'path = ' + u.path + '\\n' +\n    'query = ' + u.query + '\\n' +\n    'hash = ' + u.hash\n);\n\n// Manipulating URL parts\nu.path = '/some/new/path'; // the way to change URL path\nconsole.log(u.paths());\nu.paths(['some', 'new', 'path']); // change path by array of strings\nconsole.log(u.path);\nu.protocol = 'https' // the way to force https protocol on the source URL\n\n// inject into string\nvar str = '\u003ca href=\"' + u + '\"\u003eMy Cool Link\u003c/a\u003e';\n\n// or use in DOM context\nvar a = document.createElement('a');\na.href = u;\na.innerHTML = 'test';\ndocument.body.appendChild( a);\n\n// Stringify\nu += '';\nString(u);\nu.toString();\n// NOTE, that usually it will be done automatically, so only in special\n//       cases direct stringify is required\n```\n\n## License\n\nThis code is available under MIT license. Feel free to do what you want.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMikhus%2Fdomurl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMikhus%2Fdomurl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMikhus%2Fdomurl/lists"}