radiant-docs-validator 0.1.12 → 0.1.14
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.
- package/dist/index.d.ts +5 -1
- package/dist/index.js +25 -13
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -215,4 +215,8 @@ type IconValidationContext = {
|
|
|
215
215
|
declare function validateRadiantComponentProps(componentName: string, props: Record<string, unknown>, options: RadiantComponentValidationOptions): void;
|
|
216
216
|
declare function validateRadiantComponentNode(node: MdxJsxElementNode, options: RadiantComponentValidationOptions): void;
|
|
217
217
|
|
|
218
|
-
|
|
218
|
+
declare const HEX_COLOR_PATTERN: RegExp;
|
|
219
|
+
declare function normalizeHexColorValue(value: string): string | null;
|
|
220
|
+
declare function isValidHexColor(value: unknown): value is string;
|
|
221
|
+
|
|
222
|
+
export { type AssistantButtonConfig, type AssistantButtonSize, type AssistantConfig, type AssistantIcon, type AssistantNavbarButtonConfig, BASE_COLOR_OPTIONS, type BaseColorByMode, type BaseColorOption, type CardButtonTheme, type CardCoverTheme, type CardTheme, type CodeSyntaxThemeConfig, type CodeTheme, DEFAULT_THEME_COLOR_DARK, DEFAULT_THEME_COLOR_LIGHT, type DocsConfig, type DocsHrefResolution, type DocsTheme, type DocsValidatorOptions, type Footer, type FooterLink, HEX_COLOR_PATTERN, type HiddenPageRoute, type IconValidationContext, type Logo, type LogoVariant, type NavGroup, type NavMenu, type NavMenuItem, type NavOpenApi, type NavOpenApiPage, type NavOpenApiPageRef, type NavPage, type NavTag, type NavbarItem, type NavigationItem, PUBLISHABLE_STATIC_ASSET_EXTENSIONS, type RadiantComponentValidationOptions, type SocialPlatform, type TagTheme, type ThemeColorByMode, configureDocsValidator, getConfig, isPublishableStaticAssetPath, isValidHexColor, loadOpenApiSpec, normalizeHexColorValue, resolveDocsHref, resolveDocsPageHref, validateMdxContent, validateRadiantComponentNode, validateRadiantComponentProps };
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,18 @@ import { oas } from "@stoplight/spectral-rulesets";
|
|
|
17
17
|
import { compile } from "@mdx-js/mdx";
|
|
18
18
|
import yaml from "yaml";
|
|
19
19
|
|
|
20
|
+
// src/color-validation.ts
|
|
21
|
+
var HEX_COLOR_PATTERN = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
22
|
+
function normalizeHexColorValue(value) {
|
|
23
|
+
const trimmedValue = value.trim();
|
|
24
|
+
if (trimmedValue.length === 0) return null;
|
|
25
|
+
const normalizedValue = trimmedValue.startsWith("#") ? trimmedValue : `#${trimmedValue}`;
|
|
26
|
+
return HEX_COLOR_PATTERN.test(normalizedValue) ? normalizedValue.toLowerCase() : null;
|
|
27
|
+
}
|
|
28
|
+
function isValidHexColor(value) {
|
|
29
|
+
return typeof value === "string" && normalizeHexColorValue(value) !== null;
|
|
30
|
+
}
|
|
31
|
+
|
|
20
32
|
// src/component-validation.ts
|
|
21
33
|
import { compileSync } from "@mdx-js/mdx";
|
|
22
34
|
function componentError(componentName, message, sourceFile) {
|
|
@@ -230,8 +242,7 @@ function assertHexColor(componentName, propName, value, sourceFile) {
|
|
|
230
242
|
sourceFile
|
|
231
243
|
);
|
|
232
244
|
}
|
|
233
|
-
|
|
234
|
-
if (!/^#(?:[A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.test(normalized)) {
|
|
245
|
+
if (normalizeHexColorValue(value) === null) {
|
|
235
246
|
componentError(
|
|
236
247
|
componentName,
|
|
237
248
|
`Invalid prop "${propName}": expected a hex color like "#3b82f6"`,
|
|
@@ -813,20 +824,18 @@ function normalizeHexColor(value, currentPath, label) {
|
|
|
813
824
|
if (typeof value !== "string") {
|
|
814
825
|
throwConfigError(`${label} must be a string.`, currentPath);
|
|
815
826
|
}
|
|
816
|
-
const
|
|
817
|
-
|
|
827
|
+
const stringValue = value;
|
|
828
|
+
const normalizedValue = normalizeHexColorValue(stringValue);
|
|
829
|
+
if (normalizedValue === null && stringValue.trim().length === 0) {
|
|
818
830
|
throwConfigError(`${label} cannot be empty.`, currentPath);
|
|
819
831
|
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
normalizedValue
|
|
823
|
-
)) {
|
|
824
|
-
throwConfigError(
|
|
825
|
-
`${label} must be a valid hex color (for example: #1d4ed8).`,
|
|
826
|
-
currentPath
|
|
827
|
-
);
|
|
832
|
+
if (normalizedValue !== null) {
|
|
833
|
+
return normalizedValue;
|
|
828
834
|
}
|
|
829
|
-
return
|
|
835
|
+
return throwConfigError(
|
|
836
|
+
`${label} must be a valid hex color (for example: #1d4ed8).`,
|
|
837
|
+
currentPath
|
|
838
|
+
);
|
|
830
839
|
}
|
|
831
840
|
function normalizeThemeColorConfig(value, currentPath, label) {
|
|
832
841
|
if (typeof value === "string") {
|
|
@@ -3049,6 +3058,7 @@ export {
|
|
|
3049
3058
|
DEFAULT_SHIKI_LIGHT_THEME,
|
|
3050
3059
|
DEFAULT_THEME_COLOR_DARK,
|
|
3051
3060
|
DEFAULT_THEME_COLOR_LIGHT,
|
|
3061
|
+
HEX_COLOR_PATTERN,
|
|
3052
3062
|
PUBLISHABLE_STATIC_ASSET_EXTENSIONS,
|
|
3053
3063
|
SHIKI_BUNDLED_THEME_NAMES,
|
|
3054
3064
|
configureDocsValidator,
|
|
@@ -3056,7 +3066,9 @@ export {
|
|
|
3056
3066
|
getConfig,
|
|
3057
3067
|
isBundledShikiThemeName,
|
|
3058
3068
|
isPublishableStaticAssetPath,
|
|
3069
|
+
isValidHexColor,
|
|
3059
3070
|
loadOpenApiSpec,
|
|
3071
|
+
normalizeHexColorValue,
|
|
3060
3072
|
resolveDocsHref,
|
|
3061
3073
|
resolveDocsPageHref,
|
|
3062
3074
|
validateMdxContent,
|