Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

compact-encoding

Package Overview
Dependencies
Maintainers
3
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

compact-encoding - npm Package Compare versions

Comparing version 2.7.0 to 2.8.0

26

index.js

@@ -310,3 +310,3 @@ const b4a = require('b4a')

exports.string = exports.utf8 = string('utf-8')
const utf8 = exports.string = exports.utf8 = string('utf-8')
exports.ascii = string('ascii')

@@ -381,2 +381,26 @@ exports.hex = string('hex')

exports.json = {
preencode (state, v) {
utf8.preencode(state, JSON.stringify(v))
},
encode (state, v) {
utf8.encode(state, JSON.stringify(v))
},
decode (state) {
return JSON.parse(utf8.decode(state))
}
}
exports.ndjson = {
preencode (state, v) {
utf8.preencode(state, JSON.stringify(v) + '\n')
},
encode (state, v) {
utf8.encode(state, JSON.stringify(v) + '\n')
},
decode (state) {
return JSON.parse(utf8.decode(state))
}
}
exports.from = function from (enc) {

@@ -383,0 +407,0 @@ if (enc.preencode) return enc

2

package.json
{
"name": "compact-encoding",
"version": "2.7.0",
"version": "2.8.0",
"description": "A series of compact encoding schemes for building small and fast parsers and serializers",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -118,2 +118,4 @@ # compact-encoding

* `cenc.array(enc)` - Makes an array encoder from another encoder. Arrays are uint prefixed with their length.
* `cenc.json` - Encodes a JSON value as utf-8.
* `cenc.ndjson` - Encodes a JSON value as newline delimited utf-8.
* `cenc.from(enc)` - Makes a compact encoder from a [codec](https://github.com/mafintosh/codecs) or [abstract-encoding](https://github.com/mafintosh/abstract-encoding).

@@ -120,0 +122,0 @@

@@ -411,2 +411,25 @@ const enc = require('./')

tape('json', function (t) {
const state = enc.state()
enc.json.preencode(state, { a: 1, b: 2 })
t.alike(state, { start: 0, end: 14, buffer: null })
state.buffer = Buffer.alloc(state.end)
enc.json.encode(state, { a: 1, b: 2 })
t.alike(state, {
start: 14,
end: 14,
buffer: Buffer.concat([
Buffer.from([13]),
Buffer.from('{"a":1,"b":2}')
])
})
state.start = 0
t.alike(enc.json.decode(state), { a: 1, b: 2 })
t.exception(() => enc.json.decode(state))
})
tape('lexint: big numbers', function (t) {

@@ -413,0 +436,0 @@ t.plan(1)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc