Skip to content

Commit 894f22f

Browse files
authored
Add types
Closes GH-1. Reviewed-by: Christian Murphy <[email protected]> Reviewed-by: Junyoung Choi <[email protected]> Reviewed-by: Titus Wormer <[email protected]>
1 parent 7ff68f6 commit 894f22f

File tree

5 files changed

+102
-3
lines changed

5 files changed

+102
-3
lines changed

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,21 @@
2525
"type": "module",
2626
"main": "./index.mjs",
2727
"module": "./index.mjs",
28+
"types": "types",
2829
"files": [
29-
"index.mjs"
30+
"index.mjs",
31+
"types/index.d.ts"
3032
],
3133
"dependencies": {
34+
"@types/xast": "^1.0.0",
3235
"bcp-47-normalize": "^1.0.0",
3336
"unist-builder": "^2.0.0",
3437
"xastscript": "^2.0.0"
3538
},
3639
"devDependencies": {
3740
"c8": "^7.0.0",
3841
"concat-stream": "^2.0.0",
42+
"dtslint": "^4.0.0",
3943
"prettier": "^2.0.0",
4044
"regenerate": "^1.0.0",
4145
"remark-cli": "^9.0.0",
@@ -48,7 +52,8 @@
4852
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
4953
"test-api": "node test.mjs",
5054
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node --experimental-modules test.mjs",
51-
"test": "npm run format && npm run test-coverage"
55+
"test-types": "dtslint types",
56+
"test": "npm run format && npm run test-coverage && npm run test-types"
5257
},
5358
"prettier": {
5459
"tabWidth": 2,
@@ -78,7 +83,10 @@
7883
"no-self-compare": "off",
7984
"unicorn/prefer-number-properties": "off",
8085
"unicorn/prefer-type-error": "off"
81-
}
86+
},
87+
"ignores": [
88+
"types"
89+
]
8290
},
8391
"remarkConfig": {
8492
"plugins": [

types/index.d.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Minimum TypeScript Version: 3.5
2+
3+
import {Root} from 'xast'
4+
5+
/**
6+
* Entries represent a single URL and describe them with metadata.
7+
*/
8+
export interface Entry {
9+
/**
10+
* Full URL.
11+
*
12+
* @see https://www.sitemaps.org/protocol.html#locdef
13+
*
14+
* @example 'https://example.org/'
15+
*/
16+
url: string
17+
18+
/**
19+
* Value indicating when the page last changed.
20+
*/
21+
modified?: Date | string | number
22+
23+
/**
24+
* BCP 47 tag indicating the language of the page.
25+
*
26+
* @see https://github.com/wooorm/bcp-47
27+
*
28+
* @example 'en-GB'
29+
*/
30+
lang?: string
31+
32+
/**
33+
* Translations of the page, where each key is a BCP 47 tag and each value an entry.
34+
*
35+
* Alternate resources inherit fields from the entry they are described in.
36+
*
37+
* @see https://github.com/wooorm/bcp-47
38+
*/
39+
alternate?: Record<string, string | Omit<Entry, 'lang' | 'alternate'>>
40+
}
41+
42+
/**
43+
* Build a sitemap.
44+
*
45+
* @param data URLs to build a sitemap for.
46+
*/
47+
export function sitemap(data: Array<string | Entry>): Root

types/test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {sitemap} from 'xast-util-sitemap'
2+
3+
sitemap() // $ExpectError
4+
sitemap([
5+
'https://example.com',
6+
{url: 'https://example.com'},
7+
{url: 'https://example.com', modified: new Date()},
8+
{url: 'https://example.com', modified: Date.now()},
9+
{url: 'https://example.com', modified: '01-02-2021'},
10+
{url: 'https://example.com', lang: 'en-GB'},
11+
{
12+
url: 'https://example.com',
13+
lang: 'en-GB',
14+
alternate: {'de-AT': 'https://example.at'}
15+
},
16+
{
17+
url: 'https://example.com',
18+
lang: 'en-GB',
19+
alternate: {'de-AT': {url: 'https://example.at', modified: Date.now()}}
20+
}
21+
])

types/tsconfig.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"module": "es2015",
4+
"lib": ["es2015"],
5+
"moduleResolution": "node",
6+
"strict": true,
7+
"noEmit": true,
8+
"baseUrl": ".",
9+
"paths": {
10+
"xast-util-sitemap": ["."]
11+
}
12+
}
13+
}

types/tslint.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
{
3+
"extends": "dtslint/dtslint.json",
4+
"rules": {
5+
"no-redundant-jsdoc": false,
6+
"no-redundant-jsdoc-2": true,
7+
"semicolon": false,
8+
"whitespace": false
9+
}
10+
}

0 commit comments

Comments
 (0)