APG Converter API
raw JSON →apg-conv-api is a JavaScript library that provided an API for converting integer arrays to encoded byte streams (Node.js Buffers) and vice versa. It also exposed low-level transformation functions for encoding and decoding, and was bundled for use in both Node.js and browser environments. The package is officially deprecated as of version 1.0.1, with its functionality superseded by `apg-js`. Developers are strongly advised to migrate to `apg-js` for ongoing support and new features. The package's release cadence was tied to its companion `apg-conv` library, but is now effectively halted due to its deprecated status. Its key differentiator was providing direct programmatic access to the `apg-conv` core conversion logic for various data types.
Common errors
error TypeError: apgConv.converter.decode is not a function ↓
const apgConv = require('apg-conv-api'); is at the top of your Node.js file, or that the script tag for apg-conv-api.js is included in your HTML before calling apgConv in a browser. error ERR_REQUIRE_ESM: require() of ES Module ... not supported ↓
import() or, preferably, migrate to the apg-js package which offers ES Module support. Warnings
deprecated The `apg-conv-api` package is officially deprecated. Users should migrate to `apg-js` for all current and future development. ↓
gotcha This package is designed for CommonJS (Node.js `require`) and global browser usage. It does not provide native ES Module (ESM) support. ↓
breaking Future compatibility with newer Node.js versions or browser environments is not guaranteed due to the package's deprecated status and lack of maintenance. ↓
Install
npm install apg-conv-api yarn add apg-conv-api pnpm add apg-conv-api Imports
- apgConv wrong
import apgConv from 'apg-conv-api';correctconst apgConv = require('apg-conv-api'); - apgConv.converter.decode wrong
import { converter } from 'apg-conv-api';correctconst { converter } = require('apg-conv-api'); const decoded = converter.decode("UTF8", chars); - apgConv (global in browser)
<!-- In HTML --> <script src="./apg-conv-api.js"></script> <script> const buf = apgConv.converter.decode("UTF8", chars); </script>
Quickstart
const apgConv = require('apg-conv-api');
// Example: Define some characters (e.g., Unicode code points)
const chars = [0x41, 0x42, 0x43, 0xE2, 0x82, 0xAC]; // 'ABC€' in UTF-8 code points
console.log('Original character array:', chars);
// Encode to a Buffer (UTF8)
const buffer = apgConv.converter.encode('UTF8', chars);
console.log('Encoded Buffer:', buffer);
console.log('Buffer as string:', buffer.toString('utf8'));
// Decode back to an array of integers (UTF8)
const decodedChars = apgConv.converter.decode('UTF8', buffer);
console.log('Decoded character array:', decodedChars);