How to use json-6 - 3 common examples

To help you get started, we’ve selected a few json-6 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github d3x0r / gun-file / file.js View on Github external
function preloadDisk( opt, disk ) {
		if( fileState.loaded )
			return; // already have the disk image in memory
		if( fileState.flushPending || fileState.writing ) {
			_debug && console.log( "wait for pending flush on another connection?" );
			setTimeout( ()=>preloadDisk( opt, disk ), fileDelay/3 );
			return;
		}
		fileState.reading = true;
		_debug && console.log( new Date(), "preload happened." );
		const stream = fs.createReadStream( fileName, { flags:"r", encoding:"utf8"} );
		const parser = json6.begin( function(val) {
			//_json_debug && console.log( "Recover:", val[0] );
			disk[val[0]] = val[1];
		} );
		stream.on('open', function() {
			_debug && console.log( new Date(), "Read stream opened.." );
		} );
		stream.on('error', function( err ){ 
			if( err.code !== 'ENOENT' )
				console.log( "READ STREAM ERROR:", err );
			loaded = true;
			fileState.reading = false;
			handlePending();
		} );
 	 	stream.on('data', function(chunk) {
			//_json_debug && console.log( "got stream data",chunk );
			parser.write( chunk );
github standard-things / esm / test / misc-tests.js View on Github external
import Module from "module"
import SemVer from "semver"

import assert from "assert"
import createNamespace from "./create-namespace.js"
import fs from "fs-extra"
import * as fsExtraNs from "fs-extra"
import * as fsNs from "fs"
import path from "path"
import require from "./require.js"
import resetState from "./reset-state.js"
import stream from "stream"
import trash from "../script/trash.js"
import util from "util"

const ESM_OPTIONS = JSON6.parse(process.env.ESM_OPTIONS || "{}")

const isDebug = !! ESM_OPTIONS.debug
const isWin = process.platform === "win32"

const canTestDuplexInstance = SemVer.satisfies(process.version, ">=6.8")
const canTestHasInstance = SemVer.satisfies(process.version, ">=6.5")
const canTestUtilFormatWithOptions = Reflect.has(util, "formatWithOptions")
const canTestUtilTypes = Reflect.has(util, "types")
const canTestWorker = SemVer.satisfies(process.version, ">=10.5")

const fileProtocol = "file://" + (isWin ? "/" : "")
const slashRegExp = /[\\/]/g

const indexPath = path.resolve("../index.js")
const pkgJSON = fs.readJSONSync("../package.json")
github standard-things / esm / src / util / parse-json6.js View on Github external
function tryParse(string) {
    if (typeof string === "string" &&
        string.length) {
      try {
        return parse(string)
      } catch {}
    }

    return null
  }

json-6

JSON for the ES6 era.

MIT
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis

Popular json-6 functions