Skip to content

Commit 5bf8ecc

Browse files
Convert to ESM
Convert to the ESM model for modern module interactions.
1 parent 080233b commit 5bf8ecc

File tree

8 files changed

+45
-45
lines changed

8 files changed

+45
-45
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"name": "@moot-inc/objectid-converter",
33
"version": "1.1.1",
44
"description": "Converts Microsoft Object IDs to and from SIDs.",
5-
"main": "bin/src/index.js",
6-
"bin": "bin/src/index.js",
5+
"main": "bin/src/index.mjs",
6+
"type": "module",
77
"scripts": {
8-
"start": "node ./bin/index.js",
8+
"start": "node ./bin/index.mjs",
99
"build": "npx tsc",
1010
"test": "npx mocha",
1111
"lint": "npx eslint ./"

src/index.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { convertToSid } from './toSid.mjs';
2+
export { convertToObjectId } from './toObjectId.mjs';

src/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

test/toObjectId.test.ts renamed to test/toObjectId.test.mts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { convertToObjectId, convertToSid } from '../src/';
2-
import chai from 'chai';
1+
import { convertToObjectId, convertToSid } from '../src/index.mjs';
2+
import { expect } from 'chai';
33
import { it } from 'mocha';
44
import { randomUUID } from 'crypto';
55
import { validate } from 'uuid';
@@ -17,9 +17,9 @@ describe('Convert To Object ID', () => {
1717
const results = convertToObjectId(sidToTest);
1818

1919
// Check results for hard coded operation 1
20-
chai.expect(results).to.be.a('string');
21-
chai.expect(results).to.equal(expectedObjectId);
22-
chai.expect(results).to.be.lengthOf(36);
20+
expect(results).to.be.a('string');
21+
expect(results).to.equal(expectedObjectId);
22+
expect(results).to.be.lengthOf(36);
2323

2424
// Finish testing section
2525
done();
@@ -36,9 +36,9 @@ describe('Convert To Object ID', () => {
3636
const results = convertToObjectId(sidToTest);
3737

3838
// Check results for hard coded operation 2
39-
chai.expect(results).to.be.a('string');
40-
chai.expect(results).to.equal(expectedObjectId);
41-
chai.expect(results).to.be.lengthOf(36);
39+
expect(results).to.be.a('string');
40+
expect(results).to.equal(expectedObjectId);
41+
expect(results).to.be.lengthOf(36);
4242

4343
// Finish testing section
4444
done();
@@ -55,10 +55,10 @@ describe('Convert To Object ID', () => {
5555
const resultsRandom = convertToObjectId(sidToTest);
5656

5757
// Check results for a randomly generated SID
58-
chai.expect(resultsRandom).to.be.a('string');
59-
chai.expect(resultsRandom).to.be.equal(expectedObjectId);
60-
chai.expect(resultsRandom).to.be.lengthOf(36);
61-
chai.expect(validate(resultsRandom)).to.equal(true);
58+
expect(resultsRandom).to.be.a('string');
59+
expect(resultsRandom).to.be.equal(expectedObjectId);
60+
expect(resultsRandom).to.be.lengthOf(36);
61+
expect(validate(resultsRandom)).to.equal(true);
6262

6363
// Finish testing section
6464
done();
@@ -67,55 +67,55 @@ describe('Convert To Object ID', () => {
6767
describe('Expected Failures', () => {
6868
it('Reject Invalid Type - Junk String', (done) => {
6969
// Test Junk String input
70-
chai.expect(convertToObjectId.bind(convertToObjectId, 'Hello world!')).to.throw('The provided SID is not an Entra ID SID!');
70+
expect(convertToObjectId.bind(convertToObjectId, 'Hello world!')).to.throw('The provided SID is not an Entra ID SID!');
7171

7272
// Finish testing section
7373
done();
7474
});
7575

7676
it('Reject Invalid Type - Invalid SID', (done) => {
7777
// Test Junk String input
78-
chai.expect(convertToObjectId.bind(convertToObjectId, 'S-1-5-711957920-1182741761-3248840125-1169651596')).to.throw('The provided SID is not an Entra ID SID!');
78+
expect(convertToObjectId.bind(convertToObjectId, 'S-1-5-711957920-1182741761-3248840125-1169651596')).to.throw('The provided SID is not an Entra ID SID!');
7979

8080
// Finish testing section
8181
done();
8282
});
8383

8484
it('Reject Invalid Type - Number', (done) => {
8585
// @ts-expect-error Test number input
86-
chai.expect(convertToObjectId.bind(convertToObjectId, 123456)).to.throw('The provided sid is not a string!');
86+
expect(convertToObjectId.bind(convertToObjectId, 123456)).to.throw('The provided sid is not a string!');
8787

8888
// Finish testing section
8989
done();
9090
});
9191

9292
it('Reject Invalid Type - Boolean', (done) => {
9393
// @ts-expect-error Test boolean input
94-
chai.expect(convertToObjectId.bind(convertToObjectId, true)).to.throw('The provided sid is not a string!');
94+
expect(convertToObjectId.bind(convertToObjectId, true)).to.throw('The provided sid is not a string!');
9595

9696
// Finish testing section
9797
done();
9898
});
9999

100100
it('Reject Invalid Type - Regex', (done) => {
101101
// @ts-expect-error Test Regex input
102-
chai.expect(convertToObjectId.bind(convertToObjectId, /^something$/gum)).to.throw('The provided sid is not a string!');
102+
expect(convertToObjectId.bind(convertToObjectId, /^something$/gum)).to.throw('The provided sid is not a string!');
103103

104104
// Finish testing section
105105
done();
106106
});
107107

108108
it('Reject Invalid Type - Function', (done) => {
109109
// @ts-expect-error Test Function input
110-
chai.expect(convertToObjectId.bind(convertToObjectId, () => true)).to.throw('The provided sid is not a string!');
110+
expect(convertToObjectId.bind(convertToObjectId, () => true)).to.throw('The provided sid is not a string!');
111111

112112
// Finish testing section
113113
done();
114114
});
115115

116116
it('Reject Invalid Type - Object', (done) => {
117117
// @ts-expect-error Test Function input
118-
chai.expect(convertToObjectId.bind(convertToObjectId, { 'hello': 'world!' })).to.throw('The provided sid is not a string!');
118+
expect(convertToObjectId.bind(convertToObjectId, { 'hello': 'world!' })).to.throw('The provided sid is not a string!');
119119

120120
// Finish testing section
121121
done();

test/toSid.test.ts renamed to test/toSid.test.mts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { convertToObjectId, convertToSid } from '../src';
2-
import chai from 'chai';
1+
import { convertToObjectId, convertToSid } from '../src/index.mjs';
2+
import { expect } from 'chai';
33
import { it } from 'mocha';
44
import { randomUUID } from 'crypto';
55

@@ -16,9 +16,9 @@ describe('Convert To SID', () => {
1616
const results = convertToSid(objectIdToTest);
1717

1818
// Check results for hard coded operation
19-
chai.expect(results).to.be.a('string');
20-
chai.expect(results).to.equal(expectedSid);
21-
chai.expect(results).to.be.lengthOf(51);
19+
expect(results).to.be.a('string');
20+
expect(results).to.equal(expectedSid);
21+
expect(results).to.be.lengthOf(51);
2222

2323
// Finish testing section
2424
done();
@@ -35,9 +35,9 @@ describe('Convert To SID', () => {
3535
const results = convertToSid(objectIdToTest);
3636

3737
// Check results for hard coded operation
38-
chai.expect(results).to.be.a('string');
39-
chai.expect(results).to.equal(expectedSid);
40-
chai.expect(results).to.be.lengthOf(52);
38+
expect(results).to.be.a('string');
39+
expect(results).to.equal(expectedSid);
40+
expect(results).to.be.lengthOf(52);
4141

4242
// Finish testing section
4343
done();
@@ -54,9 +54,9 @@ describe('Convert To SID', () => {
5454
const validationId = convertToObjectId(resultsRandom);
5555

5656
// Check results for a randomly generated SID
57-
chai.expect(resultsRandom).to.be.a('string');
58-
chai.expect(resultsRandom).length.to.be.lengthOf.below(257);
59-
chai.expect(validationId).to.equal(generatedObjectId);
57+
expect(resultsRandom).to.be.a('string');
58+
expect(resultsRandom).length.to.be.lengthOf.below(257);
59+
expect(validationId).to.equal(generatedObjectId);
6060

6161
// Finish testing section
6262
done();
@@ -65,55 +65,55 @@ describe('Convert To SID', () => {
6565
describe('Expected Failures', () => {
6666
it('Reject Invalid Type - Junk String', (done) => {
6767
// Test Junk String input
68-
chai.expect(convertToSid.bind(convertToSid, 'Hello world!')).to.throw('The specified object ID is not a valid UUID v4!');
68+
expect(convertToSid.bind(convertToSid, 'Hello world!')).to.throw('The specified object ID is not a valid UUID v4!');
6969

7070
// Finish testing section
7171
done();
7272
});
7373

7474
it('Reject Invalid Type - Invalid UUID', (done) => {
7575
// Test Junk String input
76-
chai.expect(convertToSid.bind(convertToSid, 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')).to.throw('The specified object ID is not a valid UUID v4!');
76+
expect(convertToSid.bind(convertToSid, 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')).to.throw('The specified object ID is not a valid UUID v4!');
7777

7878
// Finish testing section
7979
done();
8080
});
8181

8282
it('Reject Invalid Type - Number', (done) => {
8383
// @ts-expect-error Test number input
84-
chai.expect(convertToSid.bind(convertToSid, 123456)).to.throw('The specified object ID is not a valid UUID v4!');
84+
expect(convertToSid.bind(convertToSid, 123456)).to.throw('The specified object ID is not a valid UUID v4!');
8585

8686
// Finish testing section
8787
done();
8888
});
8989

9090
it('Reject Invalid Type - Boolean', (done) => {
9191
// @ts-expect-error Test boolean input
92-
chai.expect(convertToSid.bind(convertToSid, true)).to.throw('The specified object ID is not a valid UUID v4!');
92+
expect(convertToSid.bind(convertToSid, true)).to.throw('The specified object ID is not a valid UUID v4!');
9393

9494
// Finish testing section
9595
done();
9696
});
9797

9898
it('Reject Invalid Type - Regex', (done) => {
9999
// @ts-expect-error Test Regex input
100-
chai.expect(convertToSid.bind(convertToSid, /^something$/gum)).to.throw('The specified object ID is not a valid UUID v4!');
100+
expect(convertToSid.bind(convertToSid, /^something$/gum)).to.throw('The specified object ID is not a valid UUID v4!');
101101

102102
// Finish testing section
103103
done();
104104
});
105105

106106
it('Reject Invalid Type - Function', (done) => {
107107
// @ts-expect-error Test Function input
108-
chai.expect(convertToSid.bind(convertToSid, () => true)).to.throw('The specified object ID is not a valid UUID v4!');
108+
expect(convertToSid.bind(convertToSid, () => true)).to.throw('The specified object ID is not a valid UUID v4!');
109109

110110
// Finish testing section
111111
done();
112112
});
113113

114114
it('Reject Invalid Type - Object', (done) => {
115115
// @ts-expect-error Test Function input
116-
chai.expect(convertToSid.bind(convertToSid, { 'hello': 'world!' })).to.throw('The specified object ID is not a valid UUID v4!');
116+
expect(convertToSid.bind(convertToSid, { 'hello': 'world!' })).to.throw('The specified object ID is not a valid UUID v4!');
117117

118118
// Finish testing section
119119
done();

tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
2626
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
2727
/* Modules */
28-
"module": "NodeNext", /* Specify what module code is generated. */
28+
"module": "Node16", /* Specify what module code is generated. */
2929
// "rootDir": "./", /* Specify the root folder within your source files. */
30-
"moduleResolution": "Node", /* Specify how TypeScript looks up a file from a given module specifier. */
30+
"moduleResolution": "Node16", /* Specify how TypeScript looks up a file from a given module specifier. */
3131
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
3232
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
3333
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
@@ -101,4 +101,4 @@
101101
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
102102
"skipLibCheck": true /* Skip type checking all .d.ts files. */
103103
}
104-
}
104+
}

0 commit comments

Comments
 (0)