@vuepress/shared 2.0.0-rc.26 → 2.0.0-rc.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.d.ts +139 -117
  2. package/dist/index.js +187 -158
  3. package/package.json +20 -26
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { MarkdownItHeader } from '@mdit-vue/types';
1
+ import { MarkdownItHeader } from "@mdit-vue/types";
2
2
 
3
+ //#region src/types/head.d.ts
3
4
  /**
4
5
  * Config for `<head>` tags
5
6
  */
@@ -22,7 +23,8 @@ type HeadTagEmpty = 'base' | 'link' | 'meta' | 'script';
22
23
  * Attributes to be set for tags in `<head>`
23
24
  */
24
25
  type HeadAttrsConfig = Record<string, boolean | string>;
25
-
26
+ //#endregion
27
+ //#region src/types/locale.d.ts
26
28
  /**
27
29
  * Locales config, a key-value object
28
30
  *
@@ -36,34 +38,35 @@ type LocaleConfig<T extends LocaleData = LocaleData> = Record<string, Partial<T>
36
38
  * Locales data
37
39
  */
38
40
  type LocaleData = Record<never, never>;
39
-
41
+ //#endregion
42
+ //#region src/types/page.d.ts
40
43
  /**
41
44
  * Base type of vuepress page
42
45
  */
43
46
  interface PageBase<ExtraPageFrontmatter extends Record<string, unknown> = Record<string, unknown>> {
44
- /**
45
- * Route path of the page
46
- *
47
- * Firstly inferred from the file path
48
- *
49
- * Might be overridden by permalink
50
- *
51
- * @example '/guide/index.html'
52
- * @example '/2020/02/02/hello-world.html'
53
- */
54
- path: string;
55
- /**
56
- * Title of the page
57
- */
58
- title: string;
59
- /**
60
- * Language of the page
61
- */
62
- lang: string;
63
- /**
64
- * Front matter of the page
65
- */
66
- frontmatter: PageFrontmatter<ExtraPageFrontmatter>;
47
+ /**
48
+ * Route path of the page
49
+ *
50
+ * Firstly inferred from the file path
51
+ *
52
+ * Might be overridden by permalink
53
+ *
54
+ * @example '/guide/index.html'
55
+ * @example '/2020/02/02/hello-world.html'
56
+ */
57
+ path: string;
58
+ /**
59
+ * Title of the page
60
+ */
61
+ title: string;
62
+ /**
63
+ * Language of the page
64
+ */
65
+ lang: string;
66
+ /**
67
+ * Front matter of the page
68
+ */
69
+ frontmatter: PageFrontmatter<ExtraPageFrontmatter>;
67
70
  }
68
71
  /**
69
72
  * Vuepress page data
@@ -76,53 +79,54 @@ type PageData<ExtraPageData extends Record<string, unknown> = Record<string, unk
76
79
  * so we cannot guarantee the type safety
77
80
  */
78
81
  type PageFrontmatter<T extends Record<string, unknown> = Record<string, unknown>> = Partial<T> & {
79
- date?: Date | string;
80
- description?: string;
81
- head?: HeadConfig[];
82
- lang?: string;
83
- layout?: string;
84
- permalink?: string | null;
85
- permalinkPattern?: string | null;
86
- routeMeta?: Record<string, unknown>;
87
- title?: string;
82
+ date?: Date | string;
83
+ description?: string;
84
+ head?: HeadConfig[];
85
+ lang?: string;
86
+ layout?: string;
87
+ permalink?: string | null;
88
+ permalinkPattern?: string | null;
89
+ routeMeta?: Record<string, unknown>;
90
+ title?: string;
88
91
  };
89
92
  /**
90
93
  * Vuepress page header
91
94
  */
92
95
  type PageHeader = MarkdownItHeader;
93
-
96
+ //#endregion
97
+ //#region src/types/site.d.ts
94
98
  /**
95
99
  * Vuepress site data
96
100
  */
