{"id":15012793,"url":"https://github.com/microsoft/parallax-loader","last_synced_at":"2025-10-19T14:31:15.969Z","repository":{"id":57318797,"uuid":"399061666","full_name":"microsoft/parallax-loader","owner":"microsoft","description":"parallax-loader","archived":false,"fork":false,"pushed_at":"2024-07-12T08:57:16.000Z","size":51,"stargazers_count":6,"open_issues_count":0,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-01-30T10:41:33.117Z","etag":null,"topics":["configuration","parallax","typescript"],"latest_commit_sha":null,"homepage":"","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/microsoft.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":"SECURITY.md","support":null}},"created_at":"2021-08-23T10:29:53.000Z","updated_at":"2024-07-12T08:57:20.000Z","dependencies_parsed_at":"2023-01-22T01:52:41.906Z","dependency_job_id":null,"html_url":"https://github.com/microsoft/parallax-loader","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/microsoft%2Fparallax-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fparallax-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fparallax-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fparallax-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/microsoft","download_url":"https://codeload.github.com/microsoft/parallax-loader/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237143800,"owners_count":19262277,"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":["configuration","parallax","typescript"],"created_at":"2024-09-24T19:43:13.829Z","updated_at":"2025-10-19T14:31:15.580Z","avatar_url":"https://github.com/microsoft.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Parallax ini library\nParallax config is configuration schema that is widely used within Microsoft Bing. The config is usually expressed in ini file with a schema file.\n\n## Example\nAssume there is a typescript schema file as below\n```typescript\nexport interface MainConfig {\n    Label: string;\n    Cnt: number;\n    Sub: SubConfig;\n}\n\nexport interface SubConfig {\n    Enabled: boolean;\n    Arr: number[];\n    Map: Record\u003cstring, number\u003e;\n}\n```\nAnd there is ini file as below,\n```ini\n[main]\n_type=MainConfig\nLabel=sample\nCnt\u0026param1:value1=8\nCnt=9\nSub\u0026param1:value1\u0026param2:value2=sub1\nSub=sub\n\n[sub]\n_type=SubConfig\nEnabled=false\nArr=1,2,3\nMap\u0026param3:value3=A:0,B:1,C:2\nMap=A:1,B:2,C:3\n\n[sub1]\n_type=SubConfig\nEnabled=true\nArr\u0026param3:value3=5,6,7\nArr=4,5,6\nMap=A:2,B:3,C:4\n```\nIn the ini file above, each section corresponds to one specific interface. Value of **_type** would be same as interface name. The key of each config line correponds to field of the interface with some constraints. For example, **Arr\u0026param3:value3=2,3,4** means when **param3:value3** condition matches, its value is [2,3,4].\n\u003cbr/\u003e\nAnd if there is reference to CustomType, it should be represented by section name for the the CustomType, like **Sub=sub** should point to section sub.\n\u003cbr/\u003e\nCurrently the library supports list and map (which is Record in typescript). List would be represented by string seperataed by ','. Map would be represented by string seperated by ',' as well and its key and value would be seperated by ':'.\n\u003cbr/\u003e\n**Please notice that, in current version, only line after trimmed starts with ';' would be treated as comment line.**\n## Constraint combination\nIn parallax config, we could easily express constraint combination. Take the ini config below for example,\n```ini\n[main]\n_type=Config\nProbability\u0026reg:east\u0026gender:female=0.8\nProbability\u0026reg:east\u0026gender:male=0.7\nProbability\u0026reg:west\u0026gender:female=0.5\nProbability\u0026reg:west\u0026gender:male=0.4\nProbability=0.1\n```\nAs you could see from ini file, we could express some probability with region and gender combination. Once specific constraints recieved, we could get related resolved Probability value without checking different condition combinations.\n## Configuration Resolve\nFor the ini file above, each field value is resolved by matching the constraints attached with order as prioerity. For example, if only **param3:value3** matches, then MainConfig would be resolved as below,\n```json\n{\n    Label: \"sample\",\n    Cnt: 9,\n    Sub: {\n        Enabled: false,\n        Arr: [1, 2, 3],\n        Map: {\n            A: 0,\n            B: 1,\n            C: 2\n        }\n    }\n}\n```\nIf **param1:value1\u0026param2:value2** matches, **param1:value1** matches as well, then MainConfig would be resolved as below,\n```json\n{\n    Label: \"sample\",\n    Cnt: 8,\n    Sub: {\n        Enabled: true,\n        Arr: [4,5,6],\n        Map: {\n            A: 2,\n            B: 3,\n            C: 4\n        }\n    }\n}\n```\n**Please notice that the library assumes that the resolved config would be parsed from the first section of the ini file.**\n## Supported types\nCurrently the library supports types as below in typescript,\n- string\n- number\n- boolean\n- enum\n- CustomType\n- string[]\n- number[]\n- boolean[]\n- enum[]\n- CustomType[]\n- Record\u003cstring, string\u003e\n- Record\u003cstring, number\u003e\n- Record\u003cstring, boolean\u003e\n- Record\u003cstring, enum\u003e\n- Record\u003cstring, CustomType\u003e\n\nFor custom defined enum, it should have non-negative integer assigned to each field.\n## Development Setup\nPlease install vscode as IDE.\n```ini\n# install\nnpm install\n\n# build\nnpm run build\n\n# run test\nnpm run test\n\n# run lint\nnpm run lint\n```\nTo debug test case, please set configuration to be **Jest Current File**, open test file and run **Start Debugging** from vscode menu.\n\u003cbr/\u003e\nTo debug **main.ts** from example folder, please update the **module** to be **CommonJS** in **tsconfig.json**, set configuration to be **Launch Example Gen** and run **Start Debugging** from vscode menu. Please do remember to revert the **module** change back to **ESNext** for building and running tests.\n## Usage\nThe library would be published as npm package parallax-loader which is actually a webpack loader. If your bundle tools is webpack, then you could define a rule as below,\n```javascript\n{\n    test: /\\.ini$/,\n    use: [\n        {\n            loader: 'parallax-loader',\n            options: {\n                schema: path.resolve(__dirname, '../src/Config.ts')\n            }\n        }\n    ]\n}\n```\nThen you could load the ini file in code as below,\n```\nconst configLoadFunc = rquire('./Config.ini')\nconst config = configLoadFunc(['reg:south'])\n```\nPlease check more in [Demo Folder](https://github.com/microsoft/parallax-loader/tree/main/demo).\n\u003cbr/\u003e\nIf you don't have any bundle tool, then you run the built gen.js with node.js, to generate output typescript file under the same folder of schema file, which would be ConfigGen.ts for the command below,\n```\nnode gen.js ./src/Config.ts ./src/Config.ini\n```\nAnd you could import **generateConfig** from the genreated file and resolve config with constraint list. For example,\n```typescript\nimport {generateConfig} from \"./ConfigGen\"\nconst config = generateConfig(['reg:south'])\n```\nTo generate js code, add --js as below,\n\n```ini\nnode gen.js ./src/Config.ts ./src/Config.ini --js\n```\nYou could also resolved config with code below,\n```javascript\nconst configLoadFunc = require(\"./ConfigGen\")\nconst config = configLoadFunc([\"reg:south\"])\n```\nIf you have the parallax-loader installed, gen.js is also generated as part of the library. Then you could run command like below as well.\n```\nnode node_modules/parallax-loader/dist/gen.js ./src/Config.ts ./src/Config.ini --js\n```\nAnd you could add this command to the build/debug command, which would be like a webpack loader to automatically update the generated code if you change the schema/configuration file. For example,\n```\n{\n    \"scripts\": {\n        \"code_gen\": \"node node_modules/parallax-loader/dist/gen.js ./src/Config.ts ./src/Config.ini --js\",\n        \"build_inner\": \"some build command\",\n        \"build\": \"npm run code_gen \u0026\u0026 npm run build_inner\"\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoft%2Fparallax-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrosoft%2Fparallax-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoft%2Fparallax-loader/lists"}