dotfiles/vscode/.vscode/extensions/randomfractalsinc.vscode-data-preview-2.3.0/node_modules/hjson/lib/hjson.js
Errol Sancaktar ff17c17e23 vscode
2024-06-14 09:31:58 -06:00

184 lines
5.2 KiB
JavaScript

/*!
* Hjson v3.2.1
* http://hjson.org
*
* Copyright 2014-2017 Christian Zangl, MIT license
* Details and documentation:
* https://github.com/hjson/hjson-js
*
* This code is based on the the JSON version by Douglas Crockford:
* https://github.com/douglascrockford/JSON-js (json_parse.js, json2.js)
*/
/*
This file creates a Hjson object:
Hjson.parse(text, options)
options {
keepWsc boolean, keep white space and comments. This is useful
if you want to edit an hjson file and save it while
preserving comments (default false)
dsf array of DSF (see Hjson.dsf)
legacyRoot boolean, support omitting root braces (default true)
}
This method parses Hjson text to produce an object or array.
It can throw a SyntaxError exception.
Hjson.stringify(value, options)
value any JavaScript value, usually an object or array.
options { all options are
keepWsc boolean, keep white space. See parse.
condense integer, will try to fit objects/arrays onto one line
when the output is shorter than condense characters
and the fragment contains no comments. Default 0 (off).
bracesSameLine
boolean, makes braces appear on the same line as the key
name. Default false.
quotes string, controls how strings are displayed.
setting separator implies "strings"
"min" - no quotes whenever possible (default)
"keys" - use quotes around keys
"strings" - use quotes around string values
"all" - use quotes around keys and string values
multiline string, controls how multiline strings are displayed.
setting quotes implies "off"
"std" - strings containing \n are shown in
multiline format (default)
"no-tabs" - like std but disallow tabs
"off" - show in JSON format
separator boolean, output a comma separator between elements. Default false.
space specifies the indentation of nested structures. If it is
a number, it will specify the number of spaces to indent
at each level. If it is a string (such as '\t' or ' '),
it contains the characters used to indent at each level.
eol specifies the EOL sequence (default is set by
Hjson.setEndOfLine())
colors boolean, output ascii color codes
dsf array of DSF (see Hjson.dsf)
emitRootBraces
obsolete: will always emit braces
sortProps
When serializing objects into hjson, order the keys based on
their UTF-16 code units order
}
This method produces Hjson text from a JavaScript value.
Values that do not have JSON representations, such as undefined or
functions, will not be serialized. Such values in objects will be
dropped; in arrays they will be replaced with null.
stringify(undefined) returns undefined.
Hjson.endOfLine()
Hjson.setEndOfLine(eol)
Gets or sets the stringify EOL sequence ('\n' or '\r\n').
When running with node.js this defaults to os.EOL.
Hjson.rt { parse, stringify }
This is a shortcut to roundtrip your comments when reading and updating
a config file. It is the same as specifying the keepWsc option for the
parse and stringify functions.
Hjson.version
The version of this library.
Hjson.dsf
Domain specific formats are extensions to the Hjson syntax (see
hjson.org). These formats will be parsed and made available to
the application in place of strings (e.g. enable math to allow
NaN values).
Hjson.dsf ontains standard DSFs that can be passed to parse
and stringify.
Hjson.dsf.math()
Enables support for Inf/inf, -Inf/-inf, Nan/naN and -0.
Will output as Inf, -Inf, NaN and -0.
Hjson.dsf.hex(options)
Parse hexadecimal numbers prefixed with 0x.
set options.out = true to stringify _all_ integers as hex.
Hjson.dsf.date(options)
support ISO dates
This is a reference implementation. You are free to copy, modify, or
redistribute.
*/
"use strict";
var common = require("./hjson-common");
var version = require("./hjson-version");
var parse = require("./hjson-parse");
var stringify = require("./hjson-stringify");
var comments = require("./hjson-comments");
var dsf = require("./hjson-dsf");
module.exports={
parse: parse,
stringify: stringify,
endOfLine: function() { return common.EOL; },
setEndOfLine: function(eol) {
if (eol === '\n' || eol === '\r\n') common.EOL = eol;
},
version: version,
// round trip shortcut
rt: {
parse: function(text, options) {
(options=options||{}).keepWsc=true;
return parse(text, options);
},
stringify: function(value, options) {
(options=options||{}).keepWsc=true;
return stringify(value, options);
},
},
comments: comments,
dsf: dsf.std,
};