{"id":20471347,"url":"https://github.com/statewalker/statewalker-uris","last_synced_at":"2025-08-29T14:22:21.128Z","repository":{"id":57767563,"uuid":"527621560","full_name":"statewalker/statewalker-uris","owner":"statewalker","description":null,"archived":false,"fork":false,"pushed_at":"2023-08-16T12:57:30.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-16T02:35:02.324Z","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/statewalker.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":"2022-08-22T15:23:19.000Z","updated_at":"2022-08-22T16:58:54.000Z","dependencies_parsed_at":"2025-01-16T02:21:28.847Z","dependency_job_id":"dc931a4c-d52c-43e9-b2cc-72f940744762","html_url":"https://github.com/statewalker/statewalker-uris","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"35a72ae355e808454678fa94c14042b72ac9aba8"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statewalker%2Fstatewalker-uris","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statewalker%2Fstatewalker-uris/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statewalker%2Fstatewalker-uris/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statewalker%2Fstatewalker-uris/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/statewalker","download_url":"https://codeload.github.com/statewalker/statewalker-uris/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242038950,"owners_count":20061921,"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-11-15T14:15:51.147Z","updated_at":"2025-03-05T13:42:16.595Z","avatar_url":"https://github.com/statewalker.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# @statewalker/uris: URIs Management Utilities\n\nA small library (~2.5K compressed/minimized) to manage URIs - parsing, serialization,\npath resolving, relative paths generation, concatenation and URIs rewriting.\n\nFor working examples see this Observable Notebook: https://observablehq.com/@kotelnikov/statewalker-uris.\n\n## `concatPath(...uris)`\n\nConcatenates URI paths and returns the result. The given uris can be objects or strings.\nThe resulting object is a string.\n\nExample: \n```javascript\nimport { concatPath } from '@statewalker/uris';\nconsole.log(concatPath('http://foo.bar/a/b/', '/my/path.txt'))\n// 'http://foo.bar/a/b/my/path.txt'\n```\n\n## `resolveUrl(...uris)`\n\nResolves URLs one after another starting from the first one and returns the string-serialized resulting URI.\n\nExample: \n```javascript\nimport { resolveUrl } from '@statewalker/uris';\nconsole.log(resolveUrl('http://foo.bar/a/b/', '../doc/', './my/path.txt'))\n// 'http://foo.bar/a/doc/my/path.txt'\n```\n\n## `makeRelative(first, second)`\n\nReturns the relative paths from the first URI to the second one.\n\nExample: \n```javascript\nimport { makeRelative } from '@statewalker/uris';\nconsole.log(makeRelative('http://foo.bar/a/b/index.md', 'http://foo.bar/a/c/d/readme.md'))\n// '../c/d/readme.md'\n```\n\n## `newPathMapping`\n\nThis method returns a function rewriting URIs.\nThe parameter of this method defines source base URIs with the corresponding target paths. \nThe returned function transforms URIs to the corresponding expanded paths.\n\nExample: \n```javascript\nimport { newPathMapping } from '@statewalker/uris';\n\n// Rewriting rules:\nconst transform = newPathMapping([\n    { source: './sources/', target: '/' },\n    { source: 'file:///tmp/data/', target: '/toto/' },\n    { source: 'http://www.foo.bar/tech/', target: '/docs/' },\n    { source: 'http://www.foo.bar/assets/img/', target: '/images/' }\n]);\n\nconsole.log(transform('./sources/index.md')); \n// '/index.md'\n\nconsole.log(transform('http://www.foo.bar/tech/readme.md'));\n// '/docs/readme.md'\n\nconsole.log(transform('http://www.foo.bar/assets/img/MyImage.jpg'));\n// '/images/MyImage.jpg'\n\nconsole.log(transform('file:///tmp/data/products/prices.md'));\n// '/toto/products/prices.md'\n\n```\n\n## `parseUri(uri)`\n\nParses the given string and returns the corresponding object with the following fields:\n- schema: ex: \"https\", \"ftp\", \"mailto\"\n- domain: \"foobar.com\"\n- path: \"/path/to/my/file.txt\"\n- query: { \"a\" : \"B\" }\n- fragment: \"hello\"\n\n\nExample: \n```javascript\nimport { parseUri } from '@statewalker/uris';\n\nconsole.log(parseUri('http://foo.bar/a/b/?a=b\u0026c=d#foobar'))\n/*\n{\n    schema: \"http\",\n    domain: \"foo.bar\",\n    path: \"/a/b/\",\n    query: { a: \"b\", c: \"d\" },\n    fragment: \"#foobar\"\n}\n*/\n```\n\n## `serializeUri(uri)`\n\nSerializes the given URI and returns the corresponding string representation.\n\n## `parseQuery(query)`\n\nParses the URI query and returns the corresponding object representation with key/value pairs.\n\n\n## `serializeQuery(query)`\n\nSerializes the URI query and returns the corresponding string.\n\n\n## `newUri(...list)`\n\nCreates a new URI from the list of the given URI objects. The returned result contains paths and fragments of the latest URI in the list. \nIf the specified list contains only one URI then this method returns its copy.\n   \n  \n## `resolveUri(from, to)`\n\nResolves the second URI and returns \n  \n## `makeRelativeUri(from, to)`\n\nCreates and returns a relative links from the initial URI to the target\n  \n  \n## `joinUri(...uris)`\n\nJoins URIs objects and returns resulting object with paths concatanated\n\n\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatewalker%2Fstatewalker-uris","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstatewalker%2Fstatewalker-uris","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatewalker%2Fstatewalker-uris/lists"}