{"id":11607,"library":"pvtsutils","title":"Peculiar Ventures TypeScript Utilities (pvtsutils)","description":"pvtsutils is a utility library designed for TypeScript-based projects, offering a suite of common helper functions for data manipulation. Key functionalities include robust ArrayBuffer conversions, enabling seamless transformation between various string encodings such as hexadecimal, UTF-8, binary, Base64, and Base64Url. Additionally, it provides utilities for combining multiple ArrayBuffer instances, performing deep equality checks on buffers, and handling object property assignment akin to Object.assign. The library is currently stable at version 1.3.6, with consistent maintenance reflected in recent minor updates to its Convert class functionality. While it is built with TypeScript, its module system primarily supports CommonJS and UMD patterns, making it compatible with Node.js environments via require() and browser environments through script tags or AMD loaders. This design choice differentiates it from many modern ESM-first libraries, offering broad compatibility for existing codebases. Its focused approach on ArrayBuffer operations makes it particularly useful in cryptographic contexts, data processing pipelines, and other scenarios requiring low-level binary data handling.","status":"active","version":"1.3.6","language":"javascript","source_language":"en","source_url":"https://github.com/PeculiarVentures/pvtsutils","tags":["javascript","typescript","helper","util","convert","hex","utf8","utf16","base64"],"install":[{"cmd":"npm install pvtsutils","lang":"bash","label":"npm"},{"cmd":"yarn add pvtsutils","lang":"bash","label":"yarn"},{"cmd":"pnpm add pvtsutils","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library uses 'export = pvtsutils;' for CommonJS/UMD, requiring a namespace import in ESM/TypeScript. Direct named imports are not supported without bundler configuration.","wrong":"import { Convert, assign } from 'pvtsutils';","symbol":"pvtsutils","correct":"import * as pvtsutils from 'pvtsutils';"},{"note":"This is the native and fully supported import method for Node.js CommonJS environments.","symbol":"pvtsutils (CommonJS)","correct":"const pvtsutils = require('pvtsutils');"},{"note":"Access members like 'Convert' from the imported 'pvtsutils' namespace.","wrong":"import { Convert } from 'pvtsutils';","symbol":"Convert class","correct":"import * as pvtsutils from 'pvtsutils';\nconst { Convert } = pvtsutils;"}],"quickstart":{"code":"import * as pvtsutils from 'pvtsutils';\n\nconst { Convert, assign, combine, isEqual } = pvtsutils;\n\n// 1. Convert strings to ArrayBuffer and back\nconst hexString = '736f6d6520737472696e67'; // 'some string'\nconst bufFromHex = Convert.FromString(hexString, 'hex');\nconsole.log(`Buffer from hex: ${new Uint8Array(bufFromHex)}`);\n\nconst utf8String = Convert.ToString(bufFromHex, 'utf8');\nconsole.log(`UTF-8 string from buffer: '${utf8String}'`);\n\nconst base64UrlString = Convert.ToString(bufFromHex, 'base64url');\nconsole.log(`Base64URL string from buffer: '${base64UrlString}'`);\n\n// 2. Assign properties to an object\nconst obj1 = { id: 1 };\nconst obj2 = { name: 'Bob' };\nconst obj3 = { age: 30, city: 'New York' };\nconst mergedObj = assign({}, obj1, obj2, obj3);\nconsole.log('Merged Object:', mergedObj);\n\n// 3. Combine ArrayBuffers\nconst bufferPart1 = new Uint8Array([1, 2, 3]).buffer;\nconst bufferPart2 = new Uint8Array([4, 5, 6]).buffer;\nconst combinedBuffer = combine(bufferPart1, bufferPart2);\nconsole.log(`Combined Buffer: ${new Uint8Array(combinedBuffer)}`);\n\n// 4. Compare ArrayBuffers\nconst sameBuffer = combine(bufferPart1, bufferPart2);\nconst areEqual = isEqual(combinedBuffer, sameBuffer);\nconsole.log(`Are combined buffers equal? ${areEqual}`);","lang":"typescript","description":"Demonstrates `Convert` for encoding/decoding, `assign` for object merging, `combine` for buffer concatenation, and `isEqual` for buffer comparison."},"warnings":[{"fix":"Use a namespace import: `import * as pvtsutils from 'pvtsutils';` in ESM/TypeScript, or `const pvtsutils = require('pvtsutils');` in CommonJS. Then access members as `pvtsutils.Convert`, `pvtsutils.assign`, etc.","message":"Despite being a TypeScript library, pvtsutils uses a CommonJS/UMD export style (`export = pvtsutils;`). This means direct named ESM imports like `import { Convert } from 'pvtsutils';` will not work out-of-the-box and typically result in a module resolution error.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always specify the correct encoding string (e.g., 'hex', 'utf8', 'binary', 'base64', 'base64url') based on the input data format. UTF-8 is the default if no encoding is provided.","message":"When working with `Convert.FromString` or `Convert.ToString`, ensure the encoding type matches the data. Passing incorrect encodings (e.g., 'hex' for a UTF-8 string) will lead to incorrect or corrupt data conversions without throwing explicit errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Correct the import statement to `import * as pvtsutils from 'pvtsutils';` and then access `pvtsutils.Convert.FromString(...)`.","cause":"Attempting to use `Convert` or other utilities directly after an incorrect ESM named import.","error":"TypeError: Cannot read properties of undefined (reading 'FromString') OR TypeError: pvtsutils.Convert is not a constructor"},{"fix":"For CommonJS environments, ensure you use `const pvtsutils = require('pvtsutils');`. If using ESM, use `import * as pvtsutils from 'pvtsutils';` and ensure your `tsconfig.json` and build setup are correctly configured for CJS interoperability.","cause":"This error is unlikely for pvtsutils itself (as it's CJS-first), but could occur if bundling tools incorrectly interpret it as ESM when it's consumed by a CJS module. More likely: `import ... from 'pvtsutils'` in CJS code.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ...pvtsutils/lib/index.js not supported"}],"ecosystem":"npm"}