97
101
  interface SiteData extends SiteLocaleData {
98
- /**
99
- * The base URL the site will be deployed at
100
- *
101
- * It should always start and end with a slash
102
- *
103
- * @default '/'
104
- */
105
- base: '/' | `/${string}/`;
106
- /**
107
- * Specify locales for i18n support
108
- *
109
- * It will override the root-level site data in different subpath
110
- *
111
- * @example
112
- * {
113
- * '/en/': {
114
- * lang: 'en-US',
115
- * title: 'Hello',
116
- * description: 'This will take effect under /en/ subpath',
117
- * },
118
- * '/zh/': {
119
- * lang: 'zh-CN',
120
- * title: '你好',
121
- * description: '它将会在 /zh/ 子路径下生效',
122
- * }
123
- * }
124
- */
125
- locales: SiteLocaleConfig;
102
+ /**
103
+ * The base URL the site will be deployed at
104
+ *
105
+ * It should always start and end with a slash
106
+ *
107
+ * @default '/'
108
+ */
109
+ base: '/' | `/${string}/`;
110
+ /**
111
+ * Specify locales for i18n support
112
+ *
113
+ * It will override the root-level site data in different subpath
114
+ *
115
+ * @example
116
+ * {
117
+ * '/en/': {
118
+ * lang: 'en-US',
119
+ * title: 'Hello',
120
+ * description: 'This will take effect under /en/ subpath',
121
+ * },
122
+ * '/zh/': {
123
+ * lang: 'zh-CN',
124
+ * title: '你好',
125
+ * description: '它将会在 /zh/ 子路径下生效',
126
+ * }
127
+ * }
128
+ */
129
+ locales: SiteLocaleConfig;
126
130
  }
127
131
  /**
128
132
  * Locales data of vuepress site
@@ -134,54 +138,57 @@ interface SiteData extends SiteLocaleData {
134
138
  * used for specific locale
135
139
  */
136
140
  interface SiteLocaleData {
137
- /**
138
- * Language for the site
139
- *
140
- * @default 'en-US'
141
- */
142
- lang: string;
143
- /**
144
- * Title for the site
145
- *
146
- * @default ''
147
- */
148
- title: string;
149
- /**
150
- * Description for the site
151
- *
152
- * @default ''
153
- */
154
- description: string;
155
- /**
156
- * Head config
157
- *
158
- * Describe the tags to be appended into the `<head>` tag
159
- *
160
- * @default []
161
- *
162
- * @example ['link', { rel: 'icon', href: '/logo.png' }]
163
- * @example ['style', { type: 'text/css' }, 'p { color: red; }']
164
- */
165
- head: HeadConfig[];
141
+ /**
142
+ * Language for the site
143
+ *
144
+ * @default 'en-US'
145
+ */
146
+ lang: string;
147
+ /**
148
+ * Title for the site
149
+ *
150
+ * @default ''
151
+ */
152
+ title: string;
153
+ /**
154
+ * Description for the site
155
+ *
156
+ * @default ''
157
+ */
158
+ description: string;
159
+ /**
160
+ * Head config
161
+ *
162
+ * Describe the tags to be appended into the `<head>` tag
163
+ *
164
+ * @default []
165
+ *
166
+ * @example ['link', { rel: 'icon', href: '/logo.png' }]
167
+ * @example ['style', { type: 'text/css' }, 'p { color: red; }']
168
+ */
169
+ head: HeadConfig[];
166
170
  }
167
171
  /**
168
172
  * Site locale config
169
173
  */
170
174
  type SiteLocaleConfig = LocaleConfig<SiteLocaleData>;
171
-
175
+ //#endregion
176
+ //#region src/types/ssr.d.ts
172
177
  /**
173
178
  * Context for SSR
174
179
  */
175
180
  interface VuepressSSRContext {
176
- lang: string;
177
- head: HeadConfig[];
181
+ lang: string;
182
+ head: HeadConfig[];
178
183
  }
179
-
184
+ //#endregion
185
+ //#region src/utils/links/isLinkExternal.d.ts
180
186
  /**
181
187
  * Determine a link is external or not
182
188
  */
183
189
  declare const isLinkExternal: (link: string, base?: string) => boolean;
184
-
190
+ //#endregion
191
+ //#region src/utils/links/isLinkHttp.d.ts
185
192
  /**
186
193
  * Determine a link is http link or not
187
194
  *
@@ -190,82 +197,97 @@ declare const isLinkExternal: (link: string, base?: string) => boolean;
190
197
  * - //github.com
191
198
  */
