JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1938
  • Score
    100M100P100Q111794F
  • License MIT

Make it no pain to create a Buffer object by encapsulate Buffer.from an new Buffer().

Package Exports

  • buffer-factory

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (buffer-factory) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Buffer Factory - (中文版README)

buffer-factory makes it no pain to create a Buffer object by encapsulate Buffer.from an new Buffer().

This module has been well unit tested and documented.

Usage

install

npm i buffer-factory

use

const bufferFactory = require('buffer-factory')
bufferFactory('2b', 'hex')

Implementation

If Buffer.from is accessible, this module is preffered to use it.

Buffer.from is added from v5.10.0, as the api document shows. But some node version, v4.2.6 for example, Buffer.from is a function, however, there is an error when you call Buffer.from(string, encoding)(error like hex is not function). So I also take the node version into account.

For low versions of Node.js, this module use new Buffer(...).

You're free to pass in the same params as Buffer.from(...) and new Buffer(...), I will handle the rest for you.

You're also free to check index.js for the implementation code :).