Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easy to get JSON that can be re-used by code that is not aware of json-bigint (aka stringify big numbers) #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tkissing
Copy link

See the updated "test" why this is useful :)

@sidorares
Copy link
Owner

Not sure if you really need this in the package - if you need stringified ints instead of BigNumber's you can add reviver in your own code, it's just 3 lines function as you demonstrated.

My biggest concern is that you proposing to change JSON.parse api ( probably in backward compartible way, but still). Please convince me with real life examples :)

Also, if you really want to help with this project - could you make a proper test suite out of test.js ( preferably using mocha )

anyway, thanks for your suggestion and waiting for more discussion

@KeKs0r
Copy link

KeKs0r commented Sep 24, 2015

@sidorares
I actually have a use case where I need to sent a BigInt to an API. And somehow I can't construct it without this PR.

thats my test that only passes with @tkissing changes:

    describe('BigINt', {only:true},function(){
        it('is the same', function(done){
            var JSONbig = require('json-bigint');
            var BigNumber = require('bignumber.js');
            var input = '{"id":40564371973213694,"custom_id":"2"}';
            var parsed = JSONbig.parse(input);
            var output = JSONbig.stringify(parsed);
            expect(input).equal(output);

            var ownJSON = {
                id: new BigNumber("40564371973213694"),
                custom_id: "2"
            };
            var outOwn = JSONbig.stringify(ownJSON);
            expect(outOwn).equal(input);
            done();
        });
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants