Skip to content

Commit fc4b418

Browse files
committed
feat(toJSON): add spec "should expose the property at the JSON.stringify"
1 parent bd7570f commit fc4b418

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ export default class Token {
3232
get meta() {
3333
return this[META];
3434
}
35+
toJSON() {
36+
return {
37+
type: this.type,
38+
value: this.value,
39+
options: this.options,
40+
meta: this.meta,
41+
};
42+
}
3543

3644
/**
3745
* @method clone

test/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ test('clone is should be changed meta-information only', (t) => {
4444
t.true(token.meta.transformer === undefined);
4545
t.true(clonedToken.meta.transformer === 'johndue');
4646
});
47+
48+
test('should expose the property at the JSON.stringify', (t) => {
49+
const string = JSON.stringify(new Token('text', 'foo'));
50+
t.true(string === JSON.stringify({ type: 'text', value: 'foo', options: {}, meta: {} }));
51+
});

0 commit comments

Comments
 (0)