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
}
}
}
Break `bfsTransform` into `bfsTransform` and `bfsTraverse`
https://github.com/rcorp/jequel/blob/master/src/bfs-transform.coffee is pretty big and contains two different logical components.
We should break this down into bfsTraverse
and bfsTransform
. bfsTransform
would be the same as before. bfsTraverse
needs to have a simple API, where we would execute a function for every node traversed via Breadth First Search.
API and examples in my next comment
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 for
s and forEach
es 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.
Full conformance with RFC 6901 JSONPointer
RFC 6901 - JSON Pointer specifies the path
we are using for all jequel
functions.
We need tests to ensure we are in full conformance with this Internet Standard.
Eg: According to https://tools.ietf.org/html/rfc6901#section-5
pointer.getPath('', [{a: 1}])
// returns [{a:1}]
What goes in options & browserifyOptions in Gruntfile.js
@riteshe63 Some options work on writing them inside options
and some inside browserifyOptions
. Please look into the this. The Grunt task is grunt-browserify
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.