{"_id":"@adaloop/weighted-list","name":"@adaloop/weighted-list","dist-tags":{"latest":"1.0.4"},"versions":{"1.0.4":{"name":"@adaloop/weighted-list","version":"1.0.4","description":"Weighted list implementation, pick random item using probability distribution","main":"build/index.js","types":"build/index.d.ts","type":"module","scripts":{"build":"npm run clean && tsc","clean":"del-cli build","format":"prettier --write .","lint":"eslint . --ext .ts","prepublishOnly":"npm run build","release":"npx release-it","test":"c8 node --loader ts-node/esm --enable-source-maps bin/test.ts","quick:test":"node --loader ts-node/esm --enable-source-maps bin/test.ts","typecheck":"tsc --noEmit"},"keywords":["weighted","list","probability","loot","adaloop"],"author":{"name":"adaloop","email":"hello@adaloop.com"},"license":"MIT","devDependencies":{"@japa/assert":"^3.0.0","@japa/expect-type":"^2.0.2","@japa/runner":"^3.1.4","@swc/core":"^1.7.12","@adaloop/eslint-config":"^1.0.7","@adaloop/prettier-config":"^1.0.7","@adaloop/tsconfig":"^1.0.7","@types/node":"^22.4.1","c8":"^10.1.2","del-cli":"^5.1.0","eslint":"^9.9.0","prettier":"^3.3.3","release-it":"^17.6.0","ts-node":"^10.9.2","typescript":"^5.5.4"},"eslintConfig":{"extends":"@adaloop/eslint-config/package"},"prettier":"@adaloop/prettier-config","publishConfig":{"access":"public","tag":"latest"},"release-it":{"git":{"commitMessage":"chore(release): ${version}","tagAnnotation":"v${version}","tagName":"v${version}"},"github":{"release":true,"releaseName":"v${version}","web":true}},"_id":"@adaloop/weighted-list@1.0.4","gitHead":"a7d8371ad77cd54848c6053a30446c873149422f","_nodeVersion":"21.7.3","_npmVersion":"10.8.3","dist":{"integrity":"sha512-3n1OAF9CsM+f2pXdg9HHplYpOdrRjrY31p8T6opEFOHCNTVGJdZbiWNs7u1rhC+8OCJk5qUvzWKCusWoQVxdUA==","shasum":"37eb4d3e261e2c17c2640445a1d0b951ee3cefa9","tarball":"https://registry.npmjs.org/@adaloop/weighted-list/-/weighted-list-1.0.4.tgz","fileCount":25,"unpackedSize":14533,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCMTZ8N6n7MWbZ+/QE9AptYJhHsOtzFwzTIZ0EdcTAKvAIgOD4zYmg7yv83tz2IVmfTWLMplB+kjPxdLC4QDR9kW3c="}]},"_npmUser":{"name":"tombrulin","email":"tomm.brulin@gmail.com"},"directories":{},"maintainers":[{"name":"tombrulin","email":"tomm.brulin@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/weighted-list_1.0.4_1726585087363_0.21931160557502727"},"_hasShrinkwrap":false}},"time":{"created":"2024-09-17T14:58:07.271Z","1.0.4":"2024-09-17T14:58:07.515Z","modified":"2024-09-17T14:58:07.825Z"},"maintainers":[{"name":"tombrulin","email":"tomm.brulin@gmail.com"}],"description":"Weighted list implementation, pick random item using probability distribution","keywords":["weighted","list","probability","loot","adaloop"],"author":{"name":"adaloop","email":"hello@adaloop.com"},"license":"MIT","readme":"# Weighted List\n\n`@adaloop/weighted-list` is a weighted list implementation, pick random item using probability distribution. It also includes a loot table implementation.\n\n## Features\n\n### Weighted List\n\nWeighted list are lists where each item has a weight. The probability of picking an item randomly is proportional to its weight.\n\n### Loot Table\n\nLoot table is a table is where each row is a weighted list and has a chance to be rolled. It is often used in games.\n\n## Installation\n\n```bash\nnpm install @adaloop/weighted-list\n```\n\n## Usage\n\n### Weighted List\n\n```ts\nimport { WeightedList } from '@adaloop/weighted-list'\n\nconst list = new WeightedList<string>(100) // 100 is the total weight, default is 100\nlist.add('a', 25)\nlist.add('b', 25)\nlist.add('c', 50)\n\nconst item = list.pickRandom() // 'a' or 'b' or 'c'\nconst item2 = list.pick(50) // You can also pick a specific weight\n```\n\n### Weighted List with empty weight\n\nWhen item added doesn't fill the total weight, it can return null.\n\n```ts\nimport { WeightedList } from '@adaloop/weighted-list'\n\nconst list = new WeightedList<string>(100) // 100 is the total weight, default is 100\nlist.add('a', 25)\nlist.add('b', 25)\n\nconst item = list.pickRandom() // 'a' or 'b' or null\nconst item2 = list.pick(50) // You can also pick a specific weight\n```\n\n### Loot Table\n\n```ts\nimport { LootTable, WeightedList } from '@adaloop/weighted-list'\n\nconst lootTable = new LootTable<string>()\n\nlootTable.add(new WeightedList<string>(100).add('a', 25).add('b', 25).add('c', 50), 100)\nlootTable.add(new WeightedList<string>(100).add('t', 25).add('u', 25), 50)\n\nconst rolledItems = lootTable.roll() // Return list of items\n```\n","readmeFilename":"README.md"}