{"id":17148939,"url":"https://github.com/planttheidea/nage","last_synced_at":"2025-04-13T11:42:36.070Z","repository":{"id":34301555,"uuid":"175538322","full_name":"planttheidea/nage","owner":"planttheidea","description":"Efficient, tiny object pool","archived":false,"fork":false,"pushed_at":"2024-03-28T17:33:22.000Z","size":713,"stargazers_count":9,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T02:51:15.408Z","etag":null,"topics":["memory-allocation","memory-management","pooling"],"latest_commit_sha":null,"homepage":null,"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/planttheidea.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":"2019-03-14T03:02:11.000Z","updated_at":"2024-07-29T14:49:07.000Z","dependencies_parsed_at":"2023-01-15T06:15:19.842Z","dependency_job_id":"631246f2-1eb6-4c2e-87a8-8898445a624f","html_url":"https://github.com/planttheidea/nage","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planttheidea%2Fnage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planttheidea%2Fnage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planttheidea%2Fnage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planttheidea%2Fnage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/planttheidea","download_url":"https://codeload.github.com/planttheidea/nage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248709718,"owners_count":21149181,"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":["memory-allocation","memory-management","pooling"],"created_at":"2024-10-14T21:30:36.115Z","updated_at":"2025-04-13T11:42:36.050Z","avatar_url":"https://github.com/planttheidea.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nage\n\nEfficient, tiny object pool\n\n## Table of contents\n\n- [nage](#nage)\n  - [Table of contents](#table-of-contents)\n  - [Usage](#usage)\n  - [Typings](#typings)\n  - [Pool options](#pool-options)\n      - [create](#create)\n      - [initialSize](#initialsize)\n      - [maxSize](#maxsize)\n      - [name](#name)\n      - [onReserve](#onreserve)\n      - [onRelease](#onrelease)\n      - [onReset](#onreset)\n  - [Pool methods](#pool-methods)\n      - [reserve](#reserve)\n      - [release](#release)\n      - [reserveN](#reserven)\n      - [releaseN](#releasen)\n      - [reset](#reset)\n  - [Pool values](#pool-values)\n      - [available](#available)\n      - [reserved](#reserved)\n      - [size](#size)\n  - [Development](#development)\n\n## Usage\n\n```typescript\nimport nage from 'nage';\n\n// create your pool\nconst pool = nage();\n\n// reserve an object from the pool\nconst object = pool.reserve();\n\n// do your logic\n\n// release object back to the pool\npool.release(object);\n```\n\n## Typings\n\nAll typings for the internals are under the `Nage` namespace. The available types:\n\n```typescript\ntype Entry = {\n  [key: string]: any;\n  [index: number]: any;\n};\n\ntype Creator\u003cPooled\u003e = () =\u003e Pooled;\n\ntype Handler\u003cPooled\u003e = (entry: Pooled) =\u003e void;\n\ntype ResetHandler\u003cPooled\u003e = (stack: Pooled[]) =\u003e void;\n\ntype Options\u003cPooled extends {} = Entry\u003e = {\n  create?: Creator\u003cPooled\u003e;\n  initialSize?: number;\n  name?: number | string | symbol;\n  onRelease?: Handler\u003cPooled\u003e;\n  onReserve?: Handler\u003cPooled\u003e;\n  onReset?: ResetHandler\u003cPooled\u003e;\n};\n```\n\nThe pool itself is not namespaced, it should be available directly as `NagePool`:\n\n## Pool options\n\n#### create\n\n_defaults to () =\u003e ({})_\n\nThe method used to create a new object in the pool. The default returns an empty object, but if you have objects with a consistent structure it is more memory efficient to return an object with that structure to reduce the number of hidden classes created under-the-hood.\n\n```typescript\ntype Obj = {\n  name: string | null;\n  target: any;\n}\n\nconst pool = nage\u003cObj\u003e({\n  create() {\n    return {\n      name: null,\n      target: null,\n    };\n  },\n});\n```\n\n**NOTE**: This function does not receive any arguments, and must return an object of some kind. This can be a standard POJO, array, Map, Set, etc., but it cannot be a primitive or `null`.\n\n#### initialSize\n\n_defaults to 1_\n\n```typescript\nconst pool = nage\u003cObj\u003e({ initialSize: 10 });\n```\n\nThe number of objects to prepopulate the pool with. If you expect a number of objects to be used in parallel, it is advised to prepopulate the pool with the number appropriate for the use-case.\n\n#### maxSize\n\n_defaults to Infinity_\n\n```typescript\nconst pool = nage\u003cObj\u003e({ maxSize: 10 });\n```\n\nThe maximum number of objects that will live in the pool. If you have reserved an object from the pool and try to release it back to the pool, it will allow the object to be garbage collected.\n\n**NOTE**: If you provide an `initialSize` that is larger than the `maxSize`, the `maxSize` will be used as the `initialSize`.\n\n#### name\n\n```typescript\nconst pool = nage\u003cObj\u003e({ name: 'custom-name' });\n```\n\nThe name for the given pool. This doesn't impact anything at runtime, but can help with debugging as an identifier.\n\n#### onReserve\n\n```typescript\ntype Obj = { [key: string]: any };\n\nconst pool = nage\u003cObj\u003e({\n  onReserve(object) {\n    object.reservedAt = Date.now();\n  },\n});\n```\n\nHandler called for a newly-reserved item from the pool, called with the object prior to being returned. This method is handy if you want to prepopulate the object with some data.\n\n#### onRelease\n\n```typescript\ntype Obj = { [key: string]: any };\n\nconst pool = nage\u003cObj\u003e({\n  onRelease(object) {\n    for (const key in object) {\n      object[key] = null;\n    }\n  },\n});\n```\n\nHandler called for a newly-released item back into the pool, called with the object just prior to being added to the stack. This method is handy to perform cleanup of the object in preparation for future use.\n\n#### onReset\n\n```typescript\nconst pool = nage\u003cObj\u003e({\n  onReset(stack) {\n    stack.forEach((entry) =\u003e {\n      console.log(entry);\n    });\n  },\n});\n```\n\nHandler called just prior to the stack being [`reset`](#reset). This method is handy if you need to take a snapshot of the existing pool prior to it being purged and repopulated.\n\n## Pool methods\n\n#### reserve\n\nReserves an object from the pool. If no objects remain to be reserved, it will create a new one for you based on the [`create`](#create) method from [options](#pool-options).\n\n```typescript\nconst object = pool.reserve();\n```\n\n#### release\n\nReleases an object back to the pool from where it came from.\n\n```typescript\npool.release(object);\n```\n\n#### reserveN\n\nReserves multiple objects from the pool. If no objects remain to be reserved, it will create new ones for you based on the [`create`](#create) method from [options](#pool-options).\n\n```typescript\nconst object = pool.reserveN(10);\n```\n\n#### releaseN\n\nReleases multiple objects back to the pool from where it came from.\n\n```typescript\npool.releaseN([object, anotherObject]);\n```\n\n#### reset\n\nResets the pool to its initial state, which is based on the [`initialSize`](#initialsize) value from [options](#options).\n\n```typescript\npool.reset();\n```\n\n## Pool values\n\n#### available\n\nThe number of objects in the pool available for reservation.\n\n#### reserved\n\nThe number of objects in the pool unavailable because they are reserved.\n\n#### size\n\nThe total number of objects in the pool, regardless of reservation status.\n\n## Development\n\nStandard stuff, clone the repo and `npm install` dependencies. The npm scripts available:\n\n- `benchmark` =\u003e run the benchmark suite pitting `moize` against other libraries in common use-cases\n- `build` =\u003e run rollup to build the distributed files in `dist`\n- `clean` =\u003e run `rimraf` on the `dist` folder\n- `dev` =\u003e run webpack dev server to run example app (playground!)\n- `dist` =\u003e runs `clean` and `build`\n- `lint` =\u003e runs ESLint against all files in the `src` folder\n- `lint:fix` =\u003e runs `lint``, fixing any errors if possible\n- `prepublish` =\u003e runs `compile-for-publish`\n- `prepublish:compile` =\u003e run `lint`, `test:coverage`, and `dist`\n- `test` =\u003e run test functions with `NODE_ENV=test`\n- `test:coverage` =\u003e run `test` but with `nyc` for coverage checker\n- `test:watch` =\u003e run `test`, but with persistent watcher\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplanttheidea%2Fnage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplanttheidea%2Fnage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplanttheidea%2Fnage/lists"}