shaunxcode / jsedn Goto Github PK
View Code? Open in Web Editor NEWjavascript implementation of edn
javascript implementation of edn
Should not require underscore, only used minimally anyway so should not be a huge deal to remove.
'a\\b'
is encoded as '"a\\b"'
, should be '"a\\\\b"'
edn.encode('a\\b'); // => '"a\\b"'
edn.parse(edn.encode('a\\b')); // => 'ab'
Something like:
edn.encode({foo: 1, bar: 2}, {mapCommas: true}); // => '{"foo" 1, "bar" 2}'
The regex you have is looking for anything that starts with a #, so when you setTokenAction for 'tagged', it also will mutate Sets since they also begin with a #
When using encode on the result of JSON.stringify, the quote escaping seems to be thrown off.
$ node
> JSON.stringify({a:1});
'{"a":1}'
> JSON.stringify({a:"1"});
'{"a":"1"}'
> var edn = require('jsedn');
> edn.encode(JSON.stringify({a:1}));
'"{"a":1}"'
> edn.encode(JSON.stringify({a:"1"}));
'"{"a":"1"}"'
> edn.parse(edn.encode(JSON.stringify({a:1})));
unexpected end of list
> edn.parse(edn.encode(JSON.stringify({a:"1"})));
unexpected end of list
the ruby edn reader supports meta information, it would not be hard to add this but need to clarify with edn spec if this is going to be officially supported or not.
var o = edn.parse(':a 5}'); // Keyword { ns: null, name: ':a', val: ':a' }
I am calling edn.encode [':find', '?m', ':where', ['?m', ':movie/title']]
trying to get '[:find ?m :where [?m :movie/title]]'
but '?m' turns into "?m" because is recognized as a regular string
I get around by changing the keyword matcher to keyword: pattern: /^[\:\?].*$/
Error: Cannot find module 'type' from '/home/ashnur/foo/node_modules/jsedn/lib'
Module not found: Error: Can't resolve 'fs' in '/home/brian/tmp/XenaGoWidget/node_modules/jsedn/lib'
@ ./node_modules/jsedn/lib/reader.js 275:9-22
@ ./node_modules/jsedn/index.js
@ ./src/XenaGoApp.js
@ ./demo/src/index.js
@ multi ./node_modules/nwb/polyfills.js (webpack)-dev-server/client?/ (webpack)/hot/only-dev-server.js ./demo/src/index.js
Module not found: Error: Can't resolve 'type' in '/home/brian/tmp/XenaGoWidget/node_modules/jsedn/lib'
@ ./node_modules/jsedn/lib/type.js 3:105-120
@ ./node_modules/jsedn/lib/reader.js
@ ./node_modules/jsedn/index.js
@ ./src/XenaGoApp.js
@ ./demo/src/index.js
@ multi ./node_modules/nwb/polyfills.js (webpack)-dev-server/client?/ (webpack)/hot/only-dev-server.js ./demo/src/index.js
I started migrating my test suite from Mocha to Jest for a web server and I use jsedn
in some places.
When I made the change, it threw an error that it cannot find module type
.
Jest automatically provides a global object window
that make support for FrontEnd testing in Node.js but I guess it does not automatically provide type
module.
I think it's not sufficient to test whether global object window
is available to assume type
module is also directly available (in src/type.coffee
). Maybe, you'd like to use type-component
uniformly throughout the entire project, I don't know which one would be the best solutions for this.
I have the following edn string:
var edn = '{"items" [{"title" "Test" "type" "test"}]}'
When I use jsedn.toJS(edn)
I just get the edn string back instead of a JavaScript object
When I do new Vector([':a', 'b']).ednEncode() i get '[::a :b]' instead of [:a 'b'] ... In essence it is adding : to every string without spaces. How could I avoid that?
Ty very much
I haven't thought thru this much ... But i keep running into this kind of problem
edn.encode [':db/add', 42, ':col/field', 'value']
returns (:db/add, 42, :col/field, "value")
In the cases so far I was looking for [:db/add, 42, :col/field, "value"]
I can hack it on ..
encode = ....
else if us.isArray obj
...
"[#{result.join " "}]"
But I was wondering if the default makes sense and/or if some opts would be reasonable ... or if it doesn't make sense at all :)
Current version of coffee-script compiles code very differently - there are a lot of changes that would create noise in PRs. A more common approach is to only publish compiled code to npm, but not to have it in the repo
Version 0.4.0
Tested on macOS Sierra v. 10.12.5
Trying to parse repl-test.core/foo->bar
results int the following error:
provided an invalid symbol repl-test.core/foo->bar
I notice that this is a result of failing to match the following regex (atoms.coffee) in the Symbols
class:
validRegex: /[0-9A-Za-z.*+!\-_?$%&=:#/]+/
This regex does not contain <
or >
.
This example from the readme:
edn.parse("{:x 300 y: 800}").map(function(val, key){
return new edn.Pair(edn.kw("#{key}-squared"), val * val);
});
Throws Error: keyword must start with a :
Using jsedn 0.4.1, I get an error thrown when a keyword contains the ">" character. This is a valid EDN keyword as per the EDN spec.
Symbols begin with a non-numeric character and can contain alphanumeric characters and . * + ! - _ ? $ % & = < >.
Example failing case.
const edn = require("jsedn");
edn.parse("{:a->b 1}")
Uncaught 'provided an invalid symbol :a->b'
This:
jsedn.encode(jsedn.unify('{:uuid #uuid ?a}',{a: "ac24e310-703e-11e5-92c2-d57ad6a6c940"}))
results in
"{:uuid "ac24e310-703e-11e5-92c2-d57ad6a6c940"}"
but I'm trying to get back
"{:uuid #uuid "ac24e310-703e-11e5-92c2-d57ad6a6c940"}"
So how should I go about keeping the tag in the output?
You mention that the choice is to convert a string into a keyword if possible, but it's not consistently so. Here the key "name" becomes a keyword, but the value "walter" doesn't, unless I prepend with a colon:
> edn.encode(new edn.Tagged(new edn.Tag("myApp", "Person"), {"name": "walter", age: 300}));
'#myApp/Person {:name "walter" :age 300}'
> edn.encode(new edn.Tagged(new edn.Tag("myApp", "Person"), {"name": ":walter", age: 300}));
'#myApp/Person {:name :walter :age 300}'
Also, how do I get a symbol from a js string key?
> edn.encode({a:1});
'{:a 1}'
> edn.encode({"a":1});
'{:a 1}'
> edn.encode({":a":1});
'{::a 1}'
> edn.encode({"?a":1});
'{:?a 1}'
Fully support the rest of the number spec!
Hi there, I was reading the documentation and stumbled upon this.
Not sure if it's intended, but right now one of the examples just reads:
edn.setTokenPattern()))
The text above it also doesn't make it super clear what it's about.
try {
edn.parse("{:a 5");
} catch(e) {
console.log('Error:', e); // e is a String here, should be an instance of Error (or of a subclass)
}
It would be nice to move out the support classes for hash_map, vector etc. so that jsedn is mainly the reader and the underlying implementations can be changed easily. Technically this can be done already by just doing edn.Map = MyOtherMap so really this is just about breaking out the default implementations into their own file so that in theory one could build a version w/o them that would utilize mori or the es6 hashmap etc.
To compile to JS, to run tests, etc.
Seems the jsedn column in the conversion table in readme has some problems. The constructors take collections, but the List and Vector examples do not. Don't think those examples work. The example for Set is missing some commas, so that doesn't work either.
Please add a license for the code.
A 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.