Socket
Socket
Sign inDemoInstall

yaml

Package Overview
Dependencies
1
Maintainers
3
Versions
88
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0-beta.1 to 1.0.0-beta.2

57

dist/schema/_string.js

@@ -6,8 +6,22 @@ "use strict";

});
exports.default = exports.str = void 0;
exports.default = exports.str = exports.strOptions = void 0;
var _rawYaml = require("raw-yaml");
var strOptions = {
defaultType: _rawYaml.Type.PLAIN,
dropCR: false,
doubleQuoted: {
jsonEncoding: false,
minMultiLineLength: 40
}
};
exports.strOptions = strOptions;
function doubleQuotedString(value, indent, oneLine) {
var _strOptions$doubleQuo = strOptions.doubleQuoted,
jsonEncoding = _strOptions$doubleQuo.jsonEncoding,
minMultiLineLength = _strOptions$doubleQuo.minMultiLineLength;
var json = JSON.stringify(value);
if (jsonEncoding) return json;
var str = '';

@@ -68,13 +82,13 @@ var start = 0;

i += 5;
start = i;
start = i + 1;
break;
case 'n':
if (oneLine) {
if (oneLine || json[i + 2] === '"' || json.length < minMultiLineLength) {
i += 1;
} else {
// folding will eat first newline
str += json.slice(start, i - 1) + '\n\n';
str += json.slice(start, i) + '\n\n';
while (json[i + 2] === '\\' && json[i + 3] === 'n') {
while (json[i + 2] === '\\' && json[i + 3] === 'n' && json[i + 4] !== '"') {
str += '\n';

@@ -88,3 +102,3 @@ i += 2;

i += 1;
start = i;
start = i + 1;
}

@@ -161,3 +175,3 @@

function plainString(value, indent, implicitKey, inFlow) {
function plainString(value, indent, implicitKey, inFlow, tags) {
if (implicitKey && /[\n[\]{},]/.test(value) || inFlow && /[[\]{},]/.test(value)) {

@@ -167,13 +181,16 @@ return doubleQuotedString(value, indent, implicitKey);

if (!value || /^[\n\t #]|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t ]$/.test(value)) {
if (!value || /^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t ]$/.test(value)) {
// not allowed:
// - empty string
// - start with ' ', '? ' or '- '
// - start with an indicator character (except [?:-]) or /[?-] /
// - '\n ', ': ' or ' \n' anywhere
// - '#' not preceded by a non-space char
// - end with ' '
return inFlow ? doubleQuotedString(value, indent, implicitKey) : blockString(value, indent, false);
}
return implicitKey || inFlow ? doubleQuotedString(value, indent, implicitKey) : blockString(value, indent, false);
} // Need to verify that output will be parsed as a string
return value.replace(/\n+/g, "$&\n".concat(indent));
var str = value.replace(/\n+/g, "$&\n".concat(indent));
var res = tags.resolveScalar(str);
return typeof res === 'string' ? str : doubleQuotedString(value, indent, implicitKey);
}

@@ -187,6 +204,3 @@

},
options: {
defaultType: _rawYaml.Type.PLAIN,
dropCR: true
},
options: strOptions,
stringify: function stringify(value) {

@@ -197,6 +211,9 @@ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},

inFlow = _ref.inFlow,
tags = _ref.tags,
type = _ref.type;
var dropCR = strOptions.dropCR,
defaultType = strOptions.defaultType;
if (typeof value !== 'string') value = String(value);
if (str.options.dropCR && /\r/.test(value)) value = value.replace(/\r\n?/g, '\n');
if (dropCR && /\r/.test(value)) value = value.replace(/\r\n?/g, '\n');

@@ -218,3 +235,3 @@ var _stringify = function _stringify(_type) {

case _rawYaml.Type.PLAIN:
return plainString(value, indent, implicitKey, inFlow);
return plainString(value, indent, implicitKey, inFlow, tags);

@@ -237,4 +254,4 @@ default:

if (res === null) {
res = _stringify(str.options.defaultType);
if (res === null) throw new Error("Unsupported default string type ".concat(str.options.defaultType));
res = _stringify(defaultType);
if (res === null) throw new Error("Unsupported default string type ".concat(defaultType));
}

@@ -241,0 +258,0 @@

@@ -216,3 +216,3 @@ "use strict";

if (inFlow) {
if (inFlow || items.length === 0) {
// return `{\n ${indent}${items.join(`,\n ${indent}`)}\n${indent}}`

@@ -219,0 +219,0 @@ return "{ ".concat(items.join(', '), " }");

@@ -42,2 +42,3 @@ "use strict";

value: function toString(tags, options) {
if (!tags) return JSON.stringify(this);
var key = this.key,

@@ -50,7 +51,5 @@ value = this.value;

opt.indent += ' ';
var stringifyKey = tags ? tags.getStringifier(key) : Tags.defaultStringifier;
var keyStr = stringifyKey(key, opt);
var keyStr = tags.stringify(key, opt);
opt.implicitKey = false;
var stringifyValue = tags ? tags.getStringifier(value) : Tags.defaultStringifier;
var valueStr = stringifyValue(value, opt);
var valueStr = tags.stringify(value, opt);

@@ -57,0 +56,0 @@ if (key instanceof _Collection.default) {

@@ -156,3 +156,3 @@ "use strict";

if (inFlow) {
if (inFlow || items.length === 0) {
return "[ ".concat(items.join(', '), " ]");

@@ -159,0 +159,0 @@ } else {

@@ -200,2 +200,3 @@ "use strict";

var stringifier = this.getStringifier(value, tag, format);
options.tags = this;
return stringifier(value, options);

@@ -202,0 +203,0 @@ }

{
"name": "yaml",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"main": "dist/index.js",

@@ -47,14 +47,14 @@ "license": "ISC",

"devDependencies": {
"@babel/cli": "^7.0.0-beta.37",
"@babel/core": "^7.0.0-beta.37",
"@babel/preset-env": "^7.0.0-beta.37",
"@babel/preset-stage-3": "^7.0.0-beta.37",
"@babel/cli": "^7.0.0-beta.40",
"@babel/core": "^7.0.0-beta.40",
"@babel/preset-env": "^7.0.0-beta.40",
"@babel/preset-stage-3": "^7.0.0-beta.40",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^22.0.6",
"babel-plugin-trace": "eemeli/babel-plugin-trace#babel7-build",
"jest": "^22.0.6"
"babel-jest": "^22.2.2",
"babel-plugin-trace": "^1.1.0",
"jest": "^22.3.0"
},
"dependencies": {
"raw-yaml": "^0.2.3"
"raw-yaml": "^0.2.5"
}
}

@@ -11,3 +11,3 @@ # YAML

```
npm install yaml
npm install yaml@next
```

@@ -45,3 +45,3 @@

The reason why this project exists is to have a tool that's capable of properly generating and handling YAML files with comments, specifically to provide context for translation strings that have been lifted out of JS source code. We're not there yet, as the prerequisite for that is having a complete and functioning YAML library.
The reason why this project exists is to have a tool that's capable of properly generating and handling YAML files with comments, specifically to provide context for translation strings that have been lifted out of JS source code. We're not there quite yet, as the prerequisite for that is having a complete and functioning YAML library.

@@ -57,3 +57,3 @@ The [AST level] of the library has been released separately, and is fully functional.

- Support for `<<` merge keys (default-enabled, disable with `merge: false` option)
- Complete match between the parsed `in.yaml` and `in.json` files across all of the [yaml-test-suite] test cases (note: A few of the tests are not in agreement with the spec, so this requires the use of a [custom branch] until [PR #24] and [issue #25] are resolved)
- Complete match between the parsed `in.yaml`, `in.json`, and `out.yaml` files across all of the [yaml-test-suite] test cases (note: A few of the tests are not in agreement with the spec, so this requires the use of a [custom branch] until the relevant [pull requests] and [issues] are resolved)
- Comments are parsed and included up to the [AST level] of the API

@@ -67,13 +67,11 @@ - "Native" `Map` and `Seq` collections have `toJSON()` methods for bare JavaScript `Object` and `Array` output

[custom branch]: https://github.com/eemeli/yaml-test-suite/tree/fixed-data
[PR #25]: https://github.com/yaml/yaml-test-suite/pull/24
[issue #25]: https://github.com/yaml/yaml-test-suite/issues/25
[pull requests]: https://github.com/yaml/yaml-test-suite/pulls/eemeli
[issues]: https://github.com/yaml/yaml-test-suite/issues/created_by/eemeli
[AST level]: https://www.npmjs.com/package/raw-yaml
#### Stringifying
- `Document#toString()` mostly works, producing idempotent YAML from all but a few [corner cases]
- `Document#toString()` produces idempotent YAML from all non-error spec examples and test suite cases
- `AST#toString()` works completely, but is clumsy to use
[corner cases]: https://github.com/eemeli/yaml/commit/b237e55e00071700ae02a748dff3a857cea8674a
### Still Needs Work

@@ -85,3 +83,5 @@

- Item add/remove should keep tags and comments in place
- Explicit tags are not included in the stringified output
- Not all parser errors are reported
- API needs finalising
- Better documentation
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc