Skip to content

Commit e9b90c5

Browse files
committed
WIP
1 parent 3723ab2 commit e9b90c5

File tree

6 files changed

+22
-14
lines changed

6 files changed

+22
-14
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"no-constant-condition": 0,
2828
"no-useless-escape": 0,
2929
"no-console": "error",
30-
"eqeqeq": ["error", "smart"],
3130
"capitalized-comments": [
3231
"warn",
3332
"always",
@@ -66,6 +65,7 @@
6665
{
6766
"selector": "parameter",
6867
"format": ["camelCase"],
68+
"leadingUnderscore": "allowSingleOrDouble",
6969
"trailingUnderscore": "allowSingleOrDouble"
7070
},
7171
{

src/Id.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ class IdInternal extends Uint8Array {
1111
public static create(): Id;
1212
public static create(length: number): Id;
1313
public static create(array: ArrayLike<number> | ArrayBufferLike): Id;
14-
public static create(buffer: ArrayBufferLike, byteOffset?: number, length?: number): Id;
14+
public static create(
15+
buffer: ArrayBufferLike,
16+
byteOffset?: number,
17+
length?: number,
18+
): Id;
1519
public static create(...args: Array<any>): Id {
1620
// @ts-ignore: spreading into Uint8Array constructor
1721
return new IdInternal(...args) as Id;
1822
}
1923

20-
public [Symbol.toPrimitive](hint: 'string' | 'number' | 'default'): string {
24+
public [Symbol.toPrimitive](_hint: 'string' | 'number' | 'default'): string {
2125
return utils.toString(this as unknown as Id);
2226
}
2327

src/utils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function* take<T>(g: Iterator<T>, l: number): Generator<T> {
7474

7575
function toString(id: Uint8Array): string {
7676
return String.fromCharCode(...id);
77-
// const b = Buffer.from(id.buffer, id.byteOffset, id.byteLength);
77+
// Const b = Buffer.from(id.buffer, id.byteOffset, id.byteLength);
7878
// return b.toString('binary');
7979
}
8080

@@ -84,7 +84,7 @@ function fromString(idString: string): Id | undefined {
8484
id[i] = idString.charCodeAt(i);
8585
}
8686
return id;
87-
// const b = Buffer.from(idString, 'binary');
87+
// Const b = Buffer.from(idString, 'binary');
8888
// return IdInternal.create(b.buffer, b.byteOffset, b.byteLength);
8989
}
9090

@@ -154,7 +154,11 @@ function fromBuffer(idBuffer: Buffer): Id | undefined {
154154
if (idBuffer.byteLength !== 16) {
155155
return;
156156
}
157-
return IdInternal.create(idBuffer.buffer, idBuffer.byteOffset, idBuffer.byteLength);
157+
return IdInternal.create(
158+
idBuffer.buffer,
159+
idBuffer.byteOffset,
160+
idBuffer.byteLength,
161+
);
158162
}
159163

160164
/**

tests/IdDeterministic.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe('IdDeterministic', () => {
8181
expect(idB1.equals(idB2)).toBe(true);
8282
});
8383
test('ids can be used as record indexes', () => {
84-
const idGen = new IdDeterministic({namespace: 'foo'});
84+
const idGen = new IdDeterministic({ namespace: 'foo' });
8585
const ids = [
8686
idGen.get('a'),
8787
idGen.get('b'),
@@ -97,12 +97,12 @@ describe('IdDeterministic', () => {
9797
}
9898
});
9999
test('ids in strings can be compared for equality', () => {
100-
const idGen = new IdDeterministic({namespace: 'foo'});
100+
const idGen = new IdDeterministic({ namespace: 'foo' });
101101
const id1 = idGen.get('a');
102102
const id2 = idGen.get('a');
103-
// objects will be different
103+
// Objects will be different
104104
expect(id1 == id2).toBe(false);
105-
// deterministic ids are the same
105+
// Deterministic ids are the same
106106
expect(id1.toString() == id2.toString()).toBe(true);
107107
expect(id1.toString()).toBe(id2 + '');
108108
expect(id2.toString()).toBe(String(id1));

tests/IdRandom.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ describe('IdRandom', () => {
6060
const idGen = new IdRandom();
6161
const id1 = idGen.get();
6262
const id2 = idGen.get();
63-
// objects will be different
63+
// Objects will be different
6464
expect(id1 == id2).toBe(false);
65-
// random ids are different
65+
// Random ids are different
6666
expect(id1.toString() == id2.toString()).toBe(false);
6767
expect(id1.toString()).toBe(id1 + '');
6868
expect(id2.toString()).toBe(String(id2));

tests/IdSortable.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ describe('IdSortable', () => {
182182
const idGen = new IdSortable();
183183
const id1 = idGen.get();
184184
const id2 = idGen.get();
185-
// objects will be different
185+
// Objects will be different
186186
expect(id1 == id2).toBe(false);
187-
// sortable ids are different
187+
// Sortable ids are different
188188
expect(id1.toString() == id2.toString()).toBe(false);
189189
expect(id1.toString()).toBe(id1 + '');
190190
expect(id2.toString()).toBe(String(id2));

0 commit comments

Comments
 (0)