192
199
  declare const isLinkHttp: (link: string) => boolean;
193
-
200
+ //#endregion
201
+ //#region src/utils/links/isLinkWithProtocol.d.ts
194
202
  /**
195
203
  * Determine a link has protocol or not
196
204
  */
197
205
  declare const isLinkWithProtocol: (link: string) => boolean;
198
-
206
+ //#endregion
207
+ //#region src/utils/routes/inferRoutePath.d.ts
199
208
  /**
200
209
  * Infer route path of the given raw path
201
210
  */
202
211
  declare const inferRoutePath: (rawPath: string) => string;
203
-
212
+ //#endregion
213
+ //#region src/utils/routes/normalizeRoutePath.d.ts
204
214
  /**
205
215
  * Normalize the given pathname path to the final route path
206
216
  */
207
217
  declare const normalizeRoutePath: (pathname: string, current?: string) => string;
208
-
218
+ //#endregion
219
+ //#region src/utils/routes/resolveLocalePath.d.ts
209
220
  /**
210
221
  * Resolve the matched locale path of route path
211
222
  */
212
223
  declare const resolveLocalePath: (locales: LocaleConfig, routePath: string) => string;
213
-
224
+ //#endregion
225
+ //#region src/utils/routes/resolveRoutePathFromUrl.d.ts
214
226
  /**
215
227
  * For a give URL, remove the origin and the site base to get the route path
216
228
  */
217
229
  declare const resolveRoutePathFromUrl: (url: string, base?: string) => string;
218
-
230
+ //#endregion
231
+ //#region src/utils/routes/splitPath.d.ts
219
232
  /**
220
233
  * Split a path into pathname and hashAndQueries
221
234
  */
222
235
  declare const splitPath: (path: string) => {
223
- pathname: string;
224
- hashAndQueries: string;
236
+ pathname: string;
237
+ hashAndQueries: string;
225
238
  };
226
-
239
+ //#endregion
240
+ //#region src/utils/dedupeHead.d.ts
227
241
  /**
228
242
  * Dedupe head config with identifier
229
243
  *
230
244
  * Items that appear earlier have higher priority
231
245
  */
232
246
  declare const dedupeHead: (head: HeadConfig[]) => HeadConfig[];
233
-
247
+ //#endregion
248
+ //#region src/utils/ensureLeadingSlash.d.ts
234
249
  /**
235
250
  * Ensure a url string to have leading slash /
236
251
  */
237
252
  declare const ensureLeadingSlash: (str: string) => string;
238
-
253
+ //#endregion
254
+ //#region src/utils/ensureEndingSlash.d.ts
239
255
  /**
240
256
  * Ensure a url string to have ending slash /
241
257
  */
242
258
  declare const ensureEndingSlash: (str: string) => string;
243
-
259
+ //#endregion
260
+ //#region src/utils/formatDateString.d.ts
244
261
  /**
245
262
  * Format a date string to `yyyy-MM-dd`
246
263
  */
247
264
  declare const formatDateString: (str: string, defaultDateString?: string) => string;
248
-
265
+ //#endregion
266
+ //#region src/utils/omit.d.ts
249
267
  /**
250
268
  * Omit properties from an object
251
269
  */
252
270
  declare const omit: <T extends Record<string, unknown>, U extends string[]>(obj: T, ...keys: U) => Omit<T, U[number]>;
253
-
271
+ //#endregion
272
+ //#region src/utils/removeEndingSlash.d.ts
254
273
  /**
255
274
  * Remove ending slash / from a string
256
275
  */
257
276
  declare const removeEndingSlash: (str: string) => string;
258
-
277
+ //#endregion
278
+ //#region src/utils/removeLeadingSlash.d.ts
259
279
  /**
260
280
  * Remove leading slash / from a string
261
281
  */
262
282
  declare const removeLeadingSlash: (str: string) => string;
263
-
283
+ //#endregion
284
+ //#region src/utils/resolveHeadIdentifier.d.ts
264
285
  /**
265
286
  * Resolve identifier of a tag, to avoid duplicated tags in `<head>`
266
287
  */
