{"id":16125625,"url":"https://github.com/semibran/bag","last_synced_at":"2025-04-06T13:12:54.013Z","repository":{"id":130492018,"uuid":"80589832","full_name":"semibran/bag","owner":"semibran","description":"Draw random items from a user-defined list","archived":false,"fork":false,"pushed_at":"2017-02-10T23:26:48.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-12T18:59:29.104Z","etag":null,"topics":["bag","random","tetris"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/semibran.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-01T04:35:22.000Z","updated_at":"2018-03-12T16:23:46.000Z","dependencies_parsed_at":"2024-03-15T04:16:54.243Z","dependency_job_id":null,"html_url":"https://github.com/semibran/bag","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/semibran%2Fbag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semibran%2Fbag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semibran%2Fbag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semibran%2Fbag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/semibran","download_url":"https://codeload.github.com/semibran/bag/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247485291,"owners_count":20946398,"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":["bag","random","tetris"],"created_at":"2024-10-09T21:30:16.987Z","updated_at":"2025-04-06T13:12:53.993Z","avatar_url":"https://github.com/semibran.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bag\n\u003e Draw random items from a user-defined list\n\nA rough implementation of the classic [**Random Generator**](http://tetris.wikia.com/wiki/Random_Generator) system from Tetris.\n\n```javascript\nconst Bag = require('bag')\n\nvar fruits = ['apple', 'orange', 'banana']\nvar fruitBasket = Bag(fruits)\n\nfor (var i = 0, max = 10; i \u003c max; i++) {\n  var fruit = fruitBasket.draw()\n  console.log(fruit)\n}\n```\n\nInternally, each `Bag` instance has a `contents` array which turns out to be a shuffled version of the `items` initially passed. An item is removed from the bag each time `draw` is called. Once the bag is empty, the items are reshuffled and \"poured\" back into the bag. This process continues indefinitely as long as items are drawn from the bag's contents.\n\n## Installation\n```sh\nnpm install --save semibran/bag\n```\n\n## Usage\n\n### Factory\n```javascript\nvar bag = Bag(items, seed)\n```\n\nCreates a new `Bag` instance with the following parameters:\n- `items`: An `Array` of elements to place into the bag.\n- `seed`: A `Number` used to seed the bag's output. Use to coordinate the output of two separate `Bag` instances (e.g. providing the same piece sequence for two Tetris players)\n\n### Methods\n\n#### `draw`\n```javascript\nvar randomItem = bag.draw()\n```\n\n#### `fill`\n```javascript\nbag = bag.fill() // Refill the bag until it is full enough to match `items.length`\n```\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsemibran%2Fbag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsemibran%2Fbag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsemibran%2Fbag/lists"}