{"_id":"@bortunac/matx","_rev":"4-52da9def4040f41c5ef21d5c5b3311e8","name":"@bortunac/matx","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.0":{"name":"@bortunac/matx","version":"1.0.0","keywords":["math","precision","float","nested","utils","acm","object","pointer","sum","diff"],"author":{"name":"Bortun Adrian","email":"bortunadrian@gmail.com"},"license":"MIT","_id":"@bortunac/matx@1.0.0","maintainers":[{"name":"bortunac","email":"bortunadrian@gmail.com"}],"homepage":"https://github.com/bortunac/matx#readme","bugs":{"url":"https://github.com/bortunac/matx/issues"},"dist":{"shasum":"b65f956c6dfee51a3c64849dc4b40c1defba18d7","tarball":"https://registry.npmjs.org/@bortunac/matx/-/matx-1.0.0.tgz","fileCount":4,"integrity":"sha512-FGcGE4g3++KPBUvF4zZXTsb/8y/YDgprxddmYEW09lMCEyabgt9xnJuibuFoC4sXE5CntZVl0XOjhuYaGFJ8iQ==","signatures":[{"sig":"MEUCIQChlvxgx4reSwQ5tFPWSvNqRuyQV3h2gbpBX2I6P+9RawIgU3Sd02quitqgjTXrrpYDC8r0krBW+8o7XfiLQ18dM9o=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":13323},"main":"matx.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"bortunac","email":"bortunadrian@gmail.com"},"repository":{"url":"git+https://github.com/bortunac/matx.git","type":"git"},"_npmVersion":"11.3.0","description":"Precision-safe math utilities and nested object access for JavaScript.","directories":{},"_nodeVersion":"23.5.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/matx_1.0.0_1746235481593_0.3102565478228818","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@bortunac/matx","version":"1.0.1","keywords":["math","precision","float","nested","utils","acm","object","pointer","sum","diff"],"author":{"name":"Bortun Adrian","email":"bortunadrian@gmail.com"},"license":"MIT","_id":"@bortunac/matx@1.0.1","maintainers":[{"name":"bortunac","email":"bortunadrian@gmail.com"}],"homepage":"https://github.com/bortunac/matx#readme","bugs":{"url":"https://github.com/bortunac/matx/issues"},"dist":{"shasum":"981a8dba1a8229d4081fff2e446c52d9acc4dea8","tarball":"https://registry.npmjs.org/@bortunac/matx/-/matx-1.0.1.tgz","fileCount":5,"integrity":"sha512-QPVTlh1e+KsazOF0Ap2PhrE5WUtg30WauPiJUUwZsDU/GwtqBc533mr0pyKmRYZl7l9UiP1Y4rBpU49h6Muq5Q==","signatures":[{"sig":"MEQCIHaJiT4QPS+Ncpu9IbCpe5GxZzQebFaxeihTTSomcNBJAiBlSN0HK32xX5ckz4ybZTnjVKSTftkMQ1UgXRMknjsNVg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":13727},"main":"matx.js","gitHead":"195216f99c5c28007e46a6add8f6aa61d3ed7b3a","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"bortunac","email":"bortunadrian@gmail.com"},"repository":{"url":"git+https://github.com/bortunac/matx.git","type":"git"},"_npmVersion":"11.3.0","description":"Precision-safe math utilities and nested object access for JavaScript.","directories":{},"_nodeVersion":"23.5.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/matx_1.0.1_1746463670855_0.705071463311187","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@bortunac/matx","version":"1.0.2","keywords":["math","precision","float","nested","utils","acm","object","pointer","sum","diff"],"author":{"name":"Bortun Adrian","email":"bortunadrian@gmail.com"},"license":"MIT","_id":"@bortunac/matx@1.0.2","maintainers":[{"name":"bortunac","email":"bortunadrian@gmail.com"}],"homepage":"https://github.com/bortunac/matx#readme","bugs":{"url":"https://github.com/bortunac/matx/issues"},"dist":{"shasum":"398ee86812525dff55f19b31aa27c0b26eba2caa","tarball":"https://registry.npmjs.org/@bortunac/matx/-/matx-1.0.2.tgz","fileCount":5,"integrity":"sha512-3lh4PwgZb5y1Dh7wFd1dwZmGlruIjRemymhvkT8VuYD+k6ioRhBWL03cK5+t/hsTnIzLPqdkRTAhcqLmzdbu7g==","signatures":[{"sig":"MEUCIQC4F0nM0kYssf4mKFPiOJfvTNjbmPvdBC/z5CncSNdh5QIgTB7PJd3Tf2Ruv8U4IzSrzVe0L8QhCrpuYKRHX1stedQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":14468},"main":"matx.js","gitHead":"1dab708154a1518b08937e5cd60dc6c51fb6805f","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"bortunac","email":"bortunadrian@gmail.com"},"repository":{"url":"git+https://github.com/bortunac/matx.git","type":"git"},"_npmVersion":"11.3.0","description":"Precision-safe math utilities and nested object access for JavaScript.","directories":{},"_nodeVersion":"23.5.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/matx_1.0.2_1746463793367_0.06981484834246121","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"@bortunac/matx","version":"1.0.3","description":"Precision-safe math utilities and nested object access for JavaScript.","main":"matx.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"keywords":["math","precision","float","nested","utils","acm","object","pointer","sum","diff"],"author":{"name":"Bortun Adrian","email":"bortunadrian@gmail.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/bortunac/matx.git"},"_id":"@bortunac/matx@1.0.3","gitHead":"2d9aedc7f6c5e71399054ebbb5314fc73f36a64d","bugs":{"url":"https://github.com/bortunac/matx/issues"},"homepage":"https://github.com/bortunac/matx#readme","_nodeVersion":"23.5.0","_npmVersion":"11.3.0","dist":{"integrity":"sha512-uc3H7Vq2vkgyZFaRbzYxHbHFRHyJiZvJ9PRn5qZm7g0nvh8yOWXcuOu5QF2wDtTovFL6VSoiVAZldzAurEgzSw==","shasum":"9d2e74b3055c6e0f345259fc46a23eaac3b0f21e","tarball":"https://registry.npmjs.org/@bortunac/matx/-/matx-1.0.3.tgz","fileCount":5,"unpackedSize":14468,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIENZa0l+37AkL31/xqI+rBUPGVrgWH03fG/CHyKeO6U0AiB0D4PDMO30f79KK493R5n2IXRYKQXH7AneN0oacRCLrw=="}]},"_npmUser":{"name":"bortunac","email":"bortunadrian@gmail.com"},"directories":{},"maintainers":[{"name":"bortunac","email":"bortunadrian@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/matx_1.0.3_1746464473281_0.8852134884127603"},"_hasShrinkwrap":false}},"time":{"created":"2025-05-03T01:24:41.522Z","modified":"2025-05-05T17:01:13.638Z","1.0.0":"2025-05-03T01:24:41.756Z","1.0.1":"2025-05-05T16:47:51.020Z","1.0.2":"2025-05-05T16:49:53.559Z","1.0.3":"2025-05-05T17:01:13.457Z"},"bugs":{"url":"https://github.com/bortunac/matx/issues"},"author":{"name":"Bortun Adrian","email":"bortunadrian@gmail.com"},"license":"MIT","homepage":"https://github.com/bortunac/matx#readme","keywords":["math","precision","float","nested","utils","acm","object","pointer","sum","diff"],"repository":{"type":"git","url":"git+https://github.com/bortunac/matx.git"},"description":"Precision-safe math utilities and nested object access for JavaScript.","maintainers":[{"name":"bortunac","email":"bortunadrian@gmail.com"}],"readme":"# Matx\n\nMatx is a precision-safe math utility toolkit with deep object path support, ideal for financial and data aggregation tasks. It enhances JavaScript's native `Math` with precision-aware operations and introduces two object prototype extensions: `.pointer()` for safe nested access and `.scan()` for enumerable iteration.\n\n## 🚀 Installation\n\n```bash\nnpm install matx\n```\n\n## 📦 Usage\n\n### In ES6 module:\n\n```js\nimport 'matx';\n\nconst result = Math.sum(1.1, 2.22); // 3.32\n```\n\n### In Browser:\n\nInclude the bundled script and use `window.Matx`:\n\n```html\n<script src=\"matx.js\" type=\"module\"></script>\nor\nawait import(\"/path/matx.js\");\nMath.acm(...)\n```\n\n## 🔧 Features\n\n### 🔹 Math Methods\n\n* `Math.sum(...values)` – Accumulates with precision.\n* `Math.diff(a, b)` – Subtracts with precision.\n* `Math.acm(acmObj, srcObj, keys)` – Accumulate fields from `srcObj` into `acmObj`.\n* `Math.acms(...)` – Subtract version of `acm`.\n* `Math.acmd(...)` – Divide version of `acm`.\n* `Math.float0(x)` – Safe float parse.\n* `Math.bytes(x)` – Converts bytes into human-readable units.\n* `Math.precision(x, p, type)` – Applies fixed-point rounding.\n* `Math.get_precision(x)` – Finds decimal precision of a number.\n\n### 🔸 Object Extensions\n\n#### `.pointer(path[, value])`\n\nAccess or set deeply nested properties safely.\n\n```js\nconst obj = {};\nobj.pointer(\"a.b.c\", 42);\nconsole.log(obj); // { a: { b: { c: 42 } } }\n```\n\n#### `.scan(callback)`\n\nIterates key-value pairs like `Array.prototype.map`.\n\n```js\nconst o = { a: 10, b: 20 };\nconst keys = o.scan((k, v, i) => `${k}:${v}`);\nconsole.log(keys); // [\"a:10\", \"b:20\"]\n```\n\n### Array.prototype.having()\n\nThis utility adds advanced filtering to arrays:\n\n```js\nconst COL = [\n  { a: 1, b: 2 },\n  { a: 2, b: 1 },\n  { a: 3, b: 1 },\n  { a: 4, b: 5 },\n  { a: 5, b: 5 },\n  { a: 1, c: { d: 1, e: [\"alfa\"] } },\n  { c: { d: 1, e: [\"alfa\", \"beta\"] } }\n];\n\n// Filter with object criteria\nconsole.log(COL.having({ b: 5, a: 4 }, { a: [2, 3] }));\n\n// Filter with JS condition expression\nconsole.log(COL.having(\"${b} > 1 && ${a} > 4\"));\n\n// Filter with regex logic\nconsole.log(COL.having(\"/^5/.test('${b}')\"));\n\n// Deep search using $@ pointer notation\nconsole.log(COL.having(\"$@.c.e[1] !== undefined || $@.a > 2\"));\n```\n\n## Examples\n\n#### Object `.scan()` with `.pointer` Chaining\n\n```js\nconst dataset = {\n  101: { user: { id: 101, name: \"Alice\", scores: { math: 82 } } },\n  102: { user: { id: 102, name: \"Bob\", scores: { math: 91 } } },\n  103: { user: { id: 103, name: \"Charlie\", scores: { math: 75 } } }\n};\n\nconst result = dataset.scan(function (key, value) {\n  const name = value.pointer(\"user.name\");\n  const mathScore = value.pointer(\"user.scores.math\");\n  return `User ${name} scored ${mathScore} in math.`;\n});\n\nconsole.log(result);\n// [\n//   \"User Alice scored 82 in math.\",\n//   \"User Bob scored 91 in math.\",\n//   \"User Charlie scored 75 in math.\"\n// ]\n```\n\n#### `Math.acm` Aggregation Example\n\n```js\nconst acm = { total: 0 };\nconst items = [\n  { total: 10 },\n  { total: 25 },\n  { total: 5 }\n];\n\nMath.acm(acm, items, \"total\");\nconsole.log(acm); // { total: 40 }\n```\n\n#### `Math.acm` with Nested Keys Example\n\n```js\nconst acm = {};\nconst records = [\n  {\n    year_month: \"2024-01\",\n    sales: { online: 100, retail: 200 },\n    refunds: { online: 3, retail: 4 }\n  },\n  {\n    year_month: \"2024-02\",\n    sales: { online: 150, retail: 100 },\n    refunds: { online: 2, retail: 5 }\n  }\n];\n\nMath.acm(acm, records, [\n  \"sales.online\",\n  \"sales.retail\",\n  \"refunds.online\",\n  \"refunds.retail\"\n]);\n\nconsole.log(acm);\n// {\n//   sales: { online: 250, retail: 300 },\n//   refunds: { online: 5, retail: 9 }\n// }\n```\n\n### 🔍🧠 Why Matx?\n\n* Zero-dependency\n* Precision-safe\n* Works with deeply nested objects\n* Friendly to financial, scientific, or statistical data models\n\n## 📄 License\n\nMIT\n\n\n","readmeFilename":"README.md"}