267
288
  declare const resolveHeadIdentifier: ([tag, attrs, content]: HeadConfig) => string | null;
268
-
289
+ //#endregion
290
+ //#region src/utils/typeGuards.d.ts
269
291
  /**
270
292
  * Check if a value is a function
271
293
  */
@@ -278,5 +300,5 @@ declare const isPlainObject: <T extends Record<any, any> = Record<any, any>>(val
278
300
  * Check if a value is a string
279
301
  */
280
302
  declare const isString: (val: unknown) => val is string;
281
-
282
- export { type HeadAttrsConfig, type HeadConfig, type HeadTag, type HeadTagEmpty, type HeadTagNonEmpty, type LocaleConfig, type LocaleData, type PageBase, type PageData, type PageFrontmatter, type PageHeader, type SiteData, type SiteLocaleConfig, type SiteLocaleData, type VuepressSSRContext, dedupeHead, ensureEndingSlash, ensureLeadingSlash, formatDateString, inferRoutePath, isFunction, isLinkExternal, isLinkHttp, isLinkWithProtocol, isPlainObject, isString, normalizeRoutePath, omit, removeEndingSlash, removeLeadingSlash, resolveHeadIdentifier, resolveLocalePath, resolveRoutePathFromUrl, splitPath };
303
+ //#endregion
304
+ export { HeadAttrsConfig, HeadConfig, HeadTag, HeadTagEmpty, HeadTagNonEmpty, LocaleConfig, LocaleData, PageBase, PageData, PageFrontmatter, PageHeader, SiteData, SiteLocaleConfig, SiteLocaleData, VuepressSSRContext, dedupeHead, ensureEndingSlash, ensureLeadingSlash, formatDateString, inferRoutePath, isFunction, isLinkExternal, isLinkHttp, isLinkWithProtocol, isPlainObject, isString, normalizeRoutePath, omit, removeEndingSlash, removeLeadingSlash, resolveHeadIdentifier, resolveLocalePath, resolveRoutePathFromUrl, splitPath };
package/dist/index.js CHANGED
@@ -1,167 +1,196 @@
1
- // src/utils/links/isLinkWithProtocol.ts
2
- var isLinkWithProtocol = (link) => /^[a-z][a-z0-9+.-]*:/.test(link) || link.startsWith("//");
3
-
4
- // src/utils/links/isLinkExternal.ts
5
- var markdownLinkRegexp = /.md((\?|#).*)?$/;
6
- var isLinkExternal = (link, base = "/") => isLinkWithProtocol(link) || // absolute link that does not start with `base` and does not end with `.md`
7
- link.startsWith("/") && !link.startsWith(base) && !markdownLinkRegexp.test(link);
8
-
9
- // src/utils/links/isLinkHttp.ts
10
- var isLinkHttp = (link) => /^(https?:)?\/\//.test(link);
11
-
12
- // src/utils/routes/inferRoutePath.ts
13
- var inferRoutePath = (rawPath) => {
14
- if (!rawPath || rawPath.endsWith("/")) return rawPath;
15
- let routePath = rawPath.replace(/(^|\/)README.md$/i, "$1index.html");
16
- if (routePath.endsWith(".md")) {
17
- routePath = `${routePath.substring(0, routePath.length - 3)}.html`;
18
- } else if (!routePath.endsWith(".html")) {
19
- routePath = `${routePath}.html`;
20
- }
21
- if (routePath.endsWith("/index.html")) {
22
- routePath = routePath.substring(0, routePath.length - 10);
23
- }
24
- return routePath;
1
+ //#region src/utils/links/isLinkWithProtocol.ts
2
+ /**
3
+ * Determine a link has protocol or not
4
+ */
5
+ const isLinkWithProtocol = (link) => /^[a-z][a-z0-9+.-]*:/.test(link) || link.startsWith("//");
6
+ //#endregion
7
+ //#region src/utils/links/isLinkExternal.ts
8
+ const markdownLinkRegexp = /.md((\?|#).*)?$/;
9
+ /**
10
+ * Determine a link is external or not
11
+ */
12
+ const isLinkExternal = (link, base = "/") => isLinkWithProtocol(link) || link.startsWith("/") && !link.startsWith(base) && !markdownLinkRegexp.test(link);
13
+ //#endregion
14
+ //#region src/utils/links/isLinkHttp.ts
15
+ /**
16
+ * Determine a link is http link or not
17
+ *
18
+ * - http://github.com
19
+ * - https://github.com
20
+ * - //github.com
21
+ */
22
+ const isLinkHttp = (link) => /^(https?:)?\/\//.test(link);
23
+ //#endregion
24
+ //#region src/utils/routes/inferRoutePath.ts
25
+ /**
26
+ * Infer route path of the given raw path
27
+ */
28
+ const inferRoutePath = (rawPath) => {
29
+ if (!rawPath || rawPath.endsWith("/")) return rawPath;
30
+ let routePath = rawPath.replace(/(^|\/)README.md$/i, "$1index.html");
31
+ if (routePath.endsWith(".md")) routePath = `${routePath.substring(0, routePath.length - 3)}.html`;
32
+ else if (!routePath.endsWith(".html")) routePath = `${routePath}.html`;
33
+ if (routePath.endsWith("/index.html")) routePath = routePath.substring(0, routePath.length - 10);
34
+ return routePath;
25
35
  };
26
-
27
- // src/utils/routes/normalizeRoutePath.ts
28
- var FAKE_HOST = "http://.";
29
- var normalizeRoutePath = (pathname, current) => {
30
- if (!pathname.startsWith("/") && current) {
31
- const loc = current.slice(0, current.lastIndexOf("/"));
32
- return inferRoutePath(new URL(`${loc}/${pathname}`, FAKE_HOST).pathname);
33
- }
34
- return inferRoutePath(pathname);
36
+ //#endregion
37
+ //#region src/utils/routes/normalizeRoutePath.ts
38
+ const FAKE_HOST = "http://.";
39
+ /**
40
+ * Normalize the given pathname path to the final route path
41
+ */
42
+ const normalizeRoutePath = (pathname, current) => {
43
+ if (!pathname.startsWith("/") && current) {
44
+ const loc = current.slice(0, current.lastIndexOf("/"));
45
+ return inferRoutePath(new URL(`${loc}/${pathname}`, FAKE_HOST).pathname);
46
+ }
47
+ return inferRoutePath(pathname);
35
48
  };
36
-
37
- // src/utils/routes/resolveLocalePath.ts
38
- var resolveLocalePath = (locales, routePath) => {
39
- const localePaths = Object.keys(locales).sort((a, b) => {
40
- const levelDelta = b.split("/").length - a.split("/").length;
41
- if (levelDelta !== 0) {
42
- return levelDelta;
43
- }
44
- return b.length - a.length;
45
- });
46
- for (const localePath of localePaths) {
47
- if (routePath.startsWith(localePath)) {
48
- return localePath;
49
- }
50
- }
51
- return "/";
49
+ //#endregion
50
+ //#region src/utils/routes/resolveLocalePath.ts
51
+ /**
52
+ * Resolve the matched locale path of route path
53
+ */
54
+ const resolveLocalePath = (locales, routePath) => {
55
+ const localePaths = Object.keys(locales).sort((a, b) => {
56
+ const levelDelta = b.split("/").length - a.split("/").length;
57
+ if (levelDelta !== 0) return levelDelta;
58
+ return b.length - a.length;
59
+ });
60
+ for (const localePath of localePaths) if (routePath.startsWith(localePath)) return localePath;
61
+ return "/";
52
62
  };
53
-
54
- // src/utils/routes/resolveRoutePathFromUrl.ts
55
- var resolveRoutePathFromUrl = (url, base = "/") => {
56
- const pathname = url.replace(/^(?:https?:)?\/\/[^/]*/, "");
57
- return pathname.startsWith(base) ? `/${pathname.slice(base.length)}` : pathname;
63
+ //#endregion
64
+ //#region src/utils/routes/resolveRoutePathFromUrl.ts
65
+ /**
66
+ * For a give URL, remove the origin and the site base to get the route path
67
+ */
68
+ const resolveRoutePathFromUrl = (url, base = "/") => {
69
+ const pathname = url.replace(/^(?:https?:)?\/\/[^/]*/, "");
70
+ return pathname.startsWith(base) ? `/${pathname.slice(base.length)}` : pathname;
58
71
  };
59
-
60
- // src/utils/routes/splitPath.ts
61
- var SPLIT_CHAR_REGEXP = /(#|\?)/;
62
- var splitPath = (path) => {
63
- const [pathname, ...hashAndQueries] = path.split(SPLIT_CHAR_REGEXP);
64
- return {
65
- pathname,
66
- hashAndQueries: hashAndQueries.join("")
67
- };
72
+ //#endregion
73
+ //#region src/utils/routes/splitPath.ts
74
+ const SPLIT_CHAR_REGEXP = /(#|\?)/;
75
+ /**
76
+ * Split a path into pathname and hashAndQueries
77
+ */
78
+ const splitPath = (path) => {
79
+ const [pathname, ...hashAndQueries] = path.split(SPLIT_CHAR_REGEXP);
80
+ return {
81
+ pathname,
82
+ hashAndQueries: hashAndQueries.join("")
83
+ };
68
84
  };
69
-
70
- // src/utils/resolveHeadIdentifier.ts
71
- var TAGS_ALLOWED = ["link", "meta", "script", "style", "noscript", "template"];
72
- var TAGS_UNIQUE = ["title", "base"];
73
- var resolveHeadIdentifier = ([tag, attrs, content]) => {
74
- if (TAGS_UNIQUE.includes(tag)) {
75
- return tag;
76
- }
77
- if (!TAGS_ALLOWED.includes(tag)) {
78
- return null;
79
- }
80
- if (tag === "meta" && attrs.name) {
81
- return `${tag}.${attrs.name}`;
82
- }
83
- if (tag === "template" && attrs.id) {
84
- return `${tag}.${attrs.id}`;
85
- }
86
- return JSON.stringify([
87
- tag,
88
- Object.entries(attrs).map(([key, value]) => {
89
- if (typeof value === "boolean") {
90
- return value ? [key, ""] : null;
91
- }
92
- return [key, value];
93
- }).filter((item) => item != null).sort(([keyA], [keyB]) => keyA.localeCompare(keyB)),
94
- content
95
- ]);
85
+ //#endregion
86
+ //#region src/utils/resolveHeadIdentifier.ts
87
+ const TAGS_ALLOWED = [
88
+ "link",
89
+ "meta",
90
+ "script",
91
+ "style",
92
+ "noscript",
93
+ "template"
94
+ ];
95
+ const TAGS_UNIQUE = ["title", "base"];
96
+ /**
97
+ * Resolve identifier of a tag, to avoid duplicated tags in `<head>`
98
+ */
99
+ const resolveHeadIdentifier = ([tag, attrs, content]) => {
100
+ if (TAGS_UNIQUE.includes(tag)) return tag;
101
+ if (!TAGS_ALLOWED.includes(tag)) return null;
102
+ if (tag === "meta" && attrs.name) return `${tag}.${attrs.name}`;
103
+ if (tag === "template" && attrs.id) return `${tag}.${attrs.id}`;
104
+ return JSON.stringify([
105
+ tag,
106
+ Object.entries(attrs).map(([key, value]) => {
107
+ if (typeof value === "boolean") return value ? [key, ""] : null;
108
+ return [key, value];
109
+ }).filter((item) => item != null).sort(([keyA], [keyB]) => keyA.localeCompare(keyB)),
110
+ content
111
+ ]);
96
112
  };
97
-
98
- // src/utils/dedupeHead.ts
99
- var dedupeHead = (head) => {
100
- const identifierSet = /* @__PURE__ */ new Set();
101
- const result = [];
102
- head.forEach((item) => {
103
- const identifier = resolveHeadIdentifier(item);
104
- if (identifier && !identifierSet.has(identifier)) {
105
- identifierSet.add(identifier);
106
- result.push(item);
107
- }
108
- });
109
- return result;
113
+ //#endregion
114
+ //#region src/utils/dedupeHead.ts
115
+ /**
116
+ * Dedupe head config with identifier
117
+ *
118
+ * Items that appear earlier have higher priority
119
+ */
120
+ const dedupeHead = (head) => {
121
+ const identifierSet = /* @__PURE__ */ new Set();
122
+ const result = [];
123
+ head.forEach((item) => {
124
+ const identifier = resolveHeadIdentifier(item);
125
+ if (identifier && !identifierSet.has(identifier)) {
126
+ identifierSet.add(identifier);
127
+ result.push(item);
128
+ }
129
+ });
130
+ return result;
110
131
  };
111
-
112
- // src/utils/ensureLeadingSlash.ts
113
- var ensureLeadingSlash = (str) => str.startsWith("/") ? str : `/${str}`;
114
-
115
- // src/utils/ensureEndingSlash.ts
116
- var ensureEndingSlash = (str) => str.endsWith("/") || str.endsWith(".html") ? str : `${str}/`;
117
-
118
- // src/utils/formatDateString.ts
119
- var formatDateString = (str, defaultDateString = "") => {
120
- const dateMatch = str.match(/\b(\d{4})-(\d{1,2})-(\d{1,2})\b/);
121
- if (dateMatch === null) {
122
- return defaultDateString;
123
- }
124
- const [, yearStr, monthStr, dayStr] = dateMatch;
125
- return [yearStr, monthStr.padStart(2, "0"), dayStr.padStart(2, "0")].join("-");
132
+ //#endregion
133
+ //#region src/utils/ensureLeadingSlash.ts
134
+ /**
135
+ * Ensure a url string to have leading slash /
136
+ */
137
+ const ensureLeadingSlash = (str) => str.startsWith("/") ? str : `/${str}`;
138
+ //#endregion
139
+ //#region src/utils/ensureEndingSlash.ts
140
+ /**
141
+ * Ensure a url string to have ending slash /
142
+ */
143
+ const ensureEndingSlash = (str) => str.endsWith("/") || str.endsWith(".html") ? str : `${str}/`;
144
+ //#endregion
145
+ //#region src/utils/formatDateString.ts
146
+ /**
147
+ * Format a date string to `yyyy-MM-dd`
148
+ */
149
+ const formatDateString = (str, defaultDateString = "") => {
150
+ const dateMatch = str.match(/\b(\d{4})-(\d{1,2})-(\d{1,2})\b/);
151
+ if (dateMatch === null) return defaultDateString;
152
+ const [, yearStr, monthStr, dayStr] = dateMatch;
153
+ return [
154
+ yearStr,
155
+ monthStr.padStart(2, "0"),
156
+ dayStr.padStart(2, "0")
157
+ ].join("-");
126
158
  };
127
-
128
- // src/utils/omit.ts
129
- var omit = (obj, ...keys) => {
130
- const result = { ...obj };
131
- for (const key of keys) {
132
- delete result[key];
133
- }
134
- return result;
135
- };
136
-
137
- // src/utils/removeEndingSlash.ts
138
- var removeEndingSlash = (str) => str.endsWith("/") ? str.slice(0, -1) : str;
139
-
140
- // src/utils/removeLeadingSlash.ts
141
- var removeLeadingSlash = (str) => str.startsWith("/") ? str.slice(1) : str;
142
-
143
- // src/utils/typeGuards.ts
144
- var isFunction = (val) => typeof val === "function";
145
- var isPlainObject = (val) => Object.prototype.toString.call(val) === "[object Object]";
146
- var isString = (val) => typeof val === "string";
147
- export {
148
- dedupeHead,
149
- ensureEndingSlash,
150
- ensureLeadingSlash,
151
- formatDateString,
152
- inferRoutePath,
153
- isFunction,
154
- isLinkExternal,
155
- isLinkHttp,
156
- isLinkWithProtocol,
157
- isPlainObject,
158
- isString,
159
- normalizeRoutePath,
160
- omit,
161
- removeEndingSlash,
162
- removeLeadingSlash,
163
- resolveHeadIdentifier,
164
- resolveLocalePath,
165
- resolveRoutePathFromUrl,
166
- splitPath
159
+ //#endregion
160
+ //#region src/utils/omit.ts
161
+ /**
162
+ * Omit properties from an object
163
+ */
164
+ const omit = (obj, ...keys) => {
165
+ const result = { ...obj };
166
+ for (const key of keys) delete result[key];
167
+ return result;
167
168
  };
169
+ //#endregion
170
+ //#region src/utils/removeEndingSlash.ts
171
+ /**
172
+ * Remove ending slash / from a string
173
+ */
174
+ const removeEndingSlash = (str) => str.endsWith("/") ? str.slice(0, -1) : str;
175
+ //#endregion
176
+ //#region src/utils/removeLeadingSlash.ts
177
+ /**
178
+ * Remove leading slash / from a string
179
+ */
180
+ const removeLeadingSlash = (str) => str.startsWith("/") ? str.slice(1) : str;
181
+ //#endregion
182
+ //#region src/utils/typeGuards.ts
183
+ /**
184
+ * Check if a value is a function
185
+ */
186
+ const isFunction = (val) => typeof val === "function";
187
+ /**
188
+ * Check if a value is plain object, with generic type support
189
+ */
190
+ const isPlainObject = (val) => Object.prototype.toString.call(val) === "[object Object]";
191
+ /**
192
+ * Check if a value is a string
193
+ */
194
+ const isString = (val) => typeof val === "string";
195
+ //#endregion
196
+ export { dedupeHead, ensureEndingSlash, ensureLeadingSlash, formatDateString, inferRoutePath, isFunction, isLinkExternal, isLinkHttp, isLinkWithProtocol, isPlainObject, isString, normalizeRoutePath, omit, removeEndingSlash, removeLeadingSlash, resolveHeadIdentifier, resolveLocalePath, resolveRoutePathFromUrl, splitPath };
package/package.json CHANGED
@@ -1,55 +1,49 @@
1
1
  {
2
2
  "name": "@vuepress/shared",
3
- "version": "2.0.0-rc.26",
3
+ "version": "2.0.0-rc.28",
4
4
  "description": "Utils that shared between VuePress node and client",
5
5
  "keywords": [
6
- "vuepress",
7
6
  "shared",
8
- "utils"
7
+ "utils",
8
+ "vuepress"
9
9
  ],
10
10
  "homepage": "https://github.com/vuepress",
11
11
  "bugs": {
12
12
  "url": "https://github.com/vuepress/core/issues"
13
13
  },
14
+ "license": "MIT",
15
+ "author": "meteorlxy",
14
16
  "repository": {
15
17
  "type": "git",
16
18
  "url": "git+https://github.com/vuepress/core.git"
17
19
  },
18
- "license": "MIT",
19
- "author": "meteorlxy",
20
+ "files": [
21
+ "dist"
22
+ ],
20
23
  "type": "module",
21
- "exports": {
22
- ".": "./dist/index.js",
23
- "./package.json": "./package.json"
24
- },
25
24
  "main": "./dist/index.js",
26
25
  "module": "./dist/index.js",
27
26
  "types": "./dist/index.d.ts",
28
- "files": [
29
- "dist"
30
- ],
31
- "dependencies": {
32
- "@mdit-vue/types": "^3.0.2"
27
+ "exports": {
28
+ ".": "./dist/index.js",
29
+ "./package.json": "./package.json"
33
30
  },
34
31
  "publishConfig": {
35
32
  "access": "public"
36
33
  },
37
- "tsup": {
38
- "clean": true,
39
- "dts": "./src/index.ts",
40
- "entry": [
41
- "./src/index.ts"
42
- ],
43
- "format": [
44
- "esm"
45
- ],
46
- "outDir": "./dist",
47
- "sourcemap": false,
34
+ "dependencies": {
35
+ "@mdit-vue/types": "^3.0.2"
36
+ },
37
+ "tsdown": {
38
+ "dts": true,
39
+ "entry": "./src/index.ts",
40
+ "fixedExtension": false,
41
+ "format": "esm",
48
42
  "target": "es2023",
49
43
  "tsconfig": "../../tsconfig.dts.json"
50
44
  },
51
45
  "scripts": {
52
- "build": "tsup",
46
+ "build": "tsdown",
53
47
  "clean": "rimraf dist"
54
48
  }
55
49
  }