@vuepress/shared 2.0.0-beta.38 → 2.0.0-beta.41

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 (108) hide show
  1. package/dist/index.cjs +198 -0
  2. package/dist/index.d.ts +289 -0
  3. package/dist/index.js +152 -0
  4. package/package.json +36 -13
  5. package/lib/esm/index.d.ts +0 -2
  6. package/lib/esm/index.js +0 -2
  7. package/lib/esm/types/head.d.ts +0 -27
  8. package/lib/esm/types/head.js +0 -1
  9. package/lib/esm/types/index.d.ts +0 -5
  10. package/lib/esm/types/index.js +0 -5
  11. package/lib/esm/types/locale.d.ts +0 -13
  12. package/lib/esm/types/locale.js +0 -1
  13. package/lib/esm/types/page.d.ts +0 -75
  14. package/lib/esm/types/page.js +0 -1
  15. package/lib/esm/types/site.d.ts +0 -42
  16. package/lib/esm/types/site.js +0 -1
  17. package/lib/esm/types/ssr.d.ts +0 -8
  18. package/lib/esm/types/ssr.js +0 -1
  19. package/lib/esm/utils/dedupeHead.d.ts +0 -7
  20. package/lib/esm/utils/dedupeHead.js +0 -18
  21. package/lib/esm/utils/ensureEndingSlash.d.ts +0 -4
  22. package/lib/esm/utils/ensureEndingSlash.js +0 -4
  23. package/lib/esm/utils/ensureLeadingSlash.d.ts +0 -4
  24. package/lib/esm/utils/ensureLeadingSlash.js +0 -4
  25. package/lib/esm/utils/formatDateString.d.ts +0 -4
  26. package/lib/esm/utils/formatDateString.js +0 -14
  27. package/lib/esm/utils/htmlEscape.d.ts +0 -4
  28. package/lib/esm/utils/htmlEscape.js +0 -12
  29. package/lib/esm/utils/htmlUnescape.d.ts +0 -4
  30. package/lib/esm/utils/htmlUnescape.js +0 -17
  31. package/lib/esm/utils/index.d.ts +0 -19
  32. package/lib/esm/utils/index.js +0 -19
  33. package/lib/esm/utils/isLinkExternal.d.ts +0 -4
  34. package/lib/esm/utils/isLinkExternal.js +0 -16
  35. package/lib/esm/utils/isLinkFtp.d.ts +0 -4
  36. package/lib/esm/utils/isLinkFtp.js +0 -4
  37. package/lib/esm/utils/isLinkHttp.d.ts +0 -8
  38. package/lib/esm/utils/isLinkHttp.js +0 -8
  39. package/lib/esm/utils/isLinkMailto.d.ts +0 -4
  40. package/lib/esm/utils/isLinkMailto.js +0 -4
  41. package/lib/esm/utils/isLinkTel.d.ts +0 -4
  42. package/lib/esm/utils/isLinkTel.js +0 -4
  43. package/lib/esm/utils/isPlainObject.d.ts +0 -4
  44. package/lib/esm/utils/isPlainObject.js +0 -4
  45. package/lib/esm/utils/normalizePackageName.d.ts +0 -4
  46. package/lib/esm/utils/normalizePackageName.js +0 -37
  47. package/lib/esm/utils/removeEndingSlash.d.ts +0 -4
  48. package/lib/esm/utils/removeEndingSlash.js +0 -4
  49. package/lib/esm/utils/removeLeadingSlash.d.ts +0 -4
  50. package/lib/esm/utils/removeLeadingSlash.js +0 -4
  51. package/lib/esm/utils/resolveHeadIdentifier.d.ts +0 -5
  52. package/lib/esm/utils/resolveHeadIdentifier.js +0 -18
  53. package/lib/esm/utils/resolveLocalePath.d.ts +0 -5
  54. package/lib/esm/utils/resolveLocalePath.js +0 -18
  55. package/lib/esm/utils/resolveRoutePathFromUrl.d.ts +0 -1
  56. package/lib/esm/utils/resolveRoutePathFromUrl.js +0 -5
  57. package/lib/index.d.ts +0 -2
  58. package/lib/index.js +0 -18
  59. package/lib/types/head.d.ts +0 -27
  60. package/lib/types/head.js +0 -2
  61. package/lib/types/index.d.ts +0 -5
  62. package/lib/types/index.js +0 -21
  63. package/lib/types/locale.d.ts +0 -13
  64. package/lib/types/locale.js +0 -2
  65. package/lib/types/page.d.ts +0 -75
  66. package/lib/types/page.js +0 -2
  67. package/lib/types/site.d.ts +0 -42
  68. package/lib/types/site.js +0 -2
  69. package/lib/types/ssr.d.ts +0 -8
  70. package/lib/types/ssr.js +0 -2
  71. package/lib/utils/dedupeHead.d.ts +0 -7
  72. package/lib/utils/dedupeHead.js +0 -22
  73. package/lib/utils/ensureEndingSlash.d.ts +0 -4
  74. package/lib/utils/ensureEndingSlash.js +0 -8
  75. package/lib/utils/ensureLeadingSlash.d.ts +0 -4
  76. package/lib/utils/ensureLeadingSlash.js +0 -8
  77. package/lib/utils/formatDateString.d.ts +0 -4
  78. package/lib/utils/formatDateString.js +0 -18
  79. package/lib/utils/htmlEscape.d.ts +0 -4
  80. package/lib/utils/htmlEscape.js +0 -16
  81. package/lib/utils/htmlUnescape.d.ts +0 -4
  82. package/lib/utils/htmlUnescape.js +0 -21
  83. package/lib/utils/index.d.ts +0 -19
  84. package/lib/utils/index.js +0 -40
  85. package/lib/utils/isLinkExternal.d.ts +0 -4
  86. package/lib/utils/isLinkExternal.js +0 -20
  87. package/lib/utils/isLinkFtp.d.ts +0 -4
  88. package/lib/utils/isLinkFtp.js +0 -8
  89. package/lib/utils/isLinkHttp.d.ts +0 -8
  90. package/lib/utils/isLinkHttp.js +0 -12
  91. package/lib/utils/isLinkMailto.d.ts +0 -4
  92. package/lib/utils/isLinkMailto.js +0 -8
  93. package/lib/utils/isLinkTel.d.ts +0 -4
  94. package/lib/utils/isLinkTel.js +0 -8
  95. package/lib/utils/isPlainObject.d.ts +0 -4
  96. package/lib/utils/isPlainObject.js +0 -8
  97. package/lib/utils/normalizePackageName.d.ts +0 -4
  98. package/lib/utils/normalizePackageName.js +0 -41
  99. package/lib/utils/removeEndingSlash.d.ts +0 -4
  100. package/lib/utils/removeEndingSlash.js +0 -8
  101. package/lib/utils/removeLeadingSlash.d.ts +0 -4
  102. package/lib/utils/removeLeadingSlash.js +0 -8
  103. package/lib/utils/resolveHeadIdentifier.d.ts +0 -5
  104. package/lib/utils/resolveHeadIdentifier.js +0 -22
  105. package/lib/utils/resolveLocalePath.d.ts +0 -5
  106. package/lib/utils/resolveLocalePath.js +0 -22
  107. package/lib/utils/resolveRoutePathFromUrl.d.ts +0 -1
  108. package/lib/utils/resolveRoutePathFromUrl.js +0 -9
