Major release: standards-compliant v3/v5, new v6/v7, secure random values on React Native without a polyfill, and an ES module build.
Tested on React Native 0.88.1 (iOS and Android, New Architecture, including Android R8) and Expo SDK 58 (development build and Expo Go).
Migrating from 2.x
v3()andv5()return different values. 2.x produced non-standard UUIDs (#52); 3.x matches RFC 9562, theuuidpackage and Python. Re-generate any stored v3/v5 UUIDs, or keep 2.x for reading old ones.parse()throwsTypeError('Invalid UUID')for invalid input instead of returning zero-filled bytes. Callvalidate()first if input may be invalid.v3()/v5()also throw for an invalid namespace string.- Deep imports are no longer supported (e.g.
react-native-uuid/dist/v4). Import fromreact-native-uuidinstead. validate()accepts versions 6-8 and the max UUID (ffffffff-ffff-ffff-ffff-ffffffffffff).- Node.js 22+ is required.
- React Native: run
pod installand rebuild the app to link the native random module.
Changes
Breaking
v3()andv5()now return RFC 9562 compliant UUIDs that match theuuidnpm package and Python'suuidmodule. Previously the hex text of the hash digest was used as the UUID bytes, so every v3/v5 value differs from 2.x. Re-generate any stored v3/v5 UUIDs. (#52, #18)parse()throwsTypeError('Invalid UUID')for invalid input instead of returning zero-filled bytes.v3()andv5()throw the same error for an invalid namespace string.validate()andversion()accept UUID versions 6-8 and the max UUID.- The package uses an
exportsmap. Deep imports such asreact-native-uuid/dist/v4no longer work; import fromreact-native-uuid. Internal helpers that were only reachable that way (md5,sha1,bytesToString, etc.) were removed or replaced. - Build output moved to
dist/cjs(CommonJS) anddist/esm(ES modules). v4()no longer accepts the legacy stringformatargument.- Minimum Node.js version is now 22 (npm 10). Node.js 18 and 20 are end-of-life; CI tests Node.js 22, 24 and 26 and publishes with 26.
- React Native 0.74 or newer is required (declared as an optional peer dependency). React Native apps need
pod installand a native rebuild to link the new native random module.
Added
v6()andv7()(RFC 9562), plusv1ToV6()andv6ToV1(). Output matches theuuidpackage;v7()is strictly increasing within a process.MAXconstant, andv3.DNS/v3.URL/v5.DNS/v5.URLproperties, matchinguuid.stringify(),rng()andrandomSource()exported from the package entry point.- Named exports (
import {v4} from 'react-native-uuid') alongside the defaultuuidobject, so bundlers can drop unused code. - ES module build, with type declarations for both CommonJS and ESM consumers.
- Exported types:
V1Options,V4Options,V6Options,V7Options,UUIDBuffer,GenerateUUID. v3()/v5()accept a plain number array as the name.- API docs (
docs/) regenerated for the public API with descriptions for every function.npm run docsworks again (config intypedoc.json).
Changed
- Generators return
stringwhen called withoutbufand the buffer's type when called with one, soas stringcasts are no longer needed. bufacceptsnumber[]orUint8Arrayfor every generator. Writing past the end of aUint8Array, or at a negative offset, throwsRangeError.v4()no longer modifies theoptions.randomarray passed in, and throws if it has fewer than 16 bytes.- Faster:
v3()/v5()~3-4x,parse()~3.5x,v4()~1.5x (usescrypto.randomUUIDwhen available) compared with 2.x. Random bytes fromcrypto.getRandomValuesare fetched in 256-byte batches. - MD5 and SHA-1 rewritten to operate on bytes (verified against RFC 1321 / FIPS 180 vectors and Node.js
crypto).
Security
rng()(used byv1(),v4(),v6()andv7()) uses, in order:crypto.getRandomValues; a bundled native module on React Native (iOSSecRandomCopyBytes, AndroidSecureRandom), so apps are secure without a polyfill;Math.randomonly as a last resort.- npm releases are published from CI with trusted publishing (OIDC) and provenance, without a long-lived npm token.
Fixed
v1()without options no longer throws "Can't create more than 10M uuids/sec" after ~10,000 calls.v1()honorsclockseq: 0,msecs: 0andnsecs: 0instead of replacing them with defaults.v3()/v5()no longer overflow the stack for names larger than ~100 KB.V1OptionsandV4Optionsfields are optional, so partial options type-check.v4()prefersoptions.randomoveroptions.rng, matchinguuid.- The CI publish job now runs on
v*tag pushes; previously the workflow never triggered on tags.
Tooling and maintenance
ESLint 10, Jest 30, TypeScript 5.9, TypeDoc 0.28; dual CommonJS/ESM build; package, bundle-size and coverage checks in CI; trusted publishing with provenance. See CHANGELOG.md for the full list.