{"name":"isutf8","version":"4.0.3","keywords":["charset","utf-8","is utf","is utf-8","is utf8","utf8","unicode","is unicode","text","check","validate","encoding","Buffer","Uint8Array"],"author":{"url":"https://github.com/hcodes","name":"Denis Seleznev","email":"hcodes@yandex.ru"},"license":"MIT","_id":"isutf8@4.0.3","maintainers":[{"name":"hcodes","email":"hcodes@yandex.ru"}],"homepage":"https://github.com/hcodes/isutf8","bugs":{"url":"https://github.com/hcodes/isutf8/issues"},"dist":{"shasum":"acb78bea5184d23cf10c0e84d7eb1a752613ebe6","tarball":"http://registry-npm.ywwl.com/isutf8/download/isutf8-4.0.3.tgz","fileCount":6,"integrity":"sha512-zwkHmJVbjHmG4dEDFYYTgCDjnUKBLD2pmX4q5h69VI+DdkmcwuXyb/TQUB6kmFBSQXtX+FCRPoFrC4Kg3GLvFw==","signatures":[{"sig":"MEQCIDrQu7Qa7YsxRo04kSJutrWMJz5wdvVjzSjasWuM/Ol6AiBi5kxeiftVow3aB3ulZWCewJ6Y/otSW3AJTw7y10zyow==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIFMI1ZAUF+uljZLzY7zYH2NqUAYPepgp6dqhASHvompPAiEAoT00EvvuzplB1LZ41N1u9z8JUZiZjnFTi06Q6CG4u3k=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":11011,"size":3448,"noattachment":false,"key":"/isutf8/-/isutf8-4.0.3.tgz"},"main":"dist/index.js","module":"dist/index.esm.js","engines":{"node":">= 12"},"gitHead":"a35f69ec176a7fc5fa29d82e0d21f453e60ae925","scripts":{"test":"npm run eslint && npm run typecheck && npm run unit","unit":"jest --config ./jest.config.js","build":"npm run clean && rollup --config rollup.config.mjs","clean":"del-cli dist/*","eslint":"eslint --ext .ts","typecheck":"tsc --noEmit"},"typings":"dist/index.d.ts","_npmUser":{"name":"hcodes","email":"hcodes@yandex.ru"},"deprecated":"Use isUtf8 from node:buffer in modern Node.js, or TextDecoder with { fatal: true } in browsers.","repository":{"url":"git://github.com/hcodes/isutf8.git","type":"git"},"_npmVersion":"11.6.2","description":"Check if a Node.js Buffer or Uint8Array is UTF-8","directories":{},"_nodeVersion":"24.13.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^30.5.1","tslib":"^2.8.1","eslint":"^10.10.0","rollup":"^4.63.1","del-cli":"^7.0.0","globals":"^17.12.0","ts-jest":"^29.4.12","@eslint/js":"^10.0.1","typescript":"~6.0.3","@types/jest":"^30.0.0","@types/node":"^22.20.2","typescript-eslint":"^8.70.0","@rollup/plugin-typescript":"^12.3.0","@typescript-eslint/parser":"^8.70.0","@typescript-eslint/eslint-plugin":"^8.70.0"},"_npmOperationalInternal":{"tmp":"tmp/isutf8_4.0.3_1789156969187_0.1688075753314786","host":"s3://npm-registry-packages-npm-production"},"readme":"[![NPM Version](https://img.shields.io/npm/v/isutf8.svg?style=flat)](https://www.npmjs.org/package/isutf8)\n[![NPM Downloads](https://img.shields.io/npm/dm/isutf8.svg?style=flat)](https://www.npmjs.org/package/isutf8)\n[![install size](https://packagephobia.com/badge?p=isutf8)](https://packagephobia.com/result?p=isutf8)\n\nisutf8\n======\n\n> **Deprecated:** Use [`isUtf8` from `node:buffer`](https://nodejs.org/api/buffer.html#bufferisutf8input)\n> in Node.js, or [`TextDecoder`](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/decode)\n> with `{ fatal: true }` in browsers. See the migration examples below.\n\nQuick check if a Node.js Buffer or Uint8Array is valid UTF-8.\n\n## Advantages\n\n- Ultra-small package size\n- No runtime dependencies\n- No native compilation required\n\n## Migration to built-in APIs\n\nFor modern Node.js applications, prefer the built-in\n[`isUtf8` from `node:buffer`](https://nodejs.org/api/buffer.html#bufferisutf8input),\navailable since Node.js 18.14.0 and 19.4.0:\n\n```js\nimport { isUtf8 } from 'node:buffer';\n\nconsole.log(isUtf8(Buffer.from([0xd0, 0x90]))); // true\n```\n\nIn modern browsers, use\n[`TextDecoder`](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/decode)\nwith `fatal: true` to reject invalid UTF-8:\n\n```js\nfunction isUtf8(input) {\n  if (input === undefined) return false;\n\n  try {\n    new TextDecoder('utf-8', { fatal: true }).decode(input);\n    return true;\n  } catch (error) {\n    if (error instanceof TypeError) return false;\n    throw error;\n  }\n}\n\nconsole.log(isUtf8(new Uint8Array([0xd0, 0x90]))); // true\nconsole.log(isUtf8(new Uint8Array([0xc3]))); // false\n```\n\nUnlike a byte-only validator, `TextDecoder` also produces a decoded string.\nThis package mainly remains useful for older environments without these APIs\n(it supports Node.js 12 or later), or for retaining its existing API.\nWhen migrating, note that this package returns `false` for a missing argument,\nwhile Node.js's built-in `isUtf8` throws a `TypeError`.\n\n## Install\n\n```sh\nnpm install isutf8\n```\n\n## Usage\n\n### CommonJS\n\n```js\nconst isUtf8 = require('isutf8');\n\nconst buf = Buffer.from([0xd0, 0x90]);\nconsole.log(isUtf8(buf)); // true\n\n// or\n\nconst arr = new Uint8Array([0xd0, 0x90]);\nconsole.log(isUtf8(arr)); // true\n```\n\n### ES Modules or TypeScript\n\n```js\nimport isUtf8 from 'isutf8';\n\nconst buf = Buffer.from([0xd0, 0x90]);\nconsole.log(isUtf8(buf)); // true\n\n// or\n\nconst arr = new Uint8Array([0xd0, 0x90]);\nconsole.log(isUtf8(arr)); // true\n```\n\n## API\n\n`isUtf8(input?: Buffer | Uint8Array): boolean`\n\nReturns `true` for valid UTF-8 byte sequences, including ASCII and empty input.\nReturns `false` for invalid or incomplete sequences, or a missing argument.\nIt validates bytes; it does not detect the original encoding or decode text.\n\n```js\nconst isUtf8 = require('isutf8');\n\nconsole.log(isUtf8(new Uint8Array())); // true\nconsole.log(isUtf8(new Uint8Array([0xc3]))); // false: incomplete sequence\nconsole.log(isUtf8()); // false\n```\n\n## Development\n\nUse Node.js 22.13.0 or later in the Node.js 22 line, or Node.js 24 or later,\nfor the development tools.\n\n```sh\nnpm ci\nnpm test\nnpm run build\n```\n\nTypeScript is kept on 6.0.x because the current `typescript-eslint` and `ts-jest`\nreleases do not support TypeScript 7 yet.\n\n## License\n\n[MIT License](./LICENSE)\n","publish_time":1789156969281,"_cnpm_publish_time":1789156969281,"dist-tags":{"latest":"4.0.4"}}