adleroliveira / dreamjs Goto Github PK
View Code? Open in Web Editor NEWA lightweight json data generator.
License: MIT License
A lightweight json data generator.
License: MIT License
Have you thought about using json schemas like the one found here?
http://jsonschema.net/#/
html:
<script src="bower_components/requirejs/require.js"></script>js:
var dream = require("bower_components/dreamjs/dream.js")
something error:
Uncaught Error: Module name "bower_components/dreamjs/dream.js" has not been loaded yet for context: _. Use require([])
It would be great to have some online endpoint url to get the generated json. For example when you create a prototype app and you need random data for it.
I made a quick example http://toastman.github.io/mockapitron/
Maybe it will help someone.
for e.g
{
"587b0cc9-d6e5-40c3-b874-aee034b40001" : {
name : 'Tom',
age: 32
},
"232b0cc9-d6e5-40c3-b874-aee034b40001" : {
name : 'Hilding',
age: 31
}
}
where 587b0cc9-d6e5-40c3-b874-aee034b40001 is guid (a pre-defined chance custom type)
Regards & thanks
Kapil
@adleroliveira, Hey There thanks for merging my PR, love the library. When you get the change can you update the npm package?
It is easier to see what has happened between releases and since the last release, in case there are git tags pushed to the repository.
They are trivial to create afterwards, when knowing the correct commit hashes, for example:
git tag v0.1.7 faaf6b0982a28c0d117f87c3192b37df63d0bc38
git push --tags
Maybe i'm missing something. (probably)
In the command line i ran : npm install --save dreamjs
When i follow this example : https://github.com/adleroliveira/dreamjs#generate-and-generaternd i only get empty objects.
Here's my code :
var dream = require('dreamjs');
dream.schema('User', {
name: String
});
var data1 = dream
.useSchema('User')
.generate(3)
.output();
var data2 = dream
.useSchema('User')
.generateRnd(3)
.output();
console.log(data1); // [ { name: '' }, { name: '' }, { name: '' } ]
console.log(data2); // [ { name: '' }, { name: '' }, { name: '' } ]
I do not understand why names in data2 are empty.
Am i missing something ?
Thanks !
I need date type with minimum date, date range, maximum date, default date..
Hi,
I really want to use dreamjs in my project in order to generate data for testing purposes. However I have this nasty error:
karma start
[2017-02-20 13:31:00.267] [INFO] karma - Karma v1.3.0 server started at http://l
ocalhost:9876/
[2017-02-20 13:31:00.270] [INFO] launcher - Launching browser PhantomJS with unl
imited concurrency
[2017-02-20 13:31:00.274] [INFO] launcher - Starting browser PhantomJS
[2017-02-20 13:31:02.664] [INFO] PhantomJS 2.1.1 (Windows 7 0.0.0) - Connected o
n socket /#vnb5GX37u5VGf7QKAAAA with id 91341862
PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR
SyntaxError: Cannot declare a parameter named 'input' in strict mode
at src/test/js/test-index.js:171070
I was able to fix this error by making 2 changes in dream.js and update the name of variable wherever is used in code:
Line 93: self.input = function input(input) { --> self.input = function input(myinput) {
Line 190: self.schema = function schema(schema) { --> self.schema = function schema(myschema) {
Please if you have time make this change for next release.
Hi! i love dreamjs...
Can you udpate to the latest chance release...
They are new type like 'company'
if we use : dream.schema('workspace', { name: 'company' });
its not working
So for now, i have updated chance to the latest version and use your custom type
dream.customType('company', () => chance.company());
to make it work
Hope you can update!
Thx
Yves L.
Hi @adleroliveira,
Saw this at top of /r/node, congrats!
I noticed that dreamjs supports an async API but its implementation is fully synchronous. This will lead to errors in usage like the following:
dream.output((err, result) => {
useResult(result);
});
var useResult = () => {
// do something with result...
}
The async callback model of node guarantees that the callback won't be called until the next turn of the event loop (at the earliest), so the example should be 100% safe.
It looks like your implementation does everything synchronously and calls the callback synchronously too, so the useResult(result);
line gets called before useResult
is defined, and an error ensues.
More generally, there's no point offering callbacks/Promises/streams if the implementation is synchronous. The synchronous implementation completely starves the event loop until it finishes, so there is no opportunity for other code to run. I would suggest:
setImmediate
. When the full output is ready, then return the result through the callback/Promise/etc.As for which is best, I'd say it depends how much processing is likely to be involved in producing deamjs outputs. If it's no more than a millisecond or two in the worst case, you might as well just keep it synchronous.
On the other hand if you get people wanting to generate MBs of test data from this, that could take a while to generate. Your current implementation will starve the event loop even though the API 'looks' asychronous. In this case you should definitely break up the work as suggested above.
Again, nice lib, and that's just my 2c!
It seems all dreamjs api is not async, how dreamjs use promises in future?
Passing a object Number as value of a property is returning as Date. The fix is very simple. Just compare propertyValue === Date.
as title
I want the list:
[
{id: number, name: ' '},
{id: number + 1, name: ' '},
{id: number + 2, name: ' '},
...
]
id have connection ?
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.