{"id":23280982,"url":"https://github.com/nicholaswmin/arithmeticss","last_synced_at":"2026-05-17T01:42:56.903Z","repository":{"id":263531331,"uuid":"890695801","full_name":"nicholaswmin/arithmeticss","owner":"nicholaswmin","description":"arithmetic expressions on CSS variables","archived":false,"fork":false,"pushed_at":"2024-11-24T19:05:08.000Z","size":360,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-05T11:11:37.588Z","etag":null,"topics":["css","css-custom-properties","parser"],"latest_commit_sha":null,"homepage":"https://nicholaswmin.github.io/arithmeticss/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nicholaswmin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":null,"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":"2024-11-19T02:43:08.000Z","updated_at":"2024-11-24T19:05:13.000Z","dependencies_parsed_at":"2024-11-19T20:44:22.043Z","dependency_job_id":"23f1e404-36a7-40b0-aa77-7d0a0e81899a","html_url":"https://github.com/nicholaswmin/arithmeticss","commit_stats":null,"previous_names":["nicholaswmin/calc","nicholaswmin/arithmeticss"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nicholaswmin/arithmeticss","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicholaswmin%2Farithmeticss","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicholaswmin%2Farithmeticss/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicholaswmin%2Farithmeticss/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicholaswmin%2Farithmeticss/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nicholaswmin","download_url":"https://codeload.github.com/nicholaswmin/arithmeticss/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicholaswmin%2Farithmeticss/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265595922,"owners_count":23794806,"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":["css","css-custom-properties","parser"],"created_at":"2024-12-19T23:39:50.385Z","updated_at":"2026-05-17T01:42:51.878Z","avatar_url":"https://github.com/nicholaswmin.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![tests](https://github.com/nicholaswmin/arithmeticss/actions/workflows/tests.yml/badge.svg)](https://github.com/nicholaswmin/arithmeticss/actions/workflows/tests.yml)\n[![100% coverage](https://github.com/nicholaswmin/arithmeticss/actions/workflows/coverage.yml/badge.svg)](https://github.com/nicholaswmin/arithmeticss/actions/workflows/coverage.yml)\n\narithmetic expressions on CSS variables,   \n[tokenized][subs-src] \u0026 [calculated][calc-src] in userland, w/o [`eval`][eval].  \n\nzero deps, `~900 bytes`.\n\n[playground][demo-url]\n\n## example\n\n```bash\nnpm i https://github.com/nicholaswmin/arithmeticss.git\n```\n\nAssuming `some.css`:\n\n```css\n:root {\n  --foo: 10px;\n  --bar: 5;\n  --baz: 2;\n}\n```\n\nthen in `some.js`:\n\n```js\nimport calc from '@nicholaswmin/arithmeticss'\n\nconst res = calc('--foo * --bar + --baz * 3')\n\nconsole.log(res) // logs: 56\n```\n\n...thats all.\n\n## gotchas\n\n### It's unitless\n\nFor example: `50% + 100em = 150`, which is wrong.\n\nI didn't need fancy units, so I didn't bother, but it should be fairly \neasy to extend.[^1]\n\n### No parentheses\n\ne.g: `--foo * (--bar + 5)` is invalid.    \n\nFancy arithmetic requires a [shunting-yard][syard] implementation, \ni.e., 10x more code. I'll pass.  \n\n### don't squash expressions\n\nwon't work: `--foo+--bar`. It's ambiguous.     \nworks: `--foo + --bar`.  \n\nParsing errors throw a [`SyntaxError`][synterr], the rest will either \nbe a [`TypeError`][typesrr] or (rarely) a [`RangeError`][rangerr].\n\n\n## test\n\n\u003e requires node `v23+`\n\nunit tests:\n\n```bash\nnode --run test\n```\n\ncoverage:\n\n```bash\nnode --run coverage\n```\n\n### contributing\n\n[contr. guide][cntb-url]\n\n## build\n\nbundling \u0026 min. are application-level concerns, not module-level concerns   \nso there's no `build` or `dist/` versions here.\n\nThat being said, you can run:\n\n```bash\nnpx esbuild index.js --bundle --minify --format=esm --outfile=\"dist/arithmeticss.js\"\n```\n\n... which builds a minified bundle at: `dist/arithmeticss.js`,  \nwhich you simply move to your own project \u0026 `import` as usual:\n\n```html\n\u003c!-- ... some html --\u003e\n\n\u003cscript type=\"module\"\u003e\n  import calc from './arithmeticss.js'\n  \n  console.log(calc('--foo + --bar * 10'))\n  // 230\n\u003c/script\u003e\n\n\u003c!-- more html ... --\u003e\n```\n\n## authors\n\n[@nicholaswmin][author]\n\n## license\n\n\u003e MIT License\n\u003e\n\u003e Copyright (c) 2024 Nicholas Kyriakides   \n\u003e\n\u003e Permission is hereby granted, free of charge, to any person obtaining a \n\u003e copy of this software and associated documentation files (the \"Software\"), \n\u003e to deal in the Software *without restriction*, ncluding without limitation\n\u003e the rights to: \n\u003e use, copy, modify, merge, publish, distribute, sublicense, and/or sell \n\u003e copies of the Software, and to permit persons to whom the Software is \n\u003e furnished to do so, subject to the following conditions:\n\u003e \n\u003e The above copyright notice and this permission notice shall be\n\u003e included in all copies or substantial portions of the Software.\n\n\n## footnotes\n\n[^1]: `em` is based on the font-size of the parent. Easy.\n      `rem` is based on the font-size of the root. Also easy.\n      `%` is based on the ??? ... this is tricky because \n      its based on the property where the variable is assigned.  \n      It's doable but the syntax is gonna look like crap.\n      \n\n\n\u003c!-- References --\u003e\n\n[author]: https://github.com/nicholaswmin\n\n[calc-src]: ./src/calculate.js\n[subs-src]: ./src/transform.js\n[demo-url]: https://nicholaswmin.github.io/arithmeticss/demo.html\n[cntb-url]: ./.github/CONTRIBUTING.md\n[syard]: https://en.wikipedia.org/wiki/Shunting_yard_algorithm\n[eval]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval#never_use_direct_eval!\n[calc]: https://developer.mozilla.org/en-US/docs/Web/CSS/calc\n[mit]: https://en.wikipedia.org/wiki/MIT_License\n\n[rangerr]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError\n[typesrr]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError\n[synterr]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicholaswmin%2Farithmeticss","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicholaswmin%2Farithmeticss","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicholaswmin%2Farithmeticss/lists"}