diff --git a/README.md b/README.md index b8ebff8..33012a8 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,9 @@ receivingStream.on('data', (data) => { ``` The `PackrStream` and `UnpackrStream` instances will have also the record structure extension enabled by default (see below). +## Deno Usage +Msgpackr modules are standard ESM modules and can be loaded directly from github (https://raw.githubusercontent.com/kriszyp/msgpackr/master/index.js) or downloaded and used directly in Deno. The standard pack/encode and unpack/decode functionality is available on Deno, like other platforms. + ## Browser Usage Msgpackr works as standalone JavaScript as well, and runs on modern browsers. It includes a bundled script, at `dist/index.js` for ease of direct loading: ```html diff --git a/browser.js b/browser.js deleted file mode 100644 index 231215a..0000000 --- a/browser.js +++ /dev/null @@ -1,17 +0,0 @@ -exports.Packr = require('./pack').Packr -exports.Encoder = exports.Packr -exports.Unpackr = require('./unpack').Unpackr -exports.Decoder = exports.Unpackr -exports.addExtension = require('./pack').addExtension -let packr = new exports.Packr({ useRecords: false }) -exports.unpack = packr.unpack -exports.unpackMultiple = packr.unpackMultiple -exports.pack = packr.pack -exports.decode = packr.unpack -exports.encode = packr.pack -exports.FLOAT32_OPTIONS = require('./unpack').FLOAT32_OPTIONS -Object.assign(exports, { - ALWAYS:1, - DECIMAL_ROUND: 3, - DECIMAL_FIT: 4 -}) diff --git a/browser.mjs b/browser.mjs deleted file mode 100644 index c363dc4..0000000 --- a/browser.mjs +++ /dev/null @@ -1,21 +0,0 @@ -import packModule from './pack.js' -import unpackModule from './unpack.js' - -export const Packr = packModule.Packr -export const addExtension = packModule.addExtension -export const Encoder = packModule.Packr -export const Unpackr = unpackModule.Unpackr -export const Decoder = unpackModule.Unpackr -export const C1 = unpackModule.C1 -let packr = new packModule.Packr({ useRecords: false }) -export const unpack = packr.unpack -export const unpackMultiple = packr.unpackMultiple -export const pack = packr.pack -export const decode = packr.unpack -export const encode = packr.pack -export const useRecords = false -export const mapsAsObjects = true -export const FLOAT32_OPTIONS = unpackModule.FLOAT32_OPTIONS -export const ALWAYS = 1 -export const DECIMAL_ROUND = 3 -export const DECIMAL_FIT = 4 diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 42f4f96..0000000 --- a/index.mjs +++ /dev/null @@ -1,43 +0,0 @@ -import packModule from './pack.js' -import unpackModule from './unpack.js' -import { createRequire } from 'module' - -export const Packr = packModule.Packr -export const addExtension = packModule.addExtension -export const Encoder = packModule.Packr -let extractor = tryRequire('msgpackr-extract') -if (extractor) - unpackModule.setExtractor(extractor.extractStrings) -export const Unpackr = unpackModule.Unpackr -export const Decoder = unpackModule.Unpackr -export const C1 = unpackModule.C1 -import stream from './stream.js' -export const PackrStream = stream.PackrStream -export const UnpackrStream = stream.UnpackrStream -export const EncoderStream = stream.PackrStream -export const DecoderStream = stream.UnpackrStream -let packr = new packModule.Packr({ useRecords: false }) -export const unpack = packr.unpack -export const unpackMultiple = packr.unpackMultiple -export const pack = packr.pack -export const decode = packr.unpack -export const encode = packr.pack -export const useRecords = false -export const mapsAsObjects = true -export const FLOAT32_OPTIONS = unpackModule.FLOAT32_OPTIONS -export const ALWAYS = 1 -export const DECIMAL_ROUND = 3 -export const DECIMAL_FIT = 4 - - -function tryRequire(moduleId) { - try { - let require = createRequire(import.meta.url) - return require(moduleId) - } catch (error) { - if (typeof window == 'undefined') - console.warn('Native extraction module not loaded, msgpackr will still run, but with decreased performance. ' + error.message.split('\n')[0]) - else - console.warn('For browser usage, directly use msgpackr/unpack or msgpackr/pack modules. ' + error.message.split('\n')[0]) - } -} \ No newline at end of file diff --git a/pack.mjs b/pack.mjs deleted file mode 100644 index 83181ff..0000000 --- a/pack.mjs +++ /dev/null @@ -1,2 +0,0 @@ -import packModule from './pack.js' -export const { Packr, Encoder, pack, encode, addExtension, FLOAT32_OPTIONS } = packModule \ No newline at end of file diff --git a/package.json b/package.json index e7363ee..fc46017 100644 --- a/package.json +++ b/package.json @@ -24,10 +24,6 @@ }, "type": "module", "main": "./dist/node.cjs", - "browser": { - "./index.mjs": "./browser.mjs", - "./index.js": "./browser.js" - }, "exports": { ".": { "node": { @@ -35,12 +31,13 @@ "import": "./node.js" }, "default": { - "import": "./browser.js" + "import": "./index.js" } }, "./pack": { "node": { - "import": "./index.js" + "import": "./index.js", + "require": "./dist/node.cjs" }, "default": { "import": "./pack.js" @@ -48,12 +45,11 @@ }, "./unpack": { "node": { - "import": "./index.mjs", - "require": "./index.js" + "import": "./index.js", + "require": "./dist/node.cjs" }, "default": { - "import": "./unpack.mjs", - "require": "./unpack.js" + "import": "./unpack.js" } } }, diff --git a/unpack.mjs b/unpack.mjs deleted file mode 100644 index 79ffcd1..0000000 --- a/unpack.mjs +++ /dev/null @@ -1,2 +0,0 @@ -import unpackModule from './unpack.js' -export const { Unpackr, Decoder, unpack, unpackMultiple, decode, addExtension, C1, mult10, typedArrays, C1Type, FLOAT32_OPTIONS } = unpackModule \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js deleted file mode 100644 index 52ff3f4..0000000 --- a/webpack.config.js +++ /dev/null @@ -1,19 +0,0 @@ -var webpack = require('webpack') -var path = require('path') -module.exports = { - entry: { - index: './browser.js' - }, - output: { - path: path.join(__dirname, 'dist'), - library: 'msgpackr', - libraryTarget: 'umd' - }, - node: { Buffer: false }, - devtool: 'source-map', - optimization: { - minimize: true - }, - //mode: 'development' - mode: 'production' -};