{"id":13823883,"url":"https://github.com/moznion/location-util","last_synced_at":"2025-10-25T14:30:30.280Z","repository":{"id":23004184,"uuid":"26354848","full_name":"moznion/location-util","owner":"moznion","description":"Utilities of location (URL) for browser and node. It has no dependencies.","archived":false,"fork":false,"pushed_at":"2014-11-14T04:45:41.000Z","size":176,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-30T01:38:08.667Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.org/package/location-util","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/moznion.png","metadata":{"files":{"readme":"README.md","changelog":"Changes.md","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-11-08T08:42:59.000Z","updated_at":"2021-09-26T23:55:16.000Z","dependencies_parsed_at":"2022-08-21T18:10:20.116Z","dependency_job_id":null,"html_url":"https://github.com/moznion/location-util","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Flocation-util","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Flocation-util/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Flocation-util/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Flocation-util/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moznion","download_url":"https://codeload.github.com/moznion/location-util/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238155458,"owners_count":19425718,"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-08-04T09:00:48.299Z","updated_at":"2025-10-25T14:30:29.978Z","avatar_url":"https://github.com/moznion.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"location-util [![NPM version](https://badge.fury.io/js/location-util.svg)](https://www.npmjs.org/package/location-util) [![Build Status](https://travis-ci.org/moznion/location-util.svg)](https://travis-ci.org/moznion/location-util)\n==\n\nUtilities of location (URL) for browser and node. It has no dependencies.\n\nSynopsis\n--\n\n```javascript\nvar l = new LocationUtil('http://example.com:3000/foo?bar=buz#frag');\nl.protocol();    // =\u003e 'http'\nl.host();        // =\u003e 'example.com'\nl.port();        // =\u003e 3000\nl.search();      // =\u003e {'bar': 'buz'}\nl.paramString(); // =\u003e '?bar=buz'\nl.hash();        // =\u003e 'frag'\nl.path();        // =\u003e '/foo'\nl.url();         // =\u003e '/foo?bar=buz#frag'\nl.origin();      // =\u003e 'http://example.com:3000'\n\nl.url('/user?id=123#name').absUrl();               // =\u003e 'http://example.com:3000/user?id=123#name'\nl.path('/entry').absUrl();                         // =\u003e 'http://example.com:3000/entry?id=123#name'\nl.search('date', '20140401', 'id', null).absUrl(); // =\u003e 'http://example.com:3000/entry?date=20140401#name'\nl.hash('').absUrl();                               // =\u003e 'http://example.com:3000/entry?date=20140401'\n```\n\nDescription\n--\n\nThis module parse URL and create object.\nObject provides some getter and setter methods.\nIt makes you to get URL or a part of that.\nAnd also you can rewrite and reconstruct URL via object.\n\nThis module is inspired by `$location` of [Angular.js](https://angularjs.org/).\n\nThis module has no dependencies.\nAnd it is available to use on browser and node.\n\nInstallation\n--\n\n### npm\n\n```\n$ npm install location-util\n```\n\n### bower\n\n```\n$ bower install location-util\n```\n\nMethods\n--\n\n- `new Locationutil(url)`\n\nCreates an instance. It takes `url` as string.\n\n- `absUrl()`\n\nThis method provides getter only.\n\nIt returns full URL.\n\n- `protocol()`\n\nThis method provides getter only.\n\nIt returns protocol (e.g. `http`). If protocol is empty, it returns blank string.\n\n- `host()`\n\nThis method provides getter only.\n\nIt returns the part of host.\n\n- `port()`\n\nThis method provides getter only.\n\nIt returns port number. If port number is empty, it returns `null`.\n\n- `search([queries])`\n\nThis method provides getter and setter.\n\nIf you use this method without any arguments, this method behave as getter. It returns the query as object (e.g. `{'bar': 'buz'}`).\nIf query is empty, it returns blank object.\n\nThe another case, this method behave as setter. It changes query according to arguments and returns changed instance.\nIf value of queries is null, the property specified via the first argument will be deleted.\n\n```javascript\nvar l = new LocationUtil('http://example.com?foo=bar');\nl.search(); // =\u003e {'foo': 'bar'}\nl.search('buz', 'qux');\nl.search(); // =\u003e {'foo': 'bar', 'buz': 'qux'}\nl.search('foo', null);\nl.search(); // =\u003e {'buz': 'qux'}\n```\n\n- `paramString()`\n\nThis method provides getter only.\n\nThis method returns query parameter string like a `?foo=bar\u0026buz=qux`. This method __doesn't__ ensure the order of key-values.\n\n```javascript\nvar l = new LocationUtil('http://example.com?foo=bar');\nl.paramString(); // =\u003e '?foo=bar'\nl.search('buz', 'qux');\nl.paramString(); // =\u003e '?foo=bar\u0026buz=qux'\n```\n\n- `path(pathString)`\n\nThis method provides getter and setter.\n\nIf you use this method without any arguments, this method behave as getter. It returns the part of path (e.g. `/foo/bar`).\nIf path is empty, it returns '/'.\n\nThe another case, this method behave as setter. It changes path according to arguments and returns changed instance.\nPath should always begin with forward slash ('/'), this method will add the forward slash if it is missing.\n\n```javascript\nvar l = new LocationUtil('http://example.com/foo');\nl.path(); // =\u003e '/foo'\nl.path('/bar/buz');\nl.path(); // =\u003e '/bar/buz'\n```\n\n- `hash(hashString)`\n\nThis method provides getter and setter.\n\nIf you use this method without any arguments, this method behave as getter. It returns the part of hash fragment.\nIf hash is empty, it returns blank string.\n\nThe another case, this method behave as setter. It changes hash fragment according to arguments and returns changed instance.\n\n```javascript\nvar l = new LocationUtil('http://example.com#foo');\nl.hash(); // =\u003e 'foo'\nl.hash('bar');\nl.hash(); // =\u003e 'bar'\n```\n\n- `url(urlString)`\n\nThis method provides getter and setter.\n\nIf you use this method without any arguments, this method behave as getter. It returns the URL (e.g. /foo?bar=buz#frag).\nIf URL is empty, it returns blank string.\n\nThe another case, this method behave as setter. It changes URL according to arguments and returns changed instance.\nURL should always begin with forward slash ('/'), this method will add the forward slash if it is missing.\n\n```javascript\nvar l = new LocationUtil('http://example.com/foo?bar=buz#frag');\nl.url(); // =\u003e '/foo?bar=buz#frag'\nl.url('/user?id=123#name');\nl.url(); // =\u003e '/user?id=123#name'\n```\n\n- `origin()`\n\nThis method provides only getter.\n\nThis method returns a string like so `\u003cprotocol\u003e://\u003chost\u003e:\u003cport\u003e`.\nIf underlying URL doesn't have `protocol` or `port`,\nit will omit them from result.\n\n```javascript\nvar l = new LocationUtil('http://example.com:3000/foo?bar=buz#frag');\nl.origin(); // =\u003e 'http://example.com:3000'\n\nl = new LocationUtil('http://example.com/foo?bar=buz#frag');\nl.origin(); // =\u003e 'http://example.com'\n```\n\nSee Also\n--\n\n[micro-location.js](https://github.com/cho45/micro-location.js/)\n\nIt's just simple and awesome library!\n\nlocation-util has some additional functions than this,\nbut if you don't need them, please try micro-location.js.\n\nAuthor\n--\n\nmoznion (\u003cmoznion@gmail.com\u003e)\n\nLicense\n--\n\nMIT\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoznion%2Flocation-util","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoznion%2Flocation-util","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoznion%2Flocation-util/lists"}