{"id":15495115,"url":"https://github.com/samchon/urlvariables","last_synced_at":"2025-10-09T00:42:08.164Z","repository":{"id":50097065,"uuid":"122161830","full_name":"samchon/URLVariables","owner":"samchon","description":"URLVariables class for TypeScript","archived":false,"fork":false,"pushed_at":"2021-06-04T09:50:10.000Z","size":22,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-03T12:19:46.932Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/samchon.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":"2018-02-20T06:10:35.000Z","updated_at":"2021-06-04T09:50:13.000Z","dependencies_parsed_at":"2022-08-03T19:00:28.500Z","dependency_job_id":null,"html_url":"https://github.com/samchon/URLVariables","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samchon%2FURLVariables","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samchon%2FURLVariables/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samchon%2FURLVariables/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samchon%2FURLVariables/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samchon","download_url":"https://codeload.github.com/samchon/URLVariables/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233496959,"owners_count":18684990,"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-10-02T08:16:09.485Z","updated_at":"2025-09-18T16:30:33.949Z","avatar_url":"https://github.com/samchon.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# URLVariables\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/samchon/URLVariables/blob/master/LICENSE)\n[![npm version](https://badge.fury.io/js/url-variables.svg)](https://www.npmjs.com/package/url-variables)\n[![Downloads](https://img.shields.io/npm/dm/url-variables.svg)](https://www.npmjs.com/package/url-variables)\n[![Build Status](https://github.com/samchon/URLVariables/workflows/build/badge.svg)](https://github.com/samchon/URLVariables/actions?query=workflow%3Abuild)\n[![Chat on Gitter](https://badges.gitter.im/samchon/URLVariables.svg)](https://gitter.im/samchon/URLVariables?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n`URLVariables`, it's the most simple, concise and eledic library for URL-encoding \u0026 URL-decoding. You can parse or encode url-string very easily with this `URLVariables`.\n\n```typescript\nimport URLVariables = require(\"url-variables\");\n\nlet url_str: string = \"https://some_url?id=samchon\u0026age=29\u0026is_crazy=true\";\nlet author: IAuthor = URLVariables.parse\u003cIAuthor\u003e(url_str);\n\nconsole.log(author.id); // \"samchon\" =\u003e string\nconsole.log(author.age); // 29 =\u003e number\nconsole.log(author.is_crazy); // true =\u003e boolean\n\ninterface IAuthor\n{\n    id: string;\n    age: number;\n    is_crazy: boolean;\n}\n```\n\n## Installation\n### NPM Module\nInstalling **URLVariables**, it's very easy. Just install with the `npm`\n\n```bash\n# Install URLVariables from the NPM module\nnpm install --save url-variables\n```\n\n## Usage\n### API Reference\nTo use `URLVariables`, just remember that below structure, then you'll understand how to use it.\n\nIf you want to know more about the detailed features, then utilize auto-completion of TypeScript or read the [Guide Documents](https://github.com/samchon/URLVariables/wiki). You also want to know about the `std.HashMap`, base class of the `URLVariables`, then visit the [TSTL proejct](https://github.com/samchon/tstl).\n\n```typescript\nnamespace URLVariables\n{\n    // DYNAMIC OBJECT\n    function parse(str: string, autoCase: boolean = true): Object;\n    function stringify(obj: Object): string;\n}\n\nclass URLVariables extends std.HashMap\u003cstring, string\u003e\n{\n    // CONSTRUCTORS \u0026 CONVERTERS\n    public constructor();\n    public constructor(url_encoded_str: string); // PARSE\n    public toString(); // RETURNS URL-ENCODED STRING\n\n    // ACCESSORS\n    public has(key: string): boolean;\n    public get(key: string): string;\n    public set(key: string, value: string): string;\n}\n```\n\n### Example Code\nIn this section, we'll see global functions `URLVariables.parse()` and `URLVariables.stringify()`, handling dynamic objects, first. After that, we'll study `URLVariables class`, extended from `std.HashMap class`, who is much safer then handling dynamic objects.\n\n#### example.ts\n```typescript\nimport std = require(\"tstl\");\nimport URLVariables = require(\"url-variables\");\n\ntype Element = std.Entry\u003cstring, string\u003e;\n\ninterface IAuthor\n{\n    name: string;\n    age: number;\n    git: string;\n    homepage: string;\n    memo: string;\n    is_crazy: boolean;\n}\n\nfunction main(): void\n{\n    let author: IAuthor = \n    {\n        name: \"Samchon (Jeongho Nam)\",\n        age: 29,\n        git: \"https://github.com/samchon/tstl\",\n        homepage: \"http://samchon.org\",\n        memo: \"Hello, I'm the best programmer in Korea.\",\n        is_crazy: true\n    };\n    \n    test_global(author);\n    test_class(author);\n}\n\nfunction test_global(author: IAuthor): void\n{\n    //----\n    // STRINGIFY \u0026 PARSE\n    //----\n    // STRINGIFY -\u003e OBJECT TO URL-ENCODED STRING\n    let url_encoded_str: string = URLVariables.stringify(author);\n\n    console.log(url_encoded_str);\n    console.log(\"----------------------------------\\n\");\n\n    // PARSE -\u003e URL-ENCODED STRING TO OBJECT\n    let obj: IAuthor = URLVariables.parse(url_encoded_str, true);\n\n    //----\n    // VALIDATE\n    //----\n    // VALIDATE STRINGIFY\n    if (url_encoded_str != URLVariables.stringify(obj))\n        throw new std.DomainError(\"Error on URLVariables.decode().\");\n\n    // VALIDATE PARSE -\u003e (AUTHOR == OBJ)?\n    for (let key in author)\n        if (author[key] != obj[key])\n            throw new std.DomainError(\"Error on URLVariables.parse().\");\n\n    // PRINT A DYNAMIC OBJECT, CREATED BY URL-ENCODED STRING\n    console.log(\"Re-generated Dynamic Object by url-encoding \u0026 decoding:\\n\");\n    console.log(obj);\n}\n\nfunction test_class(author: IAuthor): void\n{\n    console.log(\"\\n----------------------------------\\n\");\n\n    //----\n    // GENERATE URL-VARIABLES OBJECT\n    //----\n    let dict: URLVariables = new URLVariables();\n    \n    // FILL ELEMENTS\n    dict.set(\"name\", author.name);\n    dict.set(\"age\", String(author.age)); // MUST BE STRING\n    dict.set(\"git\", author.git);\n    dict.set(\"homepage\", author.homepage);\n    dict.set(\"memo\", author.memo);\n    dict.set(\"is_crazy\", String(author.is_crazy));\n\n    // CONVERT THE URL-VARIABLES OBJECT TO URL-ENCODED STRING\n    let url_encoded_str: string = dict.toString();\n\n    //----\n    // VALIDATIONS\n    //----\n    // CREATE A NEW URL-VARIABLES OBJECT \n    // BY PARSING THE URL-ENCODED STRING\n    let vars: URLVariables = new URLVariables(url_encoded_str);\n\n    // VALIDATE SIZE\n    if (dict.size() != vars.size())\n        throw new std.LengthError(\"Size are different.\");\n\n    // ALL ELEMENTS ARE EQUAL\n    let equal: boolean = std.equal\n    (\n        dict.begin(), dict.end(), vars.begin(), \n        function (x: Element, y: Element): boolean\n        {\n            return x.first == y.first \u0026\u0026 x.second == y.second;\n        }\n    );\n    if (equal == false)\n        throw new std.InvalidArgument(\"Elements are different.\");\n\n    // ALL ELEMENTS ARE EQUAL, THEN ENCODINGS MUST BE SAME\n    if (dict.toString() != vars.toString())\n        throw new std.DomainError(\"Error on URLVariables.toString().\");\n\n    //----\n    // ACCESSORS\n    //----\n    // ACCESS TO MEMBERS BY URLVariables.get()\n    console.log\n    (\n        `${dict.get(\"memo\")} \\n` + \n        `I'm ${dict.get(\"name\")} and ${dict.get(\"age\")} years old. \\n` +\n        `I've published my libraries on: \\n` +\n        `  - GitHub: ${dict.get(\"git\")} \\n` +\n        `  - Homepage: ${dict.get(\"homepage\")} \\n`\n    );\n\n    // TEST WHETHER SOME VARIABLES ARE REGISTERED OR NOT\n    console.log(\"Am I crazy?:\", dict.has(\"is_crazy\"));\n    console.log(\"Has name?:\", dict.has(\"name\"));\n    console.log(\"Has nickname?:\", dict.has(\"nickname\"));\n}\n\nmain();\n```\n\n#### output\n```txt\nname=Samchon%20(Jeongho%20Nam)\u0026age=29\u0026git=https%3A%2F%2Fgithub.com%2Fsamchon%2Ftstl\u0026homepage=http%3A%2F%2Fsamchon.org\u0026memo=Hello%2C%20I'm%20the%20best%20programmer%20in%20Korea.\u0026is_crazy=true\n----------------------------------\n\nRe-generated Dynamic Object by url-encoding \u0026 decoding:\n\n{ name: 'Samchon (Jeongho Nam)',\n  age: 29,\n  git: 'https://github.com/samchon/tstl',\n  homepage: 'http://samchon.org',\n  memo: 'Hello, I\\'m the best programmer in Korea.',\n  is_crazy: true }\n\n----------------------------------\n\nHello, I'm the best programmer in Korea.\nI'm Samchon (Jeongho Nam) and 29 years old.\nI've published my libraries on:\n  - GitHub: https://github.com/samchon/tstl\n  - Homepage: http://samchon.org\n\nAm I crazy?: true\nHas name?: true\nHas nickname?: false\n```\n\n\n\n## References\n  - **Repositories**\n    - [GitHub Repository](https://github.com/samchon/URLVariables)\n    - [NPM Repository](https://www.npmjs.com/package/url-variables)\n  - **Documents**\n    - [**Guide Documents**](https://github.com/samchon/URLVariables/wiki)\n    - [API Documents](http://samchon.github.io/URLVariables/api)\n  - **Related Project**\n    - [TSTL](https://github.com/samchon/tstl)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamchon%2Furlvariables","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamchon%2Furlvariables","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamchon%2Furlvariables/lists"}