nodeca / js-yaml Goto Github PK
View Code? Open in Web Editor NEWJavaScript YAML parser and dumper. Very fast.
Home Page: http://nodeca.github.io/js-yaml/
License: MIT License
JavaScript YAML parser and dumper. Very fast.
Home Page: http://nodeca.github.io/js-yaml/
License: MIT License
On Safari I get this error message from js-yaml:
Cannot declare a parameter named 'c' in strict mode
Implement JS -> YAML convertor.
Support for octal integers
octal: 0o14
Hi!
Yahoo compressor noticed me that "double" is reserved keyword, js still works, but it's not cool.
An example:
Scanner.prototype.scanFlowScalar = function scanFlowScalar(style) { var double, chunks, length, code, startMark, quote, endMark; ...
and in other parts of the code.
js-yaml used to install nicely for me (npm install
) until version 0.3.7.
I just tried today to run a simple npm install js-yaml
and noticed that the latest version was 1.0.0, and I'm getting the following error in the console:
npm http GET https://registry.npmjs.org/js-yaml
npm http 304 https://registry.npmjs.org/js-yaml
npm http GET https://registry.npmjs.org/argparse
npm http 304 https://registry.npmjs.org/argparse
npm http GET https://registry.npmjs.org/underscore.string
npm http GET https://registry.npmjs.org/underscore
npm http 304 https://registry.npmjs.org/underscore.string
npm http 304 https://registry.npmjs.org/underscore
npm ERR! error installing [email protected]
npm ERR! Error: ENOENT, no such file or directory '/Users/patrickbrosset/ariatemplates-captainbrosset/node_modules/js-yaml/bin/js-yaml.js'
npm ERR! Report this *entire* log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <[email protected]>
npm ERR!
npm ERR! System Darwin 11.4.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "js-yaml"
npm ERR! cwd /Users/patrickbrosset/ariatemplates-captainbrosset
npm ERR! node -v v0.6.7
npm ERR! npm -v 1.1.0-beta-10
npm ERR! path /Users/patrickbrosset/ariatemplates-captainbrosset/node_modules/js-yaml/bin/js-yaml.js
npm ERR! code ENOENT
npm ERR! message ENOENT, no such file or directory '/Users/patrickbrosset/ariatemplates-captainbrosset/node_modules/js-yaml/bin/js-yaml.js'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/patrickbrosset/ariatemplates-captainbrosset/npm-debug.log
npm not ok
Setup is MacOS 10.7.4
Running npm install [email protected]
runs fine though.
When node is running with --harmony we can use WeakMap and Map types, so it would be nice to first try WeakMap, then Map and finally fallback to default Object.
On Windows, for some reason after installing the module, some required files aren't present, in particular js-yaml.js and lib/js-yaml.js, which cause the library to not work at all.
But when adding it this git repository directly under my node_modules folder it works. Anybody know whats wrong?
Could support for CoffeeScript functions be added so this will work?
function: !!cs/function >
foobar = ->
"Wow! JS-YAML Rocks!"
While support of IE6 is close to necrophilia, IE7 is still one of the things that make our days not so shiny. By some reason js-yaml ignores new-line breaks on IE7.
This works:
{ foo: bar, baz: 123 }
And this one doesn't:
foo: bar
baz: 123
To demonstrate problem closer:
- foo
- bar
Becomes:
[ 'foo - baz' ]
Also, integers are becomes integers ONLY with strict type casting:
{ foo: !!int 123, bar: 123 }
The above will become:
{ foo: 123, bar: '123' }
{1: 1, a: a} yields { '1': 1, a: 'a' } instead of { 1: 1, 'a': 'a' }
I’m trying to add a constructor for custom tags using
jsyaml.addConstructor(
'!sometag',
function(node) { return "test"} );
This fails with "(Loader || _loader.Loader).addConstructor is not a function". I checked _loader.Loader using Firebug, and it indeed does not have that function. If it’s not a bug, do you have any hints on what I am doing wrong?
When js-yaml loads long files with multibyte utf-8 symbols sometimes it brokes characters (replaces valid unicode char by two error marks)
yaml = require('js-yaml')
data_broken = require('mydata.yaml')
data_correct = yaml.load( fs.readFileSync('mydata.yaml') )
Probably it happens when utf-8 symbol lays exactly on read buffer boundary and byte reader splits it on two incorrect parts.
I'm running latest Ubuntu version.
I installed the proposed fix from master tree, (related to issue #34, #35 and #36) I still receive the error Error: ENOENT, no such file or directory '..//node_modules/js-yaml/bin/js-yaml.js'
error output from standard package:
npm ERR! error installing [email protected]
npm ERR! Error: ENOENT, no such file or directory '../../node_modules/js-yaml/bin/js-yaml.js'
npm ERR! You may report this log at:
npm ERR! http://bugs.debian.org/npm
npm ERR! or use
npm ERR! reportbug --attach ../../npm-debug.log npm
npm ERR!
npm ERR! System Linux 3.2.0-29-generic
npm ERR! command "node" "/usr/bin/npm" "install" "js-yaml"
npm ERR! cwd
npm ERR! node -v v0.6.12
npm ERR! npm -v 1.1.4
npm ERR! path ../../node_modules/js-yaml/bin/js-yaml.js
npm ERR! code ENOENT
npm ERR! message ENOENT, no such file or directory '../../node_modules/js-yaml/bin/js-yaml.js'
npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! ../../npm-debug.log
error output from tarball master:
npm ERR! error installing [email protected]
npm ERR! Error: ENOENT, no such file or directory '../../node_modules/js-yaml/bin/js-yaml.js'
npm ERR! You may report this log at:
npm ERR! http://bugs.debian.org/npm
npm ERR! or use
npm ERR! reportbug --attach ../../npm-debug.log npm
npm ERR!
npm ERR! System Linux 3.2.0-29-generic
npm ERR! command "node" "/usr/bin/npm" "install" "https://github.com/nodeca/js-yaml/tarball/master"
npm ERR! cwd ../..
npm ERR! node -v v0.6.12
npm ERR! npm -v 1.1.4
npm ERR! path ../../node_modules/js-yaml/bin/js-yaml.js
npm ERR! code ENOENT
npm ERR! message ENOENT, no such file or directory '../../node_modules/js-yaml/bin/js-yaml.js'
npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! ../../npm-debug.log
npm not ok
I just installed "js-yaml" with "npm install js-yaml". It doesn't work because the file "./lib/js-yaml.js" isn't there. I had to take it from the git repo and paste it into my dir "node_modules/js-yaml/lib" to make it work. Great job for the native port though!
I'm struggling to get this working with requireJS. I've tried the examples in the README with no luck.
Here is my control case:
define([
'require',
'jquery',
'mustache',
'js-yaml.min',
], function(require, $){
var JB = {
init : function(boot){
var doc = jsyaml.load('greeting: hello\nname: world');
console.log(doc); // this works fine.
//require('js-yaml.min'); // this works both uncommented and commented.
var singleDoc = require('http://127.0.0.1/~jade/javascripts/require-js/tags.yaml').shift();
console.log(singleDoc);
// This does not work
// Uncaught Error: Module name 'http://127.0.0.1/~jade/javascripts/require-js/tags.yaml' has not been loaded yet for context: _
// http://requirejs.org/docs/errors.html#notloaded
if(typeof boot === "function") boot();
}
};
return JB;
});
As per the error documentation (http://requirejs.org/docs/errors.html#notloaded) I have tried to load the tags.yaml first in the define statement. The tags.yaml loads fine but since its not javascript, It returns a syntax error.
Any help would be appreciated, thanks.
ϟ js-yaml ./client/locales/en.yaml
{ credits:
{ roles:
{ art_director: 'Art director',
associate_producer: 'Associate producer',
producers: 'Producers',
colourist: 'Colourist',
costume_designer: 'Costume designer',
director: 'Director',
director_of_photography: 'Director of photography',
editor: 'Editor',
music: 'Music',
producer: 'Producer',
titles_and_poster: 'Titles and poster',
screenwriter: 'Screenwriter',
sound_designer: 'Sound designer',
writer: 'Writer',
sound_recorder_and_design_and_mix: 'Sound recorder, design, and mix',
sound_design_and_mix: 'Sound design and mix"',
original_music_composer_and_orchestrator_and_conductor: 'Original music composer, orchestrator, and conductor',
original_score_composer_and_performer: 'Original score, composer, and performer' } },
production_companies: 'Production companies',
production_company: 'Production company',
shooting_format: 'Shooting format',
release_date: 'Release date',
funding_agencies: 'Funding agencies',
distribution_and_sales: 'Distribution and sales',
genre: 'Genre',
languages: 'languages',
language: 'Language',
runtime: 'Runtime' }
ϟ js-yaml ./client/locales/en.yaml > test.js
.... open ./test.js...
{ credits:
{ roles:
{ art_director: �[32m'Art director'�[39m,
associate_producer: �[32m'Associate producer'�[39m,
producers: �[32m'Producers'�[39m,
colourist: �[32m'Colourist'�[39m,
costume_designer: �[32m'Costume designer'�[39m,
director: �[32m'Director'�[39m,
director_of_photography: �[32m'Director of photography'�[39m,
editor: �[32m'Editor'�[39m,
music: �[32m'Music'�[39m,
producer: �[32m'Producer'�[39m,
titles_and_poster: �[32m'Titles and poster'�[39m,
screenwriter: �[32m'Screenwriter'�[39m,
sound_designer: �[32m'Sound designer'�[39m,
writer: �[32m'Writer'�[39m,
sound_recorder_and_design_and_mix: �[32m'Sound recorder, design, and mix'�[39m,
sound_design_and_mix: �[32m'Sound design and mix"'�[39m,
original_music_composer_and_orchestrator_and_conductor: �[32m'Original music composer, orchestrator, and conductor'�[39m,
original_score_composer_and_performer: �[32m'Original score, composer, and performer'�[39m } },
production_companies: �[32m'Production companies'�[39m,
production_company: �[32m'Production company'�[39m,
shooting_format: �[32m'Shooting format'�[39m,
release_date: �[32m'Release date'�[39m,
funding_agencies: �[32m'Funding agencies'�[39m,
distribution_and_sales: �[32m'Distribution and sales'�[39m,
genre: �[32m'Genre'�[39m,
languages: �[32m'languages'�[39m,
language: �[32m'Language'�[39m,
runtime: �[32m'Runtime'�[39m }
We are comfortable with native JS parser that we have now.
But any help in writing bindigs to libyaml will be appreciated.
---
xmas: 2011-12-24
...
results in
{
xmas: Mon, 23 Jan 2012 23:00:00 GMT
}
Confirmed this on the website
IE gives error about base64 object
First of all thanks for a good lib! YAML is so much better than JSON.
A question: would it be easy to include a JSON to YAML converter?
So you can do conversion in both directions kinda like: http://js2coffee.org/
For example: 2010-10-20T20:45:00Z is being parsed as Wed Oct 20 2010 13:45:00 GMT-0700 (PDT), instead of Wed Oct 20 2010 13:45:00 (UTC).
Test and patch incoming...
Extracted inspect
from Node.JS does not stringify RegExp objects in browsers correctly.
Is there a way to convert a Javascript object to YAML?
Instead of using shims, we must use Underscore (right in the library), so the browserified version will become in two options: with underscore bundled (for hardcore standalone version) and without (when user is using underscore already).
That will probably solve any problems with different browsers.
Would be great if this npm package could be compatible with browserify so we don't have to use the minified version.
https://github.com/substack/node-browserify
At the moment I get an error when using the load() function.
If I do npm install js-yaml
, I get the following error:
Error: ENOENT, chmod '/home/marijn/src/js/heckle/node_modules/js-yaml/bin/js-yaml.js'
I put the whole npm-debug.log file at https://gist.github.com/3633900 . I'm using node 0.8.8 and npm 1.1.59
Just tried on a clean install. Randomly-tested other modules are OK:
almad@namtar /tmp $ node --version
v0.6.10
almad@namtar /tmp $ npm --version
1.1.0-3
almad@namtar /tmp $ npm install js-yaml
npm http GET https://registry.npmjs.org/js-yaml
npm http 200 https://registry.npmjs.org/js-yaml
npm http GET https://registry.npmjs.org/js-yaml/-/js-yaml-1.0.3.tgz
npm http 200 https://registry.npmjs.org/js-yaml/-/js-yaml-1.0.3.tgz
npm http GET https://registry.npmjs.org/argparse
npm http 200 https://registry.npmjs.org/argparse
npm http GET https://registry.npmjs.org/argparse/-/argparse-0.1.7.tgz
npm http 200 https://registry.npmjs.org/argparse/-/argparse-0.1.7.tgz
npm http GET https://registry.npmjs.org/underscore
npm http GET https://registry.npmjs.org/underscore.string
npm http 200 https://registry.npmjs.org/underscore
npm http GET https://registry.npmjs.org/underscore/-/underscore-1.3.3.tgz
npm http 200 https://registry.npmjs.org/underscore.string
npm http GET https://registry.npmjs.org/underscore.string/-/underscore.string-2.1.1.tgz
npm http 200 https://registry.npmjs.org/underscore/-/underscore-1.3.3.tgz
npm http 200 https://registry.npmjs.org/underscore.string/-/underscore.string-2.1.1.tgz
npm ERR! error installing [email protected]
npm ERR! Error: ENOENT, no such file or directory '/tmp/node_modules/js-yaml/bin/js-yaml.js'
npm ERR! You may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <[email protected]>
npm ERR!
npm ERR! System Linux 3.2.1-gentoo-r2
npm ERR! command "node" "/home/almad/.nvm/v0.6.10/bin/npm" "install" "js-yaml"
npm ERR! cwd /tmp
npm ERR! node -v v0.6.10
npm ERR! npm -v 1.1.0-3
npm ERR! path /tmp/node_modules/js-yaml/bin/js-yaml.js
npm ERR! code ENOENT
npm ERR! message ENOENT, no such file or directory '/tmp/node_modules/js-yaml/bin/js-yaml.js'
npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /tmp/npm-debug.log
npm not ok
almad@namtar /tmp $
When using:
accomplishment: >
Mark set a major league
home run record in 1998.
the result should be:
{ accomplishment: 'Mark set a major league home run record in 1998.' }
not:
{ accomplishment: 'Mark set a major leaguehome run record in 1998.' }
The > should convert new lines into white spaces according to the specification: http://www.yaml.org/spec/1.2/spec.html#id2760844
This doesn't seem to be supported in js-yaml:
? - Detroit Tigers
- Chicago cubs
:
- 2001-07-23
? [ New York Yankees,
Atlanta Braves ]
: [ 2001-07-02, 2001-08-12,
2001-08-14 ]
? a: b
produces
{ '[object Object]': null }
Parser fais when document have no ---
start node:
TypeError: Cannot read property '!!' of undefined
at [object Object].parseNode (/home/ixti/projects/js-yaml/lib/js-yaml/parser.js:375:44)
at [object Object].parseBlockNodeOrIndentlessSequence (/home/ixti/projects/js-yaml/lib/js-yaml/parser.js:324:17)
at [object Object].parseBlockMappingValue (/home/ixti/projects/js-yaml/lib/js-yaml/parser.js:561:23)
at [object Object].state (/home/ixti/projects/js-yaml/node_modules/jsclass/src/core.js:56:19)
at [object Object].checkEvent (/home/ixti/projects/js-yaml/lib/js-yaml/parser.js:110:32)
at [object Object].composeNode (/home/ixti/projects/js-yaml/lib/js-yaml/composer.js:89:14)
at [object Object].composeMappingNode (/home/ixti/projects/js-yaml/lib/js-yaml/composer.js:190:24)
at [object Object].composeNode (/home/ixti/projects/js-yaml/lib/js-yaml/composer.js:115:19)
at [object Object].composeMappingNode (/home/ixti/projects/js-yaml/lib/js-yaml/composer.js:190:24)
at [object Object].composeNode (/home/ixti/projects/js-yaml/lib/js-yaml/composer.js:115:19)
! 12
resolves to !!int when scalar nodes with a non-specific "!" tags should always resolve to !!str according to recommendation in spec (paragraph 3.3.2)
It is recommended that nodes having the “!” non-specific tag should be resolved as “tag:yaml.org,2002:seq”, “tag:yaml.org,2002:map” or “tag:yaml.org,2002:str” depending on the node’s kind.
From the 1.2 spec it seems that you should be allowed to override anchors: http://www.yaml.org/spec/1.2/spec.html#c-ns-alias-node
First occurrence: &anchor Foo
Second occurrence: *anchor
Override anchor: &anchor Bar
Reuse anchor: *anchor
It will throw an error with js-yaml.
Is this something that should be fixed to be 1.2 compatible?
In Opera I get this error message:
exception: TypeError: 'Object.getOwnPropertyNames' is not a function
Encoding should be automatically guessed when reading from the file. Right now it's hardcoded to read as UTF-8 only. Need to "guess" which UTF to use by first byte of the buffer: http://pyyaml.org/browser/pyyaml/trunk/lib3/yaml/reader.py#L122
It needs to raise an exception on invalid UTF bytes:
yaml.reader.ReaderError: 'utf8' codec can't decode byte #xff: invalid start byte
in "invalid-utf8-byte.loader-error", position 4119
It could be useful to run JS-YAML in browser. For example, to do nice looking debug dumps for complex data.
This valid YAML should be parseable into 3 documents:
---
a:
When parsed,
these three lines
SHOULD NOT retain linebreaks.
b: |
When parsed,
these three lines
SHOULD retain linebreaks.
---
When parsed,
these three lines
SHOULD NOT retain linebreaks.
--- |
When parsed,
these three lines
SHOULD retain linebreaks.
But yaml.loadAll
throws a ParserError
exception when the third document (beginning with --- |
) is reached.
According to the YAML 1.2 spec, Literal and Folded Style on documents is valid YAML, but most parsers fail to support either.
Can you add support for this?
Sub is needed for public API method loadFile
?
I found a bug
Keys or values y
evaluate as true (yes), the same bug with n
:
bugs: x: 1 # ok y: 2 # buggy, expect key 'y' n: 3 # buggy, expect key 'n' yesValue: y # buggy, expect string 'y' noValue: n # buggy, expect string 'n'
->
{ bugs: { x: 1, true: 2, false: 3, yesValue: true, noValue: false } }
Subj.
data: !!binary "\
...\
...\
..."
works, while
data: !binary |
...
...
...
does not
If we have an object with 'y' property, like
point:
x: 19
y: 5
it becomes
point: { x: 19, true: 5 }
Looks really strange, but maybe it's not a bug ( later I found a discussion)
expected a single document in the stream
in "<unicode string>", line 2, column 1:
pid: '/home/www/pids/thin.pid'
wait: 12.34
listen: {host: localhost, port: 3000}
modules: ['users', 'i18n']
users: &crew
puzrin:
role: manager
ixti:
role: developer
authors: *crew
require:
- logger
- debugger
dbg-mode: true
# some comments
non-ascii-ключ: значение # more comments
folded: >
Multi
line
text
literal: |
More
samples
...
---
multiple: docs
^
but found another document
in "<unicode string>", line 27, column 1:
---
multiple: docs
^
The browser version dies in safari (probably also IE!) as Function.prototype.bind
does not exist. I've fixed it for my use case using underscore's bind function as I had underscore knocking around anyway, but this isn't a long term solution.
When I do something like var c = require('config.yaml');
I get a single-element array with the YAML-derived data structure as the element. I guess that's more or less as documented, but it seems strange. I would have expected that I'd get just the data structure, with no extra array around it. Having to use a [0]
to get to the actual data is an annoyance. Is there some point I'm missing?
That is, I'd hoped to get
{"property1":"value1","property2":"value2"}
but instead I get
[{"property1":"value1","property2":"value2"}]
./test/unported
contains original tests and data./test/functional
contains ported tests and dataA declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.