Skip to content

Commit 5e052db

Browse files
committed
wip
1 parent 328452f commit 5e052db

15 files changed

+61
-73
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "textlint-rule-allowed-uris",
33
"version": "1.1.1",
4+
"type": "module",
45
"packageManager": "[email protected]",
56
"workspaces": [
67
"."

src/textlint-rule-allowed-uris.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
*/
55

66
// --------------------------------------------------------------------------------
7-
// Require
7+
// Import
88
// --------------------------------------------------------------------------------
99

10-
const { error, strikethrough } = require('./utils/theme');
11-
const {
10+
import { error, strikethrough } from './utils/theme/index.js';
11+
import {
1212
getUriTypesLink,
1313
getUriTypesImage,
1414
getUriTypesDefinition,
1515
getUriTypesHtml,
16-
} = require('./utils/get-uri-types');
16+
} from './utils/get-uri-types/index.js';
1717

1818
// --------------------------------------------------------------------------------
1919
// Typedefs
@@ -22,19 +22,19 @@ const {
2222
/**
2323
* @import { TextlintRuleContext } from '@textlint/types';
2424
* @import { TxtLinkNode, TxtImageNode, TxtDefinitionNode, TxtHtmlNode } from '@textlint/ast-node-types';
25-
* @import { UriType, Options } from './types';
25+
* @import { UriType, Options } from './types/index.js';
2626
*/
2727

2828
// --------------------------------------------------------------------------------
29-
// Exports
29+
// Export
3030
// --------------------------------------------------------------------------------
3131

3232
/**
3333
* Entry point for the `textlint-rule-allowed-uris` rule.
3434
* @param {TextlintRuleContext} context Context object.
3535
* @param {Options} rawOptions Configuration options.
3636
*/
37-
module.exports = (context, rawOptions) => {
37+
export default function textlintRuleAllowedUris(context, rawOptions) {
3838
/** @type {Options} */
3939
const options = {
4040
allowed: {
@@ -99,4 +99,4 @@ module.exports = (context, rawOptions) => {
9999
return report(node, getUriTypesHtml(node).uriTypes);
100100
},
101101
};
102-
};
102+
}

src/types/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424

2525
// --------------------------------------------------------------------------------
26-
// Exports
26+
// Export
2727
// --------------------------------------------------------------------------------
2828

29-
module.exports = {};
29+
export default {};

src/utils/get-definition-node-uri-type/get-definition-node-uri-type.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
*/
44

55
// --------------------------------------------------------------------------------
6-
// Require
6+
// Import
77
// --------------------------------------------------------------------------------
88

9-
const url = require('node:url');
10-
const mime = require('mime-types');
11-
const { error } = require('../theme');
9+
import url from 'node:url';
10+
import mime from 'mime-types';
11+
import { error } from '../theme/index.js';
1212

1313
// --------------------------------------------------------------------------------
1414
// Helpers
@@ -48,8 +48,8 @@ const getMimeType = async uri => {
4848
* @returns {Promise<'comment' | 'image' | 'link'>} Resolves to `'comment'` for empty(` `) or hash-only(`#`) URIs, `'image'` if the URI's MIME type is an image, and `'link'` for other types of URIs.
4949
* @async
5050
*/
51-
module.exports = async uri => {
51+
export default async function getDefinitionNodeUriType(uri) {
5252
if (['', '#'].includes(uri)) return 'comment';
5353
if ((await getMimeType(uri)).startsWith('image/')) return 'image';
5454
return 'link';
55-
};
55+
}

src/utils/get-definition-node-uri-type/get-definition-node-uri-type.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
*/
44

55
// --------------------------------------------------------------------------------
6-
// Require
6+
// Import
77
// --------------------------------------------------------------------------------
88

9-
const { strictEqual } = require('node:assert');
10-
const { describe, it } = require('node:test');
9+
import { strictEqual } from 'node:assert';
10+
import { describe, it } from 'node:test';
1111

12-
const getDefinitionNodeUriType = require('./get-definition-node-uri-type');
12+
import getDefinitionNodeUriType from './get-definition-node-uri-type.js';
1313

1414
// --------------------------------------------------------------------------------
1515
// Test
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const getDefinitionNodeUriType = require('./get-definition-node-uri-type');
1+
import getDefinitionNodeUriType from './get-definition-node-uri-type.js';
22

3-
module.exports = getDefinitionNodeUriType;
3+
export default getDefinitionNodeUriType;

src/utils/get-uri-types/get-uri-types.js

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
*/
44

55
// --------------------------------------------------------------------------------
6-
// Require
6+
// Import
77
// --------------------------------------------------------------------------------
88

9-
const cheerio = require('cheerio');
10-
11-
const UriTypes = require('../uri-types');
12-
const getDefinitionNodeUriType = require('../get-definition-node-uri-type');
9+
import * as cheerio from 'cheerio';
10+
import UriTypes from '../uri-types/index.js';
11+
import getDefinitionNodeUriType from '../get-definition-node-uri-type/index.js';
1312

1413
// --------------------------------------------------------------------------------
1514
// Typedefs
@@ -20,30 +19,32 @@ const getDefinitionNodeUriType = require('../get-definition-node-uri-type');
2019
*/
2120

2221
// --------------------------------------------------------------------------------
23-
// Helpers
22+
// Export
2423
// --------------------------------------------------------------------------------
2524

2625
/**
2726
* Retrieves URI from a given `Link` node and returns an instance of `UriTypes`.
2827
* @param {TxtLinkNode} node `Link` type node.
2928
* @return {UriTypes}
3029
*/
31-
const getUriTypesLink = ({ url }) => new UriTypes().push({ uri: url, type: 'link' });
30+
export const getUriTypesLink = ({ url }) =>
31+
new UriTypes().push({ uri: url, type: 'link' });
3232

3333
/**
3434
* Retrieves URI from a given `Image` node and returns an instance of `UriTypes`.
3535
* @param {TxtImageNode} node `Image` type node.
3636
* @return {UriTypes}
3737
*/
38-
const getUriTypesImage = ({ url }) => new UriTypes().push({ uri: url, type: 'image' });
38+
export const getUriTypesImage = ({ url }) =>
39+
new UriTypes().push({ uri: url, type: 'image' });
3940

4041
/**
4142
* Retrieves URI from a given `Definition` node and returns an instance of `UriTypes`.
4243
* @param {TxtDefinitionNode} node `Definition` type node.
4344
* @return {Promise<UriTypes>}
4445
* @async
4546
*/
46-
const getUriTypesDefinition = async ({ url }) => {
47+
export const getUriTypesDefinition = async ({ url }) => {
4748
const type = await getDefinitionNodeUriType(url);
4849

4950
return type === 'link' || type === 'image'
@@ -56,7 +57,7 @@ const getUriTypesDefinition = async ({ url }) => {
5657
* @param {TxtHtmlNode} node `Html` type node.
5758
* @return {UriTypes}
5859
*/
59-
const getUriTypesHtml = ({ value }) => {
60+
export const getUriTypesHtml = ({ value }) => {
6061
const uriTypes = new UriTypes();
6162
const $ = cheerio.load(value);
6263

@@ -78,14 +79,3 @@ const getUriTypesHtml = ({ value }) => {
7879

7980
return uriTypes;
8081
};
81-
82-
// --------------------------------------------------------------------------------
83-
// Exports
84-
// --------------------------------------------------------------------------------
85-
86-
module.exports = {
87-
getUriTypesLink,
88-
getUriTypesImage,
89-
getUriTypesDefinition,
90-
getUriTypesHtml,
91-
};

src/utils/get-uri-types/get-uri-types.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
*/
44

55
// --------------------------------------------------------------------------------
6-
// Require
6+
// Import
77
// --------------------------------------------------------------------------------
88

9-
const { deepStrictEqual } = require('node:assert');
10-
const { describe, it } = require('node:test');
9+
import { deepStrictEqual } from 'node:assert';
10+
import { describe, it } from 'node:test';
1111

12-
const {
12+
import {
1313
getUriTypesLink,
1414
getUriTypesImage,
1515
getUriTypesDefinition,
1616
getUriTypesHtml,
17-
} = require('./get-uri-types');
17+
} from './get-uri-types.js';
1818

1919
// --------------------------------------------------------------------------------
2020
// Test

src/utils/get-uri-types/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
const getUriTypes = require('./get-uri-types');
2-
3-
module.exports = getUriTypes;
1+
export * from './get-uri-types.js';

src/utils/theme/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
const theme = require('./theme');
2-
3-
module.exports = theme;
1+
export * from './theme.js';

0 commit comments

Comments
 (0)