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

Move to ESM #83

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
4 changes: 1 addition & 3 deletions .c8rc.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"all": true,
"exclude": [
"{coverage,test}/**",
".eslintrc.js",
"index.d.ts"
"{coverage,test}/**"
],
"reporter": [
"html",
Expand Down
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = false

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
indent_size = 2
15 changes: 0 additions & 15 deletions .eslintrc.js

This file was deleted.

2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto eol=lf
*.snap binary
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [^10.18.0, ^12.14.0, ^14]
node-version: [18, 20, 21]
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: actions/setup-node@v1
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install --no-audit
Expand Down
40 changes: 21 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
'use strict'
import {compare, compareDescriptors} from './lib/compare.js';
import describe from './lib/describe.js';
import {diff, diffDescriptors} from './lib/diff.js';
import {format, formatDescriptor} from './lib/format.js';
import {serialize, deserialize} from './lib/serialize.js';

const compare = require('./lib/compare')
const describe = require('./lib/describe')
const diff = require('./lib/diff')
const format = require('./lib/format')
const serialize = require('./lib/serialize')
export {compare, compareDescriptors} from './lib/compare.js';
export {default as describe} from './lib/describe.js';
export {diff, diffDescriptors} from './lib/diff.js';
export {format, formatDescriptor} from './lib/format.js';
export {serialize, deserialize} from './lib/serialize.js';

exports.compare = compare.compare
exports.compareDescriptors = compare.compareDescriptors

exports.describe = describe

exports.diff = diff.diff
exports.diffDescriptors = diff.diffDescriptors

exports.format = format.format
exports.formatDescriptor = format.formatDescriptor

exports.serialize = serialize.serialize
exports.deserialize = serialize.deserialize
export default {
compare,
compareDescriptors,
describe,
diff,
diffDescriptors,
format,
formatDescriptor,
serialize,
deserialize,
};
72 changes: 38 additions & 34 deletions lib/Circular.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
'use strict'

class Circular {
constructor () {
this.stack = new Map()
}

add (descriptor) {
if (this.stack.has(descriptor)) throw new Error('Already in stack')

if (descriptor.isItem !== true && descriptor.isMapEntry !== true && descriptor.isProperty !== true) {
this.stack.set(descriptor, this.stack.size + 1)
}
return this
}

delete (descriptor) {
if (this.stack.has(descriptor)) {
if (this.stack.get(descriptor) !== this.stack.size) throw new Error('Not on top of stack')
this.stack.delete(descriptor)
}
return this
}

has (descriptor) {
return this.stack.has(descriptor)
}

get (descriptor) {
return this.stack.has(descriptor)
? this.stack.get(descriptor)
: 0
}
export default class Circular {
constructor() {
this.stack = new Map();
}

add(descriptor) {
if (this.stack.has(descriptor)) {
throw new Error('Already in stack');
}

if (descriptor.isItem !== true && descriptor.isMapEntry !== true && descriptor.isProperty !== true) {
this.stack.set(descriptor, this.stack.size + 1);
}

return this;
}

delete(descriptor) {
if (this.stack.has(descriptor)) {
if (this.stack.get(descriptor) !== this.stack.size) {
throw new Error('Not on top of stack');
}

this.stack.delete(descriptor);
}

return this;
}

has(descriptor) {
return this.stack.has(descriptor);
}

get(descriptor) {
return this.stack.has(descriptor)
? this.stack.get(descriptor)
: 0;
}
}
module.exports = Circular
33 changes: 15 additions & 18 deletions lib/Indenter.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
'use strict'
export default class Indenter {
constructor(level, step) {
this.level = level;
this.step = step;
this.value = step.repeat(level);
}

class Indenter {
constructor (level, step) {
this.level = level
this.step = step
this.value = step.repeat(level)
}
increase() {
return new Indenter(this.level + 1, this.step);
}

increase () {
return new Indenter(this.level + 1, this.step)
}
decrease() {
return new Indenter(this.level - 1, this.step);
}

decrease () {
return new Indenter(this.level - 1, this.step)
}

toString () {
return this.value
}
toString() {
return this.value;
}
}
module.exports = Indenter
37 changes: 17 additions & 20 deletions lib/Registry.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
'use strict'
export default class Registry {
constructor() {
this.counter = 0;
this.map = new WeakMap();
}

class Registry {
constructor () {
this.counter = 0
this.map = new WeakMap()
}
has(value) {
return this.map.has(value);
}

has (value) {
return this.map.has(value)
}
get(value) {
return this.map.get(value).descriptor;
}

get (value) {
return this.map.get(value).descriptor
}

alloc (value) {
const index = ++this.counter
const pointer = { descriptor: null, index }
this.map.set(value, pointer)
return pointer
}
alloc(value) {
const index = ++this.counter;
const pointer = {descriptor: null, index};
this.map.set(value, pointer);
return pointer;
}
}
module.exports = Registry
Loading