Giter Site home page Giter Site logo

jequel's Issues

Options in Gruntfile.js

@riteshe63 Please see the following

Outside options should be the same as the ones inside the task

browserify: {
    options: {
        node: true
       },
       dist : {
       }
}

Should be the same as

browserify: {
    options: {
       },
       dist : {
                options: {
             node: true
               }
       }
}

Rewrite of `select` and `where`

Since we have migrated jequel to the new format, we have to rewrite the select and where code in CS and with new bfs functions.

@dpchn Please handle this. @prakash1517 @riteshe63 your inputs please!

The API for select according to me should be:

jequel.query(obj, {
  select: '0/*/*'
})
// For obj = [{a: {b: 1, c: 2}}]
// Returns [1, 2]  

jequel.query(obj, {
  select: '0/*'
})

//Returns [{b: 1, c: 2}]

Then we can move on to where

JSON Path Iterator / Transformer

Any @rcorp/engineers or any other collaborators are welcome to implement / contribute.

I thought we could have a specific transformation utility that can work like Iterators on JSONPaths.

Signature would be something like ->
transform(jsonObject, jsonPath, transformationFunction)
transformationFunction = function (data)

So given a JSON:

var bookStore = {
    "store": {
        "book": [
            {
                "category": "reference",
                "author": "Nigel Rees",
                "title": "Sayings of the Century",
                "price": 8.95
            },
            {
                "category": "fiction",
                "author": "Evelyn Waugh",
                "title": "Sword of Honour",
                "price": 12.99
            },
            {
                "category": "fiction",
                "author": "Herman Melville",
                "title": "Moby Dick",
                "isbn": "0-553-21311-3",
                "price": 8.99
            },
            {
                "category": "fiction",
                "author": "J. R. R. Tolkien",
                "title": "The Lord of the Rings",
                "isbn": "0-395-19395-8",
                "price": 22.99
            }
        ],
        "bicycle": {
            "color": "red",
            "price": 19.95
        }
    },
    "expensive": 10
}

//Suppose we want to increase the price of each book by 10
var newBookstore = transform(bookStore, '$.*.book', book => book.price += 10)

console.log(newBookStore)

//Outputs
{
    "store": {
        "book": [
            {
                "category": "reference",
                "author": "Nigel Rees",
                "title": "Sayings of the Century",
                "price": 18.95
            },
            {
                "category": "fiction",
                "author": "Evelyn Waugh",
                "title": "Sword of Honour",
                "price": 22.99
            },
            {
                "category": "fiction",
                "author": "Herman Melville",
                "title": "Moby Dick",
                "isbn": "0-553-21311-3",
                "price": 18.99
            },
            {
                "category": "fiction",
                "author": "J. R. R. Tolkien",
                "title": "The Lord of the Rings",
                "isbn": "0-395-19395-8",
                "price": 32.99
            }
        ],
        "bicycle": {
            "color": "red",
            "price": 19.95
        }
    },
    "expensive": 10
}

The equivalent of doing this with plain fors and forEaches would be loooooong! ->

for (var key in bookStore){
    var books = bookStore[key]['book'];
    if (books instanceof Array){
        for (var i = 0; i<books.length; i++){
            books[i].price +=10;
        }
    }
    else {
        for (var bookKey in books){
            var book = books[bookKey];
            book.price +=10;
        }
    }
}  

Infact, for more number of *s in the jsonPath the more horridly long this code can become!

I want to update this to support nested transformations as well. I'll edit this issue then.

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.