Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dqbd/tiktoken

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dqbd/tiktoken - npm Package Compare versions

Comparing version 1.0.0-alpha.1 to 1.0.0-alpha.2

bundler.d.ts

73

package.json
{
"name": "@dqbd/tiktoken",
"version": "1.0.0-alpha.1",
"version": "1.0.0-alpha.2",
"description": "Javascript bindings for tiktoken",
"license": "MIT",
"scripts": {
"build": "run-s build:*",
"build:cleanup": "rm -rf dist/",
"build:rank": "tsx scripts/inline_ranks.ts",
"build:wasm": "run-s wasm:*",
"build:postprocess": "tsx scripts/post_process.ts",
"wasm:bundler": "wasm-pack build --target bundler --release --out-dir dist && rm -rf dist/.gitignore dist/README.md dist/package.json",
"wasm:node": "wasm-pack build --target nodejs --release --out-dir dist/node && rm -rf dist/node/.gitignore dist/node/README.md dist/node/package.json",
"test": "yarn vitest"
},
"repository": {

@@ -21,10 +11,55 @@ "type": "git",

"dependencies": {},
"devDependencies": {
"@types/node": "^18.14.4",
"npm-run-all": "^4.1.5",
"ts-morph": "^17.0.1",
"tsx": "^3.12.3",
"typescript": "^4.9.5",
"vitest": "^0.28.5"
"files": [
"**/*"
],
"main": "tiktoken.cjs",
"types": "tiktoken.d.ts",
"exports": {
".": {
"types": "./tiktoken.d.ts",
"node": "./tiktoken.cjs",
"default": "./tiktoken.js"
},
"./bundler": {
"types": "./bundler.d.ts",
"default": "./bundler.js"
},
"./init": {
"types": "./init.d.ts",
"node": "./init.cjs",
"default": "./init.js"
},
"./load": {
"types": "./load.d.ts",
"node": "./load.cjs",
"default": "./load.js"
},
"./tiktoken_bg.wasm": {
"types": "./tiktoken_bg.wasm.d.ts",
"default": "./tiktoken_bg.wasm"
},
"./lite": {
"types": "./lite/tiktoken.d.ts",
"node": "./lite/tiktoken.cjs",
"default": "./lite/tiktoken.js"
},
"./lite/bundler": {
"types": "./lite/bundler.d.ts",
"default": "./lite/bundler.js"
},
"./lite/init": {
"types": "./lite/init.d.ts",
"node": "./lite/init.cjs",
"default": "./lite/init.js"
},
"./lite/load": {
"types": "./lite/load.d.ts",
"node": "./lite/load.cjs",
"default": "./lite/load.js"
},
"./lite/tiktoken_bg.wasm": {
"types": "./lite/tiktoken_bg.wasm.d.ts",
"default": "./lite/tiktoken_bg.wasm"
}
}
}
}

@@ -56,11 +56,11 @@ # ⏳ tiktoken

| Runtime | Status | Notes |
| ------------------- | ------ | ------------------------------------------ |
| Node.js | ✅ | |
| Bun | ✅ | |
| Vite | ✅ | See [here](#vite) for notes |
| Next.js | ✅ | See [here](#nextjs) for notes |
| Vercel Edge Runtime | ✅ | See [here](#vercel-edge-runtime) for notes |
| Cloudflare Workers | 🚧 | Untested |
| Deno | ❌ | Currently unsupported |
| Runtime | Status | Notes |
| ------------------- | ------ | ------------------------------------------- |
| Node.js | ✅ | |
| Bun | ✅ | |
| Vite | ✅ | See [here](#vite) for notes |
| Next.js | ✅ | See [here](#nextjs) for notes |
| Vercel Edge Runtime | ✅ | See [here](#vercel-edge-runtime) for notes |
| Cloudflare Workers | 🚧 | See [here](#cloudflare-workers) for caveats |
| Deno | ❌ | Currently unsupported |

@@ -133,4 +133,34 @@ ### [Vite](#vite)

### [Cloudflare Workers](#cloudflare-workers)
Similar to Vercel Edge Runtime, Cloudflare Workers must import the WASM binary file manually. However, users need to point directly at the WASM binary, including `node_modules` prefix in some cases.
Add the following rule to the `wrangler.toml` to upload WASM during build:
```toml
[[rules]]
globs = ["**/*.wasm"]
type = "CompiledWasm"
```
Initialize the encoder with the following snippet:
```javascript
import wasm from "./node_modules/@dqbd/tiktoken/tiktoken_bg.wasm";
import { get_encoding, init } from "@dqbd/tiktoken/init";
export default {
async fetch() {
await init((imports) => WebAssembly.instantiate(wasm, imports));
const encoder = get_encoder("cl100k_base");
const tokens = encoder.encode("hello world");
encoder.free();
return new Response(`${tokens}`);
},
};
```
## Acknowledgements
- https://github.com/zurawiki/tiktoken-rs
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc