Git Product home page Git Product logo

javascript-yaml-parser's Introduction

================================================================================
                          YAML Parser for Javascript
--------------------------------------------------------------------------------

Author: Diogo Costa ([email protected])
Date: 2nd April 2011
================================================================================

DESCRIPTION

This project intends to implement a simple YAML parser. It does not intend to
implement all the aspects formalized in the YAML specs, but rather to implement
a robust parser in Javascript, enough to load simply structured YAML files,
without depending on external libraries and as compatible as possible with all
Javascript-powered browsers.

INSTALLATION

To use the parser, copy 'src/yaml.js' to your javascript-files folder and 
include it in your page:

    <script type="text/javascript" src="yaml.js"></script>

Then use the functions 'YAML.fromURL' or 'YAML.eval' to parse a YAML file.

DOCUMENTATION

In the 'lib' folder, you can find the JSDoc toolkit.
This toolkit is used to generate the documentation for the project.
The documentation is in the folder 'doc'. 
Use a web browser to visualize 'index.html', the base file of the documentation.
To generate the documentation again, open a terminal and navigate to the folder
where the file 'Makefile' is. Then, run the command 'make'. This will generate
the documentation.

DISCLAIMER

I try to deliver high quality products, but I do not guarantee that the product
is free from defects. Our software is provided "as is", and you use the software
at your own risk.

I make no warranties as to performance, merchantability, fitness for a 
particular purpose, or any other warranties whether expressed or implied.

Under no circumstances shall I be liable for direct, indirect, special, 
incidental, or consequential damages resulting from the use, misuse, or 
inability to use this software, even if I have been advised of the possibility 
of such damages.

Please consult the license file for more information.

javascript-yaml-parser's People

Contributors

h4evr avatar

Watchers

James Cloos avatar

javascript-yaml-parser's Issues

Pull Request

I wanted a system for deserializing into custom classes, so I added some 
modifications. The patch file is attached.

Basically, you add 'types' using addType(key, func). If a type with the 
specified key shows up, the parsed contents of it are passed to func which 
returns a replacement. The first character of key is expected to be an '!' and 
is ignored.

I added the types variable.
I modified the key regex to simplify the code. If you need an explanation, load 
it into regex101.com (that website is awesome).
In parseBlock, I added a line to set the default type function to a pass 
through.
I modified parseBlock to find the parse function if the YAML specifies a type 
and to pass the parsed children through the type function.

Original issue reported on code.google.com by [email protected] on 19 Mar 2014 at 5:53

Attachments:

The .fromURL() function tries to read the file when the readyState is 1

