jsondiffpatch
jsondiffpatch copied to clipboard
Formatters are not available after create
In node.js after using
var jsondiffpatch = require('jsondiffpatch').create(options);
to create specialized instance, property formatters
(as well as console
) is undefined
on jsondiffpatch
object whereas without using create
they work correctly.
Not a big issue but took me some time to find the problem in the code.
I couldn't find anything in the documentation saying it is not a bug, moreover it says this is a recommended way of using jsondiffpatch in node.js.
that's correct, formatters are not part of a jsondiffpatch instance. instances don't inherit all members of the static main module, I guess maybe that code snippet could make it more clear by not naming the created instance with the same name as the library?
var jsondiffpatch = require('jsondiffpatch');
var jsondiffpatchInstance = jsondiffpatch.create(options);
That looks great and definitely makes it easier to understand the concept for new users. Especially, the line about initialization I was talking above may be misleading a little. Anyway, great project, keep it up [;
This worked for me (ES6 syntax):
import { diff } from 'jsondiffpatch';
import formatters from 'jsondiffpatch/src/formatters';
I am trying to get access to the formatters using the recommended ways but have had no luck. Maybe they don't work in browserified environment? After requiring 'jsondiffpatch' the formatters property is undefined. I am using it within karma running a browserified app bundle.
@chinshr apparently src
disappeared from npm dist so:
import formatters from 'jsondiffpatch/src/formatters';
no longer works.
@benjamine any es6 import
analogy to suggest for below?:
var jsondiffpatch = require('jsondiffpatch');
var jsondiffpatchInstance = jsondiffpatch.create(options);
sadly, i'm not up enough on modules to know why the following results in a null for jsondiffpatch
:
import jsondiffpatch from 'jsondiffpatch'
formatters continue to exist under the main module:
const jsondiffpatch = require('jsondiffpatch');
console.log(jsondiffpatch.formaters));
you can also try console.log(jsondiffpatch.formaters));
at https://benjamine.github.io/jsondiffpatch/demo/index.html (which uses the umd version)
@tony-kerz in ES modules you can import specific members, for example:
import { diff, formatters } from 'jsondiffpatch';
formatters.console.log(diff({ a: 23 }, { a: 3, b: 31 }));
thanks @benjamine the following works great!:
import { diff, formatters } from 'jsondiffpatch';
formatters.console.log(diff({ a: 23 }, { a: 3, b: 31 }));
I am unable to access the jsonpatch formatter (RFC 6902) from the npm package
Hello, sorry for the delayed response!
I believe that formatters are available as described in this comment, so I'll go ahead and close this issue. Let me know if you're still having issues and I can reopen this.