package/dist/index.cjs ADDED
@@ -0,0 +1,198 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/index.ts
20
+ var src_exports = {};
21
+ __export(src_exports, {
22
+ dedupeHead: () => dedupeHead,
23
+ ensureEndingSlash: () => ensureEndingSlash,
24
+ ensureLeadingSlash: () => ensureLeadingSlash,
25
+ formatDateString: () => formatDateString,
26
+ htmlEscape: () => htmlEscape,
27
+ htmlUnescape: () => htmlUnescape,
28
+ isArray: () => import_shared.isArray,
29
+ isFunction: () => import_shared.isFunction,
30
+ isLinkExternal: () => isLinkExternal,
31
+ isLinkFtp: () => isLinkFtp,
32
+ isLinkHttp: () => isLinkHttp,
33
+ isLinkMailto: () => isLinkMailto,
34
+ isLinkTel: () => isLinkTel,
35
+ isPlainObject: () => isPlainObject,
36
+ isPromise: () => import_shared.isPromise,
37
+ isString: () => import_shared.isString,
38
+ removeEndingSlash: () => removeEndingSlash,
39
+ removeLeadingSlash: () => removeLeadingSlash,
40
+ resolveHeadIdentifier: () => resolveHeadIdentifier,
41
+ resolveLocalePath: () => resolveLocalePath,
42
+ resolveRoutePathFromUrl: () => resolveRoutePathFromUrl
43
+ });
44
+ module.exports = __toCommonJS(src_exports);
45
+
46
+ // src/utils/index.ts
47
+ var import_shared = require("@vue/shared");
48
+
49
+ // src/utils/resolveHeadIdentifier.ts
50
+ var resolveHeadIdentifier = ([
51
+ tag,
52
+ attrs,
53
+ content
54
+ ]) => {
55
+ if (tag === "meta" && attrs.name) {
56
+ return `${tag}.${attrs.name}`;
57
+ }
58
+ if (["title", "base"].includes(tag)) {
59
+ return tag;
60
+ }
61
+ if (tag === "template" && attrs.id) {
62
+ return `${tag}.${attrs.id}`;
63
+ }
64
+ return JSON.stringify([tag, attrs, content]);
65
+ };
66
+
67
+ // src/utils/dedupeHead.ts
68
+ var dedupeHead = (head) => {
69
+ const identifierSet = /* @__PURE__ */ new Set();
70
+ const result = [];
71
+ head.forEach((item) => {
72
+ const identifier = resolveHeadIdentifier(item);
73
+ if (!identifierSet.has(identifier)) {
74
+ identifierSet.add(identifier);
75
+ result.push(item);
76
+ }
77
+ });
78
+ return result;
79
+ };
80
+
81
+ // src/utils/ensureLeadingSlash.ts
82
+ var ensureLeadingSlash = (str) => str.replace(/^\/?/, "/");
83
+
84
+ // src/utils/ensureEndingSlash.ts
85
+ var ensureEndingSlash = (str) => /(\.html|\/)$/.test(str) ? str : str + "/";
86
+
87
+ // src/utils/formatDateString.ts
88
+ var formatDateString = (str, defaultDateString = "") => {
89
+ const dateMatch = str.match(/\b(\d{4})-(\d{1,2})-(\d{1,2})\b/);
90
+ if (dateMatch === null) {
91
+ return defaultDateString;
92
+ }
93
+ const [, yearStr, monthStr, dayStr] = dateMatch;
94
+ return [yearStr, monthStr.padStart(2, "0"), dayStr.padStart(2, "0")].join("-");
95
+ };
96
+
97
+ // src/utils/htmlEscape.ts
98
+ var htmlEscapeMap = {
99
+ "&": "&",
100
+ "<": "&lt;",
101
+ ">": "&gt;",
102
+ "'": "&#39;",
103
+ '"': "&quot;"
104
+ };
105
+ var htmlEscapeRegexp = /[&<>'"]/g;
106
+ var htmlEscape = (str) => str.replace(htmlEscapeRegexp, (char) => htmlEscapeMap[char]);
107
+
108
+ // src/utils/htmlUnescape.ts
109
+ var htmlUnescapeMap = {
110
+ "&amp;": "&",
111
+ "&#38;": "&",
112
+ "&lt;": "<",
113
+ "&#60;": "<",
114
+ "&gt;": ">",
115
+ "&#62;": ">",
116
+ "&apos;": "'",
117
+ "&#39;": "'",
118
+ "&quot;": '"',
119
+ "&#34;": '"'
120
+ };
121
+ var htmlUnescapeRegexp = /&(amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
122
+ var htmlUnescape = (str) => str.replace(htmlUnescapeRegexp, (char) => htmlUnescapeMap[char]);
123
+
124
+ // src/utils/isLinkFtp.ts
125
+ var isLinkFtp = (link) => link.startsWith("ftp://");
126
+
127
+ // src/utils/isLinkHttp.ts
128
+ var isLinkHttp = (link) => /^(https?:)?\/\//.test(link);
129
+
130
+ // src/utils/isLinkExternal.ts
131
+ var isLinkExternal = (link, base = "/") => {
132
+ if (isLinkHttp(link) || isLinkFtp(link)) {
133
+ return true;
134
+ }
135
+ if (link.startsWith("/") && !link.startsWith(base)) {
136
+ return true;
137
+ }
138
+ return false;
139
+ };
140
+
141
+ // src/utils/isLinkMailto.ts
142
+ var isLinkMailto = (link) => /^mailto:/.test(link);
143
+
144
+ // src/utils/isLinkTel.ts
145
+ var isLinkTel = (link) => /^tel:/.test(link);
146
+
147
+ // src/utils/isPlainObject.ts
148
+ var isPlainObject = (val) => Object.prototype.toString.call(val) === "[object Object]";
149
+
150
+ // src/utils/removeEndingSlash.ts
151
+ var removeEndingSlash = (str) => str.replace(/\/$/, "");
152
+
153
+ // src/utils/removeLeadingSlash.ts
154
+ var removeLeadingSlash = (str) => str.replace(/^\//, "");
155
+
156
+ // src/utils/resolveLocalePath.ts
157
+ var resolveLocalePath = (locales, routePath) => {
158
+ const localePaths = Object.keys(locales).sort((a, b) => {
159
+ const levelDelta = b.split("/").length - a.split("/").length;
160
+ if (levelDelta !== 0) {
161
+ return levelDelta;
162
+ }
163
+ return b.length - a.length;
164
+ });
165
+ for (const localePath of localePaths) {
166
+ if (routePath.startsWith(localePath)) {
167
+ return localePath;
168
+ }
169
+ }
170
+ return "/";
171
+ };
172
+
173
+ // src/utils/resolveRoutePathFromUrl.ts
174
+ var resolveRoutePathFromUrl = (url, base = "/") => url.replace(/^(https?:)?\/\/[^/]*/, "").replace(new RegExp(`^${base}`), "/");
175
+ // Annotate the CommonJS export names for ESM import in node:
176
+ 0 && (module.exports = {
177
+ dedupeHead,
178
+ ensureEndingSlash,
179
+ ensureLeadingSlash,
180
+ formatDateString,
181
+ htmlEscape,
182
+ htmlUnescape,
183
+ isArray,
184
+ isFunction,
185
+ isLinkExternal,
186
+ isLinkFtp,
187
+ isLinkHttp,
188
+ isLinkMailto,
189
+ isLinkTel,
190
+ isPlainObject,
191
+ isPromise,
192
+ isString,
193
+ removeEndingSlash,
194
+ removeLeadingSlash,
195
+ resolveHeadIdentifier,
196
+ resolveLocalePath,
197
+ resolveRoutePathFromUrl
198
+ });
@@ -0,0 +1,289 @@
1
+ export { isArray, isFunction, isPromise, isString } from '@vue/shared';
2
+
3
+ /**
4
+ * Config for `<head>` tags
5
+ */
6
+ declare type HeadConfig = [HeadTagEmpty, HeadAttrsConfig] | [HeadTagNonEmpty, HeadAttrsConfig, string];
7
+ /**
8
+ * Allowed tags in `<head>`
9
+ *
10
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head
11
+ */
12
+ declare type HeadTag = HeadTagNonEmpty | HeadTagEmpty;
13
+ /**
14
+ * Non-empty tags in `<head>`
15
+ */
16
+ declare type HeadTagNonEmpty = 'title' | 'style' | 'script' | 'noscript' | 'template';
17
+ /**
18
+ * Empty tags in `<head>`
19
+ */
20
+ declare type HeadTagEmpty = 'base' | 'link' | 'meta' | 'script';
21
+ /**
22
+ * Attributes to be set for tags in `<head>`
23
+ */
24
+ declare type HeadAttrsConfig = Record<string, string | boolean>;
25
+
26
+ /**
27
+ * Locales config, a key-value object
28
+ *
29
+ * - Key is the locale path (prefix)
30
+ * - Value is the locales data
31
+ *
32
+ * @remark suffix `Config` means this is for user config
33
+ */
34
+ declare type LocaleConfig<T extends LocaleData = LocaleData> = Record<string, Partial<T>>;
35
+ /**
36
+ * Locales data
37
+ */
38
+ declare type LocaleData = Record<string, any>;
39
+
40
+ /**
41
+ * Base type of vuepress page
42
+ */
43
+ declare type PageBase<ExtraPageFrontmatter extends Record<any, any> = Record<string, unknown>> = {
44
+ /**
45
+ * Identifier of the page
46
+ *
47
+ * Will also be used as the component name
48
+ *
49
+ * @example 'v-foobar'
50
+ */
51
+ key: string;
52
+ /**
53
+ * Route path of the page
54
+ *
55
+ * Firstly inferred from the file path
56
+ *
57
+ * Might be overridden by permalink
58
+ *
59
+ * @example '/guide/index.html'
60
+ * @example '/2020/02/02/hello-world.html'
61
+ */
62
+ path: string;
63
+ /**
64
+ * Title of the page
65
+ */
66
+ title: string;
67
+ /**
68
+ * Language of the page
69
+ */
70
+ lang: string;
71
+ /**
72
+ * Front matter of the page
73
+ */
74
+ frontmatter: PageFrontmatter<ExtraPageFrontmatter>;
75
+ /**
76
+ * Excerpt of the page
77
+ */
78
+ excerpt: string;
79
+ /**
80
+ * Headers of the page
81
+ */
82
+ headers: PageHeader[];
83
+ };
84
+ /**
85
+ * Vuepress page data
86
+ */
87
+ declare type PageData<ExtraPageData extends Record<any, any> = Record<never, never>, ExtraPageFrontmatter extends Record<any, any> = Record<string, unknown>> = PageBase<ExtraPageFrontmatter> & ExtraPageData;
88
+ /**
89
+ * Vuepress page frontmatter
90
+ *
91
+ * Notice that frontmatter is parsed from yaml or other languages,
92
+ * so we cannot guarantee the type safety
93
+ */
94
+ declare type PageFrontmatter<T extends Record<any, any> = Record<string, unknown>> = Partial<T> & {
95
+ date?: string | Date;
96
+ description?: string;
97
+ head?: HeadConfig[];
98
+ lang?: string;
99
+ layout?: string;
100
+ permalink?: string;
101
+ permalinkPattern?: string;
102
+ routeMeta?: Record<string, unknown>;
103
+ title?: string;
104
+ };
105
+ /**
106
+ * Vuepress page header
107
+ */
108
+ interface PageHeader {
109
+ level: number;
110
+ title: string;
111
+ slug: string;
112
+ children: PageHeader[];
113
+ }
114
+
115
+ /**
116
+ * Vuepress site data
117
+ */
118
+ interface SiteData extends SiteLocaleData {
119
+ /**
120
+ * The base URL the site will be deployed at
121
+ *
122
+ * It should always start and end with a slash
123
+ *
124
+ * @default '/'
125
+ */
126
+ base: '/' | `/${string}/`;
127
+ /**
128
+ * Specify locales for i18n support
129
+ *
130
+ * It will override the root-level site data in different subpath
131
+ *
132
+ * @example
133
+ * {
134
+ * '/en/': {
135
+ * lang: 'en-US',
136
+ * title: 'Hello',
137
+ * description: 'This will take effect under /en/ subpath',
138
+ * },
139
+ * '/zh/': {
140
+ * lang: 'zh-CN',
141
+ * title: '你好',
142
+ * description: '它将会在 /zh/ 子路径下生效',
143
+ * }
144
+ * }
145
+ */
146
+ locales: SiteLocaleConfig;
147
+ }
148
+ /**
149
+ * Locales data of vuepress site
150
+ *
151
+ * If they are set in the root of site data, they will be used
152
+ * as the default value
153
+ *
154
+ * If they are set in the `locales` of site data, they will be
155
+ * used for specific locale
156
+ */
157
+ interface SiteLocaleData {
158
+ /**
159
+ * Language for the site
160
+ *
161
+ * @default 'en-US'
162
+ */
163
+ lang: string;
164
+ /**
165
+ * Title for the site
166
+ *
167
+ * @default ''
168
+ */
169
+ title: string;
170
+ /**
171
+ * Description for the site
172
+ *
173
+ * @default ''
174
+ */
175
+ description: string;
176
+ /**
177
+ * Head config
178
+ *
179
+ * Descibe the tags to be appended into the `<head>` tag
180
+ *
181
+ * @default []
182
+ *
183
+ * @example ['link', { rel: 'icon', href: '/logo.png' }]
184
+ * @example ['style', { type: 'text/css' }, 'p { color: red; }']
185
+ */
186
+ head: HeadConfig[];
187
+ }
188
+ /**
189
+ * Site locale config
190
+ */
191
+ declare type SiteLocaleConfig = LocaleConfig<SiteLocaleData>;
192
+
193
+ /**
194
+ * Context for SSR
195
+ */
196
+ interface VuepressSSRContext {
197
+ lang: string;
198
+ head: HeadConfig[];
199
+ }
200
+
201
+ /**
202
+ * Dedupe head config with identifier
203
+ *
204
+ * Items that appear earlier have higher priority
205
+ */
206
+ declare const dedupeHead: (head: HeadConfig[]) => HeadConfig[];
207
+
208
+ /**
209
+ * Ensure a url string to have leading slash /
210
+ */
211
+ declare const ensureLeadingSlash: (str: string) => string;
212
+
213
+ /**
214
+ * Ensure a url string to have ending slash /
215
+ */
216
+ declare const ensureEndingSlash: (str: string) => string;
217
+
218
+ /**
219
+ * Format a date string to `yyyy-MM-dd`
220
+ */
221
+ declare const formatDateString: (str: string, defaultDateString?: string) => string;
222
+
223
+ /**
224
+ * Escape html chars
225
+ */
226
+ declare const htmlEscape: (str: string) => string;
227
+
228
+ /**
229
+ * Unescape html chars
230
+ */
231
+ declare const htmlUnescape: (str: string) => string;
232
+
233
+ /**
234
+ * Determine a link is external or not
235
+ */
236
+ declare const isLinkExternal: (link: string, base?: string) => boolean;
237
+
238
+ /**
239
+ * Determine a link is ftp link or not
240
+ */
241
+ declare const isLinkFtp: (link: string) => boolean;
242
+
243
+ /**
244
+ * Determine a link is http link or not
245
+ *
246
+ * - http://github.com
247
+ * - https://github.com
248
+ * - //github.com
249
+ */
250
+ declare const isLinkHttp: (link: string) => boolean;
251
+
252
+ /**
253
+ * Determine a link is a mailto: address or not
254
+ */
255
+ declare const isLinkMailto: (link: string) => boolean;
256
+
257
+ /**
258
+ * Determine a link is a tel: address or not
259
+ */
260
+ declare const isLinkTel: (link: string) => boolean;
261
+
262
+ /**
263
+ * Check if a value is plain object, with generic type support
264
+ */
265
+ declare const isPlainObject: <T extends Record<any, any> = Record<any, any>>(val: unknown) => val is T;
266
+
267
+ /**
268
+ * Remove ending slash / from a string
269
+ */
270
+ declare const removeEndingSlash: (str: string) => string;
271
+
272
+ /**
273
+ * Remove leading slash / from a string
274
+ */
275
+ declare const removeLeadingSlash: (str: string) => string;
276
+
277
+ /**
278
+ * Resolve identifier of a tag, to avoid duplicated tags in `<head>`
279
+ */
280
+ declare const resolveHeadIdentifier: ([tag, attrs, content,]: HeadConfig) => string;
281
+
282
+ /**
283
+ * Resolve the matched locale path of route path
284
+ */
285
+ declare const resolveLocalePath: (locales: LocaleConfig, routePath: string) => string;
286
+
287
+ declare const resolveRoutePathFromUrl: (url: string, base?: string) => string;
288
+
289
+ export { HeadAttrsConfig, HeadConfig, HeadTag, HeadTagEmpty, HeadTagNonEmpty, LocaleConfig, LocaleData, PageBase, PageData, PageFrontmatter, PageHeader, SiteData, SiteLocaleConfig, SiteLocaleData, VuepressSSRContext, dedupeHead, ensureEndingSlash, ensureLeadingSlash, formatDateString, htmlEscape, htmlUnescape, isLinkExternal, isLinkFtp, isLinkHttp, isLinkMailto, isLinkTel, isPlainObject, removeEndingSlash, removeLeadingSlash, resolveHeadIdentifier, resolveLocalePath, resolveRoutePathFromUrl };
package/dist/index.js ADDED
@@ -0,0 +1,152 @@
1
+ // src/utils/index.ts
2
+ import { isArray, isFunction, isPromise, isString } from "@vue/shared";
3
+
4
+ // src/utils/resolveHeadIdentifier.ts
5
+ var resolveHeadIdentifier = ([
6
+ tag,
7
+ attrs,
8
+ content
9
+ ]) => {
10
+ if (tag === "meta" && attrs.name) {
11
+ return `${tag}.${attrs.name}`;
12
+ }
13
+ if (["title", "base"].includes(tag)) {
14
+ return tag;
15
+ }
16
+ if (tag === "template" && attrs.id) {
17
+ return `${tag}.${attrs.id}`;
18
+ }
19
+ return JSON.stringify([tag, attrs, content]);
20
+ };
21
+
22
+ // src/utils/dedupeHead.ts
23
+ var dedupeHead = (head) => {
24
+ const identifierSet = /* @__PURE__ */ new Set();
25
+ const result = [];
26
+ head.forEach((item) => {
27
+ const identifier = resolveHeadIdentifier(item);
28
+ if (!identifierSet.has(identifier)) {
29
+ identifierSet.add(identifier);
30
+ result.push(item);
31
+ }
32
+ });
33
+ return result;
34
+ };
35
+
36
+ // src/utils/ensureLeadingSlash.ts
37
+ var ensureLeadingSlash = (str) => str.replace(/^\/?/, "/");
38
+
39
+ // src/utils/ensureEndingSlash.ts
40
+ var ensureEndingSlash = (str) => /(\.html|\/)$/.test(str) ? str : str + "/";
41
+
42
+ // src/utils/formatDateString.ts
43
+ var formatDateString = (str, defaultDateString = "") => {
44
+ const dateMatch = str.match(/\b(\d{4})-(\d{1,2})-(\d{1,2})\b/);
45
+ if (dateMatch === null) {
46
+ return defaultDateString;
47
+ }
48
+ const [, yearStr, monthStr, dayStr] = dateMatch;
49
+ return [yearStr, monthStr.padStart(2, "0"), dayStr.padStart(2, "0")].join("-");
50
+ };
51
+
52
+ // src/utils/htmlEscape.ts
53
+ var htmlEscapeMap = {
54
+ "&": "&amp;",
55
+ "<": "&lt;",
56
+ ">": "&gt;",
57
+ "'": "&#39;",
58
+ '"': "&quot;"
59
+ };
60
+ var htmlEscapeRegexp = /[&<>'"]/g;
61
+ var htmlEscape = (str) => str.replace(htmlEscapeRegexp, (char) => htmlEscapeMap[char]);
62
+
63
+ // src/utils/htmlUnescape.ts
64
+ var htmlUnescapeMap = {
65
+ "&amp;": "&",
66
+ "&#38;": "&",
67
+ "&lt;": "<",
68
+ "&#60;": "<",
69
+ "&gt;": ">",
70
+ "&#62;": ">",
71
+ "&apos;": "'",
72
+ "&#39;": "'",
73
+ "&quot;": '"',
74
+ "&#34;": '"'
75
+ };
76
+ var htmlUnescapeRegexp = /&(amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
77
+ var htmlUnescape = (str) => str.replace(htmlUnescapeRegexp, (char) => htmlUnescapeMap[char]);
78
+
79
+ // src/utils/isLinkFtp.ts
80
+ var isLinkFtp = (link) => link.startsWith("ftp://");
81
+
82
+ // src/utils/isLinkHttp.ts
83
+ var isLinkHttp = (link) => /^(https?:)?\/\//.test(link);
84
+
85
+ // src/utils/isLinkExternal.ts
86
+ var isLinkExternal = (link, base = "/") => {
87
+ if (isLinkHttp(link) || isLinkFtp(link)) {
88
+ return true;
89
+ }
90
+ if (link.startsWith("/") && !link.startsWith(base)) {
91
+ return true;
92
+ }
93
+ return false;
94
+ };
95
+
96
+ // src/utils/isLinkMailto.ts
97
+ var isLinkMailto = (link) => /^mailto:/.test(link);
98
+
99
+ // src/utils/isLinkTel.ts
100
+ var isLinkTel = (link) => /^tel:/.test(link);
101
+
102
+ // src/utils/isPlainObject.ts
103
+ var isPlainObject = (val) => Object.prototype.toString.call(val) === "[object Object]";
104
+
105
+ // src/utils/removeEndingSlash.ts
106
+ var removeEndingSlash = (str) => str.replace(/\/$/, "");
107
+
108
+ // src/utils/removeLeadingSlash.ts
109
+ var removeLeadingSlash = (str) => str.replace(/^\//, "");
110
+
111
+ // src/utils/resolveLocalePath.ts
112
+ var resolveLocalePath = (locales, routePath) => {
113
+ const localePaths = Object.keys(locales).sort((a, b) => {
114
+ const levelDelta = b.split("/").length - a.split("/").length;
115
+ if (levelDelta !== 0) {
116
+ return levelDelta;
117
+ }
118
+ return b.length - a.length;
119
+ });
120
+ for (const localePath of localePaths) {
121
+ if (routePath.startsWith(localePath)) {
122
+ return localePath;
123
+ }
124
+ }
125
+ return "/";
126
+ };
127
+
128
+ // src/utils/resolveRoutePathFromUrl.ts
129
+ var resolveRoutePathFromUrl = (url, base = "/") => url.replace(/^(https?:)?\/\/[^/]*/, "").replace(new RegExp(`^${base}`), "/");
130
+ export {
131
+ dedupeHead,
132
+ ensureEndingSlash,
133
+ ensureLeadingSlash,
134
+ formatDateString,
135
+ htmlEscape,
136
+ htmlUnescape,
137
+ isArray,
138
+ isFunction,
139
+ isLinkExternal,
140
+ isLinkFtp,
141
+ isLinkHttp,
142
+ isLinkMailto,
143
+ isLinkTel,
144
+ isPlainObject,
145
+ isPromise,
146
+ isString,
147
+ removeEndingSlash,
148
+ removeLeadingSlash,
149
+ resolveHeadIdentifier,
150
+ resolveLocalePath,
151
+ resolveRoutePathFromUrl
152
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/shared",
3
- "version": "2.0.0-beta.38",
3
+ "version": "2.0.0-beta.41",
4
4
  "description": "Utils that shared between VuePress node and client",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -16,22 +16,45 @@
16
16
  "url": "git+https://github.com/vuepress/vuepress-next.git"
17
17
  },
18
18
  "license": "MIT",
19
- "author": "Evan You",
20
- "main": "lib/index.js",
21
- "module": "lib/esm/index.js",
22
- "types": "lib/index.d.ts",
19
+ "author": "meteorlxy",
20
+ "type": "module",
21
+ "exports": {
22
+ ".": {
23
+ "import": "./dist/index.js",
24
+ "require": "./dist/index.cjs"
25
+ },
26
+ "./package.json": "./package.json"
27
+ },
28
+ "main": "./dist/index.cjs",
29
+ "module": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
23
31
  "files": [
24
- "lib"
32
+ "dist"
25
33
  ],
26
- "scripts": {
27
- "build": "tsc -b tsconfig.build.json",
28
- "clean": "rimraf lib *.tsbuildinfo"
29
- },
30
34
  "dependencies": {
31
- "@vue/shared": "^3.2.31"
35
+ "@vue/shared": "^3.2.33"
32
36
  },
33
37
  "publishConfig": {
34
38
  "access": "public"
35
39
  },
36
- "gitHead": "7cb24eab18628a66371a367090f7c9c33b519136"
37
- }
40
+ "tsup": {
41
+ "clean": true,
42
+ "dts": [
43
+ "src/index.ts"
44
+ ],
45
+ "entry": [
46
+ "src/index.ts"
47
+ ],
48
+ "format": [
49
+ "cjs",
50
+ "esm"
51
+ ],
52
+ "outDir": "dist",
53
+ "sourcemap": false,
54
+ "tsconfig": "tsconfig.dts.json"
55
+ },
56
+ "scripts": {
57
+ "build": "tsup",
58
+ "clean": "rimraf dist"
59
+ }
60
+ }
@@ -1,2 +0,0 @@
1
- export * from './types';
2
- export * from './utils';
package/lib/esm/index.js DELETED
@@ -1,2 +0,0 @@
1
- export * from './types';
2
- export * from './utils';