What steps will reproduce the problem?
1. Used ember.js to create my app and use the App.ready = function() { /** 
called YAML function here **/  }
2. Opened YAML.fromURL("languages_V2/en.yml", function(data) { 
console.log(data); } 
3. Got an exception thrown InvalidState 

What is the expected output? What do you see instead?
Expected output is to load the file and return the JS object from YAML file

What version of the product are you using? On what operating system?
Version is 0.4

Please provide any additional information below.

Here's the issue I was facing:
yaml.js, line 114: if (this.readyState == 4 || this.status == 200) {

It happens that in the process, 
this.readyState "can" be 1 and this.status "can" be 200 at the same time. But 
following the specifications, if the state is 1 ( "Open and accepted", ready to 
process to the file transfer ) and operations are attempted to the XHR object, 
the browser have to throw an exception "InvalideStateError" ( source: 
http://www.w3.org/TR/XMLHttpRequest/#states, 4.7.1-1.1 )

Possible fix ( worked for me ): replace line 114 by if (this.readyState == 4 && 
this.status == 200) {
To check that readyState == 4 AND this.status == 200.

Original issue reported on code.google.com by [email protected] on 5 Nov 2012 at 2:32

Parseing fails in IE7

We tried to use your parser with IE7 and had to find out that nothing works. In 
our opinion the reason is that IE7 handles regularexpression with an optional 
group different than all other browsers.

We found a fix for this issue: 

before:
line 361:  if(typeof m[2] != "undefined" ) {

after:
line 361:  if(typeof m[2] != "undefined" && m[2]!="") {

As far as we understood this is the only location in your code where this 
happens.

Useing this fix your parser is working fine with IE7, as far as we tried it... 

Original issue reported on code.google.com by [email protected] on 2 Oct 2012 at 12:48

Simple YAML not supported?

I tried the following:

YAML.eval("---\n- one\n- two") // [], expect ["one", "two"]
YAML.eval("---\none: two") // [], expect {"one": "two"}

Am I missing something?  Is there a particular subset of YAML that is supported 
here?

Original issue reported on code.google.com by [email protected] on 19 Apr 2011 at 12:51

paragraph breaks ignored in folded and literal blocks

sometext: >
  this the start of a new paragraph

  this is another paragraph

The parser should recognize the blank line (paragraph break) and preserve it, 
but it gets stripped out very early in the parsing (matches invalidLine regex).




Original issue reported on code.google.com by [email protected] on 3 Feb 2014 at 7:13

While parsing a .yml file, the parsers crashes and throws an Exception "True does not have a method match"

What steps will reproduce the problem?
1. Opened a yaml file using YAML.fromURL("language/en.yml", function(data) { 
console.log(data); })
2. Got a crash saying that "True" does not have a method Match

What is the expected output? What do you see instead?
-> I was supposed to get the YAML ( valid ) parsed

What version of the product are you using? On what operating system?
-> 0.4

Please provide any additional information below.

Basically, I do not know why it was that specific on my browser, but the 
problem is the following. 

yaml.js, line 448: var lines = src.split("\n");
-> This method was working good, outputting an array of lines ( correct number )

yaml.js, line 452: for(var i in lines) {
-> This line was where the trouble arrived. for(var i in lines) was outputting 
all the lines (good), but also all the "lines" object properties (not good). 
After i arrived to the end of the array, it was starting to try to find 
lines[i].match(r) from i = "text" values, returning an undefined lines[i]. 

My (working) solution:

My solution is not the best, because it doesn't make sure that for(var i in 
lines) outputs just the array. But it's working by avoiding parasites. 

I replaced the for(var i in lines) { } by:

        for(var i in lines) {
            try {
                if(!isNaN(i) && (m = lines[i].match(r))) {
                    if(typeof m[3] !== "undefined") {
                        lines[i] = m[0].substr(0, m[0].length - m[3].length);
                    }
                }
            } catch(e) {
                console.log(e);
            }
        }

I'm just making sure that we're having an array index here, and try/catch to 
avoid errors. 

Original issue reported on code.google.com by [email protected] on 7 Nov 2012 at 1:07

Error Parsing YAML array Objects

What steps will reproduce the problem?
1. Eval the following YAML data:
items:
- name: "Barking Deer"
  slug: "barking-deer"
- name: "Chital"
  slug: "chital"
- name: "Common Palm Civet"
  slug: "common-palm-civet"
- name: "Elephant"
  slug: "elephant"
- name: "Golden Jackal"
  slug: "golden-jackal"
2. Output is:
{
  "items": [
    {
      "name": "Golden Jackal", 
      "slug": "golden-jackal"
    }
  ]
}
What is the expected output? What do you see instead?
{
  "items": [
    {
      "name": "Barking Deer", 
      "slug": "barking-deer"
    }, 
    {
      "name": "Chital", 
      "slug": "chital"
    }, 
    {
      "name": "Common Palm Civet", 
      "slug": "common-palm-civet"
    }, 
    {
      "name": "Elephant", 
      "slug": "elephant"
    }, 
    {
      "name": "Golden Jackal", 
      "slug": "golden-jackal"
    }
  ]
}

What version of the product are you using? On what operating system?
0.3

Please provide any additional information below.
A fixed yaml.js has been attached. The problem is in line 353 of yaml.js for 
every iteration it is resetting isMap to true. Removing isMap = true from line 
353 of YAML.js fixes the issue.

Original issue reported on code.google.com by [email protected] on 23 Jun 2011 at 2:00

Attachments:

XMLHTTPRequest onreadystatechange is not written properly.

I cannot use the ondone callback for YAML.fromURL reliably. This is because of 
this line:

    if (this.readyState == 4 || this.status == 200) {

That gets called three times, because of the OR statement. It should be this 
instead:

    if (this.readyState == 4 && this.status == 200) {

That will make it useable again.

Original issue reported on code.google.com by [email protected] on 18 Aug 2011 at 7:37

key/val pair following text block ends up on wrong part of hierarchy

To reproduce, try this YAML example:

var data = YAML2.eval(
"node:\n\
  - one: arg1\n\
    two: arg2\n\
    desc: >\n\
      a long desciption\n\
      that spans two line\n\
    three: arg3\n\
  - one: arg4");

"three => arg3" kv pair ends up getting dropped from the node[0] assoc array 
(it ends up as an element in the node array, rather than a member of the 
node[0] assoc array).

I was able to (seemingly) correct the issue by making this change on line 390:

- else res[key] = processValue(value);
+ else res[0][key] = processValue(value);

However I'm not entirely certain this is a safe fix (or if it will blow up in 
some corner case), or if it would need accompanying changes elsewhere...

I would like to enable the parser to parse my example YAML though, so that I 
may use it for my application.

Thanks!


Original issue reported on code.google.com by [email protected] on 3 Feb 2014 at 5:31

parsing string as date

YAML.eval('name: test/2')
returns 
{name: Thu Feb 01 2001 00:00:00 GMT+0400 (RTZ 2 (лето))}

I tried to add qoutes to use this value like a string, but it didn't helped.

I've found the reason:
in processValue you can find strings:

if( !isNaN(m = Date.parse(val))) {
    return new Date(m);
}

In my case simply commenting this lines was the decision. But the problem is 
bigger - qoutes doesn't "postulate" strings!

Original issue reported on code.google.com by [email protected] on 15 Dec 2014 at 4:03

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.