{"_id":"es-intrinsic-cache","_rev":"4-89f9e3126249d318b20cd7d8f67b7c87","name":"es-intrinsic-cache","dist-tags":{"latest":"1.0.4"},"versions":{"1.0.0":{"name":"es-intrinsic-cache","version":"1.0.0","keywords":["intrinsic","intrinsics","cache","es-abstract","javascript","ecmascript","es","js","getintrinsic"],"author":{"name":"Fox Jones"},"license":"MIT","_id":"es-intrinsic-cache@1.0.0","maintainers":[{"name":"xsfj","email":"oagde5@gmail.com"}],"homepage":"https://github.com/xsfj/es-intrinsic-cache#readme","bugs":{"url":"https://github.com/xsfj/es-intrinsic-cache/issues"},"dist":{"shasum":"4a7b577e95af3c1218ebdb3928d6aeb2d8ba7627","tarball":"https://registry.npmjs.org/es-intrinsic-cache/-/es-intrinsic-cache-1.0.0.tgz","fileCount":7,"integrity":"sha512-qQMXhWkF9BEykbmCyCxBh4jH81j3n8bFmKXooUmYnbMCj+/2NSj4Tv1ln7ZKfsr+55Xm2srBqx1XEH1OM2ztzA==","signatures":[{"sig":"MEUCIQDlrvIcV9soU7r4WRI8HGljMTCsLYGDcnK/RBX1SfHTDAIgMktlFo1PKK4ZUMOhMH7TMu42QYY31JcP4yMgyhMD+nw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":50091},"main":"index.js","type":"commonjs","types":"./index.d.ts","gitHead":"2ce18e9efd2000ba6fb2e1c909db69ab27432dba","scripts":{"lint":"biome lint .","test":"npm run types && nyc tape test/test.js","check":"npm run types && biome check .","types":"node tools/generate-typescript-definitions.js > index.d.ts && echo Type definitions generated.","format":"biome format --write .","lint:fix":"biome lint --write .","check:fix":"npm run types && biome check --write .","prepublishOnly":"npm run check:fix"},"_npmUser":{"name":"xsfj","email":"oagde5@gmail.com"},"repository":{"url":"git+https://github.com/xsfj/es-intrinsic-cache.git","type":"git"},"_npmVersion":"11.6.2","description":"Get the pristine, unmodified JavaScript built-ins and cache them before anyone can tamper with them","directories":{},"_nodeVersion":"24.11.1","dependencies":{"gopd":"^1.2.0","hasown":"^2.0.2","get-proto":"^1.0.1","function-bind":"^1.1.2","async-function":"^1.0.0","es-object-atoms":"^1.1.1","function.call-x":"^1.0.0","math-intrinsics":"^1.1.0","function.apply-x":"^1.0.0","es-define-property":"^1.0.1","generator-function":"^2.0.1","es-error-intrinsics":"^1.0.0","has-symbol-support-x":"^1.4.2","async-generator-function":"^1.0.0"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^17.1.0","tape":"^5.9.0","for-each":"^0.3.5","call-bound":"^1.0.4","es-abstract":"^1.24.1","mock-property":"^1.1.0","@biomejs/biome":"^2.3.10","object-inspect":"^1.13.4","es-value-fixtures":"^1.7.1","make-async-function":"^1.0.0","make-generator-function":"^2.1.0","make-async-generator-function":"^1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/es-intrinsic-cache_1.0.0_1766360959281_0.8150122243264726","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"es-intrinsic-cache","version":"1.0.1","keywords":["intrinsic","intrinsics","cache","es-abstract","javascript","ecmascript","es","js","getintrinsic"],"author":{"name":"Fox Jones"},"license":"MIT","_id":"es-intrinsic-cache@1.0.1","maintainers":[{"name":"xsfj","email":"oagde5@gmail.com"}],"homepage":"https://github.com/xsfj/es-intrinsic-cache#readme","bugs":{"url":"https://github.com/xsfj/es-intrinsic-cache/issues"},"dist":{"shasum":"07d9b741077535c811467391f3a142b90cbad8f8","tarball":"https://registry.npmjs.org/es-intrinsic-cache/-/es-intrinsic-cache-1.0.1.tgz","fileCount":10,"integrity":"sha512-aWPN1psoCyrMMWRspy1ZvdiHx7pJJNgJ88P+v20cwVbfdpsluEfm1mrLegZePTQj+QejPF6xdNwEZm0pQdQI1w==","signatures":[{"sig":"MEUCIE2i4n0Fx7bT0wKA3ty+WUYBiQHF+78EbJ6ptVUikKGTAiEAuwDn2JZnTM3jt7/CBm9MNDx9WdmZZPbQQ18+ZlxA/64=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":67373},"main":"index.js","type":"commonjs","types":"./index.d.ts","exports":"./index.js","gitHead":"078a4ec21bba9954319a1a01378195cd8fd74b65","scripts":{"lint":"biome lint .","test":"npm run types && nyc tape test/test.js","check":"npm run types && biome check .","types":"node tools/generate-typescript-definitions.js > index.d.ts && echo Type definitions generated.","format":"biome format --write .","lint:fix":"biome lint --write .","check:fix":"npm run types && biome check --write .","prepublishOnly":"npm run check:fix"},"_npmUser":{"name":"xsfj","email":"oagde5@gmail.com"},"repository":{"url":"git+https://github.com/xsfj/es-intrinsic-cache.git","type":"git"},"_npmVersion":"11.6.2","description":"Get the pristine, unmodified JavaScript built-ins and cache them before anyone can tamper with them","directories":{},"_nodeVersion":"24.11.1","dependencies":{"gopd":"^1.2.0","hasown":"^2.0.2","get-proto":"^1.0.1","function-bind":"^1.1.2","async-function":"^1.0.0","es-object-atoms":"^1.1.1","function.call-x":"^1.0.0","math-intrinsics":"^1.1.0","function.apply-x":"^1.0.0","es-define-property":"^1.0.1","generator-function":"^2.0.1","es-error-intrinsics":"^1.0.0","has-symbol-support-x":"^1.4.2","async-generator-function":"^1.0.0"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^17.1.0","tape":"^5.9.0","for-each":"^0.3.5","call-bound":"^1.0.4","es-abstract":"^1.24.1","mock-property":"^1.1.0","@biomejs/biome":"^2.3.10","object-inspect":"^1.13.4","es-value-fixtures":"^1.7.1","make-async-function":"^1.0.0","make-generator-function":"^2.1.0","make-async-generator-function":"^1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/es-intrinsic-cache_1.0.1_1766420058964_0.6094017384839132","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"es-intrinsic-cache","version":"1.0.3","keywords":["intrinsic","intrinsics","cache","es-abstract","javascript","ecmascript","es","js","getintrinsic"],"author":{"name":"Fox Jones"},"license":"MIT","_id":"es-intrinsic-cache@1.0.3","maintainers":[{"name":"xsfj","email":"oagde5@gmail.com"}],"homepage":"https://github.com/xsfj/es-intrinsic-cache#readme","bugs":{"url":"https://github.com/xsfj/es-intrinsic-cache/issues"},"dist":{"shasum":"c5a6814627d92a189a3587c4d437c5d77e59c91a","tarball":"https://registry.npmjs.org/es-intrinsic-cache/-/es-intrinsic-cache-1.0.3.tgz","fileCount":8,"integrity":"sha512-p+lTv9Vjw4jdZNUzkJSPFxMxaPBlfH4tAuDnwB+BU65X0nHt8vnLQVbkOrRoenAa7P5Xvt9rl7GLU4DQxIBfeg==","signatures":[{"sig":"MEYCIQCDRjWdHbd8I50LYJV07tFAYyMSu/50/qTg5E8e5r70oQIhANuT2YSuSwk9OysAe/I/4wHK6fUcUQkSULgdbvxWsRW2","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":51340},"main":"index.js","type":"commonjs","types":"./index.d.ts","exports":"./index.js","gitHead":"1578ac97941454301cd0c99715e37d185ca71e26","scripts":{"lint":"biome lint .","check":"biome check .","format":"biome format --write .","lint:fix":"biome lint --write .","check:fix":"biome check --write ."},"_npmUser":{"name":"xsfj","email":"oagde5@gmail.com"},"repository":{"url":"git+https://github.com/xsfj/es-intrinsic-cache.git","type":"git"},"_npmVersion":"11.6.2","description":"Get the pristine, unmodified JavaScript built-ins and cache them before anyone can tamper with them","directories":{},"_nodeVersion":"24.12.0","dependencies":{"gopd":"^1.2.0","hasown":"^2.0.2","get-proto":"^1.0.1","function-bind":"^1.1.2","async-function":"^1.0.0","es-object-atoms":"^1.1.1","function.call-x":"^1.0.0","math-intrinsics":"^1.1.0","function.apply-x":"^1.0.0","es-define-property":"^1.0.1","generator-function":"^2.0.1","es-error-intrinsics":"^1.0.0","has-symbol-support-x":"^1.4.2","async-generator-function":"^1.0.0"},"_hasShrinkwrap":false,"devDependencies":{"@biomejs/biome":"^2.3.10"},"_npmOperationalInternal":{"tmp":"tmp/es-intrinsic-cache_1.0.3_1768251130040_0.985633812013589","host":"s3://npm-registry-packages-npm-production"}},"1.0.4":{"name":"es-intrinsic-cache","version":"1.0.4","description":"Get the pristine, unmodified JavaScript built-ins and cache them before anyone can tamper with them","keywords":["intrinsic","intrinsics","cache","es-abstract","javascript","ecmascript","es","js","getintrinsic"],"homepage":"https://github.com/xsfj/es-intrinsic-cache#readme","bugs":{"url":"https://github.com/xsfj/es-intrinsic-cache/issues"},"repository":{"type":"git","url":"git+https://github.com/xsfj/es-intrinsic-cache.git"},"license":"MIT","author":{"name":"Fox Jones"},"type":"commonjs","main":"index.js","exports":"./index.js","scripts":{"lint":"biome lint .","lint:fix":"biome lint --write .","format":"biome format --write .","check":"biome check .","check:fix":"biome check --write ."},"dependencies":{"async-function":"^1.0.0","async-generator-function":"^1.0.0","es-define-property":"^1.0.1","es-error-intrinsics":"^1.0.0","es-object-atoms":"^1.1.1","function-bind":"^1.1.2","function.apply-x":"^1.0.0","function.call-x":"^1.0.0","generator-function":"^2.0.1","get-proto-x":"^1.0.0","gopd":"^1.2.0","has-symbol-support-x":"^1.4.2","hasown":"^2.0.2","math-intrinsics":"^1.1.0","object.getprototypeof-x":"^1.0.0","reflect.getprototypeof-x":"^1.0.0"},"devDependencies":{"@biomejs/biome":"^2.3.10"},"gitHead":"711447845245e518547e8ce13c11e2bfd6d6a553","types":"./index.d.ts","_id":"es-intrinsic-cache@1.0.4","_nodeVersion":"24.12.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-zU7ooNCIzx1v9cBqJy8gXSiFKC8r1FLFiCe8pRrDmOwNuc0cMxYLNjO4p07DH7fQONvJKVAwy5HNdBPoy3XuEQ==","shasum":"324338977faa12f683259a5a5e8cd4aa6315c73f","tarball":"https://registry.npmjs.org/es-intrinsic-cache/-/es-intrinsic-cache-1.0.4.tgz","fileCount":8,"unpackedSize":51487,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIHXUPwz3SVWvIWppNpDHVtGomxIc36aWxbaIwwUbup0zAiEAuWyVaNBXsBqkuI8B78JdYCBM7IyQHKi/MsxeVI0q5Fw="}]},"_npmUser":{"name":"xsfj","email":"oagde5@gmail.com"},"directories":{},"maintainers":[{"name":"xsfj","email":"oagde5@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/es-intrinsic-cache_1.0.4_1768340104325_0.7638363165246393"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-21T23:49:19.280Z","modified":"2026-01-13T21:35:04.596Z","1.0.0":"2025-12-21T23:49:19.414Z","1.0.1":"2025-12-22T16:14:19.126Z","1.0.3":"2026-01-12T20:52:10.186Z","1.0.4":"2026-01-13T21:35:04.456Z"},"bugs":{"url":"https://github.com/xsfj/es-intrinsic-cache/issues"},"author":{"name":"Fox Jones"},"license":"MIT","homepage":"https://github.com/xsfj/es-intrinsic-cache#readme","keywords":["intrinsic","intrinsics","cache","es-abstract","javascript","ecmascript","es","js","getintrinsic"],"repository":{"type":"git","url":"git+https://github.com/xsfj/es-intrinsic-cache.git"},"description":"Get the pristine, unmodified JavaScript built-ins and cache them before anyone can tamper with them","maintainers":[{"name":"xsfj","email":"oagde5@gmail.com"}],"readme":"# es-intrinsic-cache\r\n\r\n> Get and robustly cache all JavaScript language-level intrinsics at first require time\r\n\r\n[![npm version](https://img.shields.io/npm/v/es-intrinsic-cache.svg)](https://www.npmjs.com/package/es-intrinsic-cache)\r\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\r\n\r\n## What is this?\r\n\r\n`es-intrinsic-cache` provides safe, cached access to JavaScript's built-in objects and functions (intrinsics) before they can be modified by other code. This is essential for building robust libraries that need to rely on pristine versions of native JavaScript functionality.\r\n\r\n## Why would you need this?\r\n\r\nJavaScript allows modification of built-in prototypes and globals, which can break your code:\r\n\r\n```javascript\r\n// Malicious or buggy code could do this:\r\nArray.prototype.push = function() { \r\n  console.log(\"hacked\") \r\n}\r\n\r\n// Now normal array operations break:\r\nconst arr = [1, 2, 3]\r\narr.push(4) // Logs \"hacked\" instead of working correctly\r\nconsole.log(arr) // Logs [1,2,3] - nothing actually modified\r\n```\r\n\r\n`es-intrinsic-cache` solves this by caching the original intrinsics when your module first loads:\r\n\r\n```javascript\r\nconst GetIntrinsic = require(\"es-intrinsic-cache\")\r\n\r\n// Hack the Array.prototype.push\r\nArray.prototype.push = function() { \r\n  console.log(\"hacked\") \r\n}\r\n\r\n// Get the REAL Array.prototype.push, cached at module load time\r\nconst $push = GetIntrinsic(\"%Array.prototype.push%\")\r\n\r\n// This always works, even if Array.prototype.push was modified\r\nconst arr = [1, 2, 3]\r\n$push.call(arr, 4) // ✅ Works correctly\r\nconsole.log(arr) // Logs [1, 2, 3, 4]\r\n```\r\n\r\n## Installation\r\n\r\nUsing NPM:\r\n```bash\r\nnpm install es-intrinsic-cache\r\n```\r\n\r\nUsing Yarn:\r\n```bash\r\nyarn add es-intrinsic-cache\r\n```\r\n\r\nUsing PNPM:\r\n```bash\r\npnpm add es-intrinsic-cache\r\n```\r\n\r\nUsing Bun:\r\n```bash\r\nbun add es-intrinsic-cache\r\n```\r\n\r\n## Usage\r\n\r\n```javascript\r\nconst GetIntrinsic = require(\"es-intrinsic-cache\")\r\n\r\n// Access intrinsics with % wrapper syntax\r\nconst ArrayProto = GetIntrinsic(\"%Array.prototype%\")\r\nconst ObjectCreate = GetIntrinsic(\"%Object.create%\")\r\nconst JSONParse = GetIntrinsic(\"%JSON.parse%\")\r\n\r\n// Or without % wrappers (they're optional)\r\nconst Array = GetIntrinsic(\"Array\")\r\nconst push = GetIntrinsic(\"Array.prototype.push\")\r\n```\r\n\r\n### Accessor Properties\r\n\r\nFor accessor properties (getters/setters), `GetIntrinsic` returns the getter function. (**Note**: If a getter is emulating a data property (indicated by an `originalValue` property on the getter), the actual value is returned instead.)\r\n\r\nExample:\r\n\r\n```javascript\r\nconst GetIntrinsic = require(\"es-intrinsic-cache\")\r\n\r\n// Get the getter for Map.prototype.size\r\nconst $mapSize = GetIntrinsic(\"%Map.prototype.size%\")\r\n\r\nconst myMap = new Map([[\"a\", 1], [\"b\", 2]])\r\nconsole.log($mapSize.call(myMap)) // 2\r\n```\r\n\r\n### `allowMissing` parameter\r\n\r\nSome intrinsics may not exist in all environments. Use the second parameter to avoid errors. This also applies to nested properties: if the base intrinsic exists but the requested property does not, it returns undefined instead of throwing.\r\n\r\n```javascript\r\nconst GetIntrinsic = require(\"es-intrinsic-cache\")\r\n\r\n// Throws TypeError if AsyncGeneratorPrototype doesn't exist\r\nconst AsyncGenProto = GetIntrinsic(\"%AsyncGeneratorPrototype%\")\r\n\r\n// Returns undefined if AsyncGeneratorPrototype doesn't exist\r\nconst AsyncGenProto = GetIntrinsic(\"%AsyncGeneratorPrototype%\", true)\r\n```\r\n\r\n## ⚠️ Important Note: Load Order Matters\r\n\r\n**`es-intrinsic-cache` must be loaded as early as possible in your application**, ideally before any other code runs. If other code modifies built-ins before `es-intrinsic-cache` is loaded, those modifications will be cached.\r\n\r\n```javascript\r\n// ✅ GOOD - Load es-intrinsic-cache first\r\nconst GetIntrinsic = require(\"es-intrinsic-cache\")\r\n// ... rest of your application\r\n\r\n// ❌ BAD - Other code runs first\r\nrequire(\"some-library-that-modifies-prototypes\")\r\nconst GetIntrinsic = require(\"es-intrinsic-cache\") // Too late!\r\n```\r\n\r\n## Available Intrinsics\r\n\r\nSee the full list of available intrinsics that you can cache with `es-intrinsic-cache` in the TypeScript definitions (`index.d.ts`).\r\n\r\n## API\r\n\r\n### `GetIntrinsic(name, [allowMissing])`\r\n\r\n**Parameters:**\r\n- `name` (string, required): The name of the intrinsic to retrieve. Can be wrapped in `%` or not.\r\n- `allowMissing` (boolean, optional): If `true`, returns `undefined` for missing intrinsics instead of throwing. Default: `false`\r\n\r\n**Returns:** The requested intrinsic value.\r\n\r\n**Throws:**\r\n- `TypeError` if `name` is not a non-empty string.\r\n- `TypeError` if `allowMissing` is not a boolean.\r\n- `SyntaxError` if `%` appears in the middle of the name (e.g., `%Array%.push`).\r\n- `SyntaxError` if quoted property paths have mismatched or invalid quotes.\r\n- `TypeError` if the intrinsic (or a base property) is missing/unavailable (unless `allowMissing` is true).\r\n\r\n\r\n## Common Use Case\r\n\r\n```javascript\r\nconst GetIntrinsic = require(\"es-intrinsic-cache\")\r\n\r\nconst susLibrary = require(\"sus-library\") // library that we're not sure about that might replace an intrinsic\r\n\r\nconst $JSONParse = GetIntrinsic(\"%JSON.parse%\")\r\nconst $ObjectKeys = GetIntrinsic(\"%Object.keys%\")\r\n\r\nfunction safeJSONParse(str) {\r\n  // Always uses pristine JSON.parse, even if JSON.parse was replaced\r\n  return $JSONParse(str)\r\n}\r\n```\r\n\r\n## Why `es-intrinsic-cache` instead of `get-intrinsic`?\r\n\r\n`es-intrinsic-cache` is a modernized refactor of `get-intrinsic` that maintains **100% API compatibility** while improving internal clarity, dependency focus, and developer experience. Both libraries cache JavaScript intrinsics to protect against prototype pollution, but they differ in implementation philosophy.\r\n\r\n### Key Advantages\r\n\r\n- **Cleaner internals** 🧹  \r\n  Removes the legacy `needsEval` / `doEval` mechanism and initializes intrinsics explicitly at module load time. This results in simpler, more readable code with less state-machine complexity.\r\n\r\n- **Complete TypeScript definitions** 🧠  \r\n  Includes **240+ fully typed intrinsics**, covering missing entries from `@types/get-intrinsic` (such as `%Float16Array%`, `%FinalizationRegistry%`, `%WeakRef%`, and legacy aliases). Types are auto-generated and always stay in sync with the implementation.\r\n\r\n- **Comprehensive JSDoc documentation** 📚  \r\n  Provides detailed JSDoc comments with parameter descriptions, edge cases, and examples, enabling better IDE hover docs and easier contributor onboarding.\r\n\r\n- **Smaller, more focused dependencies** 📦  \r\n  Uses single-responsibility helper modules instead of multi-purpose utilities, reducing unused code and dependency surface area.\r\n\r\n- **Identical public API** 🔁  \r\n  Fully compatible with `get-intrinsic`, including the same function signature, intrinsic naming syntax, legacy aliases, error handling, and edge-case protections.\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please:\r\n\r\n1. Fork the repository\r\n2. Create a feature branch\r\n3. Add tests for any new functionality\r\n4. Ensure all tests pass\r\n5. Submit a pull request\r\n\r\n## License\r\n\r\nMIT © Fox Jones\r\nSee license in [LICENSE](https://github.com/xsfj/es-intrinsic-cache/blob/main/LICENSE) (or don't, because it's just your regular MIT license)\r\n\r\n## Support\r\n\r\n- 🐛 [Report bugs](https://github.com/xsfj/es-intrinsic-cache/issues)\r\n- 💡 [Request features](https://github.com/xsfj/es-intrinsic-cache/issues)\r\n\r\n---\r\n\r\n**Remember**: Load `es-intrinsic-cache` early in your application to ensure you get pristine intrinsics! 🛡️","readmeFilename":"README.md"}