shelving 1.231.0 → 1.233.0
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/package.json +1 -1
- package/schema/EmailSchema.js +3 -1
- package/schema/URISchema.d.ts +1 -0
- package/schema/URISchema.js +5 -0
- package/schema/URLSchema.d.ts +1 -0
- package/schema/URLSchema.js +5 -0
- package/ui/block/Block.module.css +1 -1
- package/ui/form/Popover.module.css +1 -1
- package/ui/layout/CenteredLayout.js +3 -1
- package/ui/layout/CenteredLayout.tsx +3 -1
- package/ui/layout/Layout.module.css +2 -2
- package/ui/layout/SidebarLayout.js +6 -7
- package/ui/layout/SidebarLayout.tsx +6 -7
- package/ui/router/Navigation.d.ts +1 -8
- package/ui/router/Navigation.js +2 -10
- package/ui/router/Navigation.tsx +3 -14
- package/ui/router/Router.js +1 -1
- package/ui/router/Router.tsx +1 -1
- package/util/string.d.ts +9 -0
- package/util/string.js +13 -0
package/package.json
CHANGED
package/schema/EmailSchema.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sanitizeWord } from "../util/string.js";
|
|
1
2
|
import { NULLABLE } from "./NullableSchema.js";
|
|
2
3
|
import { StringSchema } from "./StringSchema.js";
|
|
3
4
|
const R_MATCH = /^[a-z0-9](?:[a-zA-Z0-9._+-]{0,62}[a-zA-Z0-9])?@(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.){1,3}(?:[a-z]{2,63}|xn--[a-z0-9-]{0,58}[a-z0-9])$/;
|
|
@@ -32,7 +33,8 @@ export class EmailSchema extends StringSchema {
|
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
35
|
sanitize(str) {
|
|
35
|
-
|
|
36
|
+
// Email addresses never contain whitespace, so strip it entirely, then lowercase (RFC says addresses should be case-insensitive).
|
|
37
|
+
return sanitizeWord(str).toLowerCase();
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
/** Valid email, e.g. `test@test.com` */
|
package/schema/URISchema.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare class URISchema extends StringSchema {
|
|
|
14
14
|
readonly schemes: URISchemes;
|
|
15
15
|
constructor({ one, title, schemes, ...options }: URISchemaOptions);
|
|
16
16
|
validate(unsafeValue: unknown): URIString;
|
|
17
|
+
sanitize(str: string): string;
|
|
17
18
|
format(value: string): string;
|
|
18
19
|
}
|
|
19
20
|
/** Valid URI string, e.g. `https://www.google.com` */
|
package/schema/URISchema.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { formatURI } from "../util/format.js";
|
|
2
|
+
import { sanitizeWord } from "../util/string.js";
|
|
2
3
|
import { getURI, HTTP_SCHEMES } from "../util/uri.js";
|
|
3
4
|
import { NULLABLE } from "./NullableSchema.js";
|
|
4
5
|
import { StringSchema } from "./StringSchema.js";
|
|
@@ -31,6 +32,10 @@ export class URISchema extends StringSchema {
|
|
|
31
32
|
throw `Invalid ${this.one} scheme`;
|
|
32
33
|
return uri.href;
|
|
33
34
|
}
|
|
35
|
+
sanitize(str) {
|
|
36
|
+
// URIs never contain whitespace (a real space must be `%20`-encoded), so strip it entirely.
|
|
37
|
+
return sanitizeWord(str);
|
|
38
|
+
}
|
|
34
39
|
format(value) {
|
|
35
40
|
return formatURI(value, this.format);
|
|
36
41
|
}
|
package/schema/URLSchema.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare class URLSchema extends StringSchema {
|
|
|
17
17
|
readonly schemes: URISchemes;
|
|
18
18
|
constructor({ one, title, base, schemes, ...options }: URLSchemaOptions);
|
|
19
19
|
validate(unsafeValue: unknown): URLString;
|
|
20
|
+
sanitize(str: string): string;
|
|
20
21
|
format(value: string): string;
|
|
21
22
|
}
|
|
22
23
|
/** Valid URL string, e.g. `https://www.google.com` */
|
package/schema/URLSchema.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { formatURL } from "../util/format.js";
|
|
2
|
+
import { sanitizeWord } from "../util/string.js";
|
|
2
3
|
import { HTTP_SCHEMES } from "../util/uri.js";
|
|
3
4
|
import { getURL } from "../util/url.js";
|
|
4
5
|
import { NULLABLE } from "./NullableSchema.js";
|
|
@@ -34,6 +35,10 @@ export class URLSchema extends StringSchema {
|
|
|
34
35
|
throw `Invalid ${this.one} scheme`;
|
|
35
36
|
return url.href;
|
|
36
37
|
}
|
|
38
|
+
sanitize(str) {
|
|
39
|
+
// URLs never contain whitespace (a real space must be `%20`-encoded), so strip it entirely.
|
|
40
|
+
return sanitizeWord(str);
|
|
41
|
+
}
|
|
37
42
|
format(value) {
|
|
38
43
|
return formatURL(value, this.base, this.format);
|
|
39
44
|
}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
.scrollable,
|
|
19
19
|
.prose [role="region"][tabindex="0"] {
|
|
20
20
|
overflow-x: auto;
|
|
21
|
-
overscroll-behavior
|
|
21
|
+
overscroll-behavior: contain;
|
|
22
22
|
|
|
23
23
|
&:focus-visible {
|
|
24
24
|
outline: var(--focus-stroke, var(--stroke-thick)) solid var(--focus-color, var(--color-focus));
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
z-index: 1000;
|
|
21
21
|
max-height: var(--popover-max-height, 30vh);
|
|
22
22
|
overflow-y: auto;
|
|
23
|
-
overscroll-behavior:
|
|
23
|
+
overscroll-behavior: contain;
|
|
24
24
|
border-radius: var(--popover-radius, var(--radius-xsmall));
|
|
25
25
|
border: var(--popover-border, var(--stroke-normal)) solid var(--popover-color-border, var(--color-vivid));
|
|
26
26
|
padding: var(--popover-padding, var(--space-small));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { requireMetaURL } from "../misc/MetaContext.js";
|
|
2
3
|
import { getClass } from "../util/css.js";
|
|
3
4
|
import CENTERED_LAYOUT_CSS from "./CenteredLayout.module.css";
|
|
4
5
|
import { LAYOUT_CLASS } from "./Layout.js";
|
|
@@ -7,5 +8,6 @@ import { LAYOUT_CLASS } from "./Layout.js";
|
|
|
7
8
|
* - Used for e.g. login/register/error/form pages where the content is the only focus.
|
|
8
9
|
*/
|
|
9
10
|
export function CenteredLayout({ children, fullWidth = false }) {
|
|
10
|
-
|
|
11
|
+
const { path } = requireMetaURL();
|
|
12
|
+
return (_jsx("main", { className: getClass(CENTERED_LAYOUT_CSS.main, LAYOUT_CLASS), children: _jsx("div", { className: CENTERED_LAYOUT_CSS.mainInner, style: fullWidth ? { maxWidth: "none" } : undefined, children: children }) }, path));
|
|
11
13
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReactElement } from "react";
|
|
2
|
+
import { requireMetaURL } from "../misc/MetaContext.js";
|
|
2
3
|
import { getClass } from "../util/css.js";
|
|
3
4
|
import type { OptionalChildProps } from "../util/props.js";
|
|
4
5
|
import CENTERED_LAYOUT_CSS from "./CenteredLayout.module.css";
|
|
@@ -13,8 +14,9 @@ export interface CenteredLayoutProps extends OptionalChildProps {
|
|
|
13
14
|
* - Used for e.g. login/register/error/form pages where the content is the only focus.
|
|
14
15
|
*/
|
|
15
16
|
export function CenteredLayout({ children, fullWidth = false }: CenteredLayoutProps): ReactElement {
|
|
17
|
+
const { path } = requireMetaURL();
|
|
16
18
|
return (
|
|
17
|
-
<main className={getClass(CENTERED_LAYOUT_CSS.main, LAYOUT_CLASS)}>
|
|
19
|
+
<main key={path} className={getClass(CENTERED_LAYOUT_CSS.main, LAYOUT_CLASS)}>
|
|
18
20
|
<div className={CENTERED_LAYOUT_CSS.mainInner} style={fullWidth ? { maxWidth: "none" } : undefined}>
|
|
19
21
|
{children}
|
|
20
22
|
</div>
|
|
@@ -40,7 +40,6 @@
|
|
|
40
40
|
width: 100dvw;
|
|
41
41
|
overflow: hidden;
|
|
42
42
|
overflow-wrap: break-word; /* Break overlong words only as a last resort; `anywhere` would also break mid-word to fit narrow table/flex columns. */
|
|
43
|
-
overscroll-behavior: none;
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
body:has(.layout) {
|
|
@@ -61,6 +60,7 @@
|
|
|
61
60
|
/* Own the page's vertical scroll. */
|
|
62
61
|
overflow: hidden auto;
|
|
63
62
|
scroll-behavior: smooth;
|
|
64
|
-
|
|
63
|
+
/* `contain` keeps the elastic bounce on the layout itself but stops the scroll chain leaking up to the locked body. */
|
|
64
|
+
overscroll-behavior: contain;
|
|
65
65
|
}
|
|
66
66
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Bars3Icon, XMarkIcon } from "@heroicons/react/24/solid";
|
|
3
|
-
import {
|
|
4
|
-
import { useStore } from "../../react/useStore.js";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
5
4
|
import { Button } from "../form/Button.js";
|
|
6
|
-
import {
|
|
5
|
+
import { requireMetaURL } from "../misc/MetaContext.js";
|
|
7
6
|
import { getClass } from "../util/css.js";
|
|
8
7
|
import { LAYOUT_CLASS } from "./Layout.js";
|
|
9
8
|
import SIDEBAR_LAYOUT_CSS from "./SidebarLayout.module.css";
|
|
@@ -16,15 +15,15 @@ import SIDEBAR_LAYOUT_CSS from "./SidebarLayout.module.css";
|
|
|
16
15
|
* - Use the `--sidebar-layout-width`, `--sidebar-layout-bg`, `--sidebar-layout-border`, and `--sidebar-layout-color-border` custom properties to override defaults.
|
|
17
16
|
*/
|
|
18
17
|
export function SidebarLayout({ sidebar, children, right = false }) {
|
|
18
|
+
const { path } = requireMetaURL();
|
|
19
19
|
const [open, setOpen] = useState(false);
|
|
20
20
|
// Close the drawer whenever navigation changes the URL — covers tapping a link inside the sidebar.
|
|
21
|
-
const href = useStore(use(NavigationContext))?.href;
|
|
22
21
|
useEffect(() => {
|
|
23
|
-
if (
|
|
22
|
+
if (path)
|
|
24
23
|
setOpen(false);
|
|
25
|
-
}, [
|
|
24
|
+
}, [path]);
|
|
26
25
|
const sidebarEl = (_jsx("nav", { className: getClass(SIDEBAR_LAYOUT_CSS.sidebar, open && SIDEBAR_LAYOUT_CSS.open), children: sidebar }, "sidebar"));
|
|
27
|
-
const contentEl = (_jsxs("div", { className: getClass(LAYOUT_CLASS, SIDEBAR_LAYOUT_CSS.content), children: [_jsx("div", { className: SIDEBAR_LAYOUT_CSS.toggle, children: _jsx(Button, { fit: true, title: open ? "Close menu" : "Show menu", onClick: () => setOpen(o => !o), children: open ? _jsx(XMarkIcon, {}) : _jsx(Bars3Icon, {}) }) }), _jsx("div", { className: SIDEBAR_LAYOUT_CSS.contentInner, children: children })] },
|
|
26
|
+
const contentEl = (_jsxs("div", { className: getClass(LAYOUT_CLASS, SIDEBAR_LAYOUT_CSS.content), children: [_jsx("div", { className: SIDEBAR_LAYOUT_CSS.toggle, children: _jsx(Button, { fit: true, title: open ? "Close menu" : "Show menu", onClick: () => setOpen(o => !o), children: open ? _jsx(XMarkIcon, {}) : _jsx(Bars3Icon, {}) }) }), _jsx("div", { className: SIDEBAR_LAYOUT_CSS.contentInner, children: children })] }, path));
|
|
28
27
|
const overlayEl = open && (_jsx("button", { type: "button", className: SIDEBAR_LAYOUT_CSS.overlay, "aria-label": "Close menu", onClick: () => setOpen(false) }, "overlay"));
|
|
29
28
|
return (_jsx("main", { className: getClass(SIDEBAR_LAYOUT_CSS.main, LAYOUT_CLASS), children: right ? [contentEl, sidebarEl, overlayEl] : [sidebarEl, contentEl, overlayEl] }));
|
|
30
29
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Bars3Icon, XMarkIcon } from "@heroicons/react/24/solid";
|
|
2
|
-
import { type ReactElement, type ReactNode,
|
|
3
|
-
import { useStore } from "../../react/useStore.js";
|
|
2
|
+
import { type ReactElement, type ReactNode, useEffect, useState } from "react";
|
|
4
3
|
import { Button } from "../form/Button.js";
|
|
5
|
-
import {
|
|
4
|
+
import { requireMetaURL } from "../misc/MetaContext.js";
|
|
6
5
|
import { getClass } from "../util/css.js";
|
|
7
6
|
import type { OptionalChildProps } from "../util/props.js";
|
|
8
7
|
import { LAYOUT_CLASS } from "./Layout.js";
|
|
@@ -24,13 +23,13 @@ export interface SidebarLayoutProps extends OptionalChildProps {
|
|
|
24
23
|
* - Use the `--sidebar-layout-width`, `--sidebar-layout-bg`, `--sidebar-layout-border`, and `--sidebar-layout-color-border` custom properties to override defaults.
|
|
25
24
|
*/
|
|
26
25
|
export function SidebarLayout({ sidebar, children, right = false }: SidebarLayoutProps): ReactElement {
|
|
26
|
+
const { path } = requireMetaURL();
|
|
27
27
|
const [open, setOpen] = useState(false);
|
|
28
28
|
|
|
29
29
|
// Close the drawer whenever navigation changes the URL — covers tapping a link inside the sidebar.
|
|
30
|
-
const href = useStore(use(NavigationContext))?.href;
|
|
31
30
|
useEffect(() => {
|
|
32
|
-
if (
|
|
33
|
-
}, [
|
|
31
|
+
if (path) setOpen(false);
|
|
32
|
+
}, [path]);
|
|
34
33
|
|
|
35
34
|
const sidebarEl = (
|
|
36
35
|
<nav key="sidebar" className={getClass(SIDEBAR_LAYOUT_CSS.sidebar, open && SIDEBAR_LAYOUT_CSS.open)}>
|
|
@@ -38,7 +37,7 @@ export function SidebarLayout({ sidebar, children, right = false }: SidebarLayou
|
|
|
38
37
|
</nav>
|
|
39
38
|
);
|
|
40
39
|
const contentEl = (
|
|
41
|
-
<div key=
|
|
40
|
+
<div key={path} className={getClass(LAYOUT_CLASS, SIDEBAR_LAYOUT_CSS.content)}>
|
|
42
41
|
<div className={SIDEBAR_LAYOUT_CSS.toggle}>
|
|
43
42
|
<Button fit title={open ? "Close menu" : "Show menu"} onClick={() => setOpen(o => !o)}>
|
|
44
43
|
{open ? <XMarkIcon /> : <Bars3Icon />}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ReactElement } from "react";
|
|
2
2
|
import type { PossibleMeta } from "../util/index.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { OptionalChildProps } from "../util/props.js";
|
|
4
4
|
export interface NavigationProps extends PossibleMeta, OptionalChildProps {
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
@@ -15,10 +15,3 @@ export interface NavigationProps extends PossibleMeta, OptionalChildProps {
|
|
|
15
15
|
* TODO: switch click/popstate handling to the browser Navigation API when broadly supported.
|
|
16
16
|
*/
|
|
17
17
|
export declare function Navigation({ children, ...meta }: NavigationProps): ReactElement;
|
|
18
|
-
export interface NavigationIsolateProps extends ChildProps {
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Force a full remount of children whenever the navigation URL changes.
|
|
22
|
-
* - Use to reset stateful sub-trees on navigation.
|
|
23
|
-
*/
|
|
24
|
-
export declare function NavigationIsolate({ children }: NavigationIsolateProps): ReactElement;
|
package/ui/router/Navigation.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useEffect } from "react";
|
|
3
3
|
import { useInstance } from "../../react/useInstance.js";
|
|
4
4
|
import { useStore } from "../../react/useStore.js";
|
|
5
5
|
import { MetaContext, requireMeta } from "../misc/MetaContext.js";
|
|
6
|
-
import { NavigationContext
|
|
6
|
+
import { NavigationContext } from "./NavigationContext.js";
|
|
7
7
|
import { NavigationStore } from "./NavigationStore.js";
|
|
8
8
|
/**
|
|
9
9
|
* Top-level navigation provider.
|
|
@@ -46,11 +46,3 @@ export function Navigation({ children, ...meta }) {
|
|
|
46
46
|
}, [nav]);
|
|
47
47
|
return (_jsx(NavigationContext, { value: nav, children: _jsx(MetaContext, { value: { url: nav.value, root, ...merged }, children: children }) }));
|
|
48
48
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Force a full remount of children whenever the navigation URL changes.
|
|
51
|
-
* - Use to reset stateful sub-trees on navigation.
|
|
52
|
-
*/
|
|
53
|
-
export function NavigationIsolate({ children }) {
|
|
54
|
-
const nav = useStore(requireNavigation());
|
|
55
|
-
return _jsx(Fragment, { children: children }, nav.href);
|
|
56
|
-
}
|
package/ui/router/Navigation.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ReactElement, useEffect } from "react";
|
|
2
2
|
import { useInstance } from "../../react/useInstance.js";
|
|
3
3
|
import { useStore } from "../../react/useStore.js";
|
|
4
4
|
import { MetaContext, requireMeta } from "../misc/MetaContext.js";
|
|
5
5
|
import type { PossibleMeta } from "../util/index.js";
|
|
6
|
-
import type {
|
|
7
|
-
import { NavigationContext
|
|
6
|
+
import type { OptionalChildProps } from "../util/props.js";
|
|
7
|
+
import { NavigationContext } from "./NavigationContext.js";
|
|
8
8
|
import { NavigationStore } from "./NavigationStore.js";
|
|
9
9
|
|
|
10
10
|
export interface NavigationProps extends PossibleMeta, OptionalChildProps {}
|
|
@@ -59,14 +59,3 @@ export function Navigation({ children, ...meta }: NavigationProps): ReactElement
|
|
|
59
59
|
</NavigationContext>
|
|
60
60
|
);
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
export interface NavigationIsolateProps extends ChildProps {}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Force a full remount of children whenever the navigation URL changes.
|
|
67
|
-
* - Use to reset stateful sub-trees on navigation.
|
|
68
|
-
*/
|
|
69
|
-
export function NavigationIsolate({ children }: NavigationIsolateProps): ReactElement {
|
|
70
|
-
const nav = useStore(requireNavigation());
|
|
71
|
-
return <Fragment key={nav.href}>{children}</Fragment>;
|
|
72
|
-
}
|
package/ui/router/Router.js
CHANGED
|
@@ -41,7 +41,7 @@ function _matchRoute(routes, fallback, meta, path = meta.path, depth = 0) {
|
|
|
41
41
|
if (typeof Route !== "function")
|
|
42
42
|
return Route;
|
|
43
43
|
// Component — render with merged URL query params and route placeholders as props (placeholders win on conflict).
|
|
44
|
-
_jsx(Route, { ...meta.params, ...placeholders }, path);
|
|
44
|
+
return _jsx(Route, { ...meta.params, ...placeholders }, path);
|
|
45
45
|
}
|
|
46
46
|
// No match, try the fallback.
|
|
47
47
|
if (fallback !== undefined)
|
package/ui/router/Router.tsx
CHANGED
|
@@ -61,7 +61,7 @@ function _matchRoute(
|
|
|
61
61
|
if (typeof Route !== "function") return Route;
|
|
62
62
|
|
|
63
63
|
// Component — render with merged URL query params and route placeholders as props (placeholders win on conflict).
|
|
64
|
-
<Route key={path} {...meta.params} {...placeholders} />;
|
|
64
|
+
return <Route key={path} {...meta.params} {...placeholders} />;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
// No match, try the fallback.
|
package/util/string.d.ts
CHANGED
|
@@ -42,6 +42,15 @@ export declare function joinStrings(strs: Iterable<string> & NotString, joiner?:
|
|
|
42
42
|
* @example santizeString("\x00Nice! "); // Returns `"Nice!"`
|
|
43
43
|
*/
|
|
44
44
|
export declare function sanitizeText(str: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Sanitize a single word of text.
|
|
47
|
+
* - Used when you're sanitising a value that can never contain whitespace, e.g. an email address or token.
|
|
48
|
+
* - Remove all control characters (like `sanitizeText()`).
|
|
49
|
+
* - Strip all whitespace entirely (rather than collapsing runs to a single space like `sanitizeText()`).
|
|
50
|
+
*
|
|
51
|
+
* @example sanitizeWord("\x00 a b c "); // Returns `"abc"`
|
|
52
|
+
*/
|
|
53
|
+
export declare function sanitizeWord(str: string): string;
|
|
45
54
|
/**
|
|
46
55
|
* Sanitize multiple lines of text.
|
|
47
56
|
* - Used when you're sanitising a multi-line input, e.g. a description for something.
|
package/util/string.js
CHANGED
|
@@ -69,6 +69,19 @@ export function sanitizeText(str) {
|
|
|
69
69
|
.replace(/\s+/gu, " ") // Normalise runs of whitespace to one ` ` space.
|
|
70
70
|
.trim(); // Trim whitespace from the start and end of the string.
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Sanitize a single word of text.
|
|
74
|
+
* - Used when you're sanitising a value that can never contain whitespace, e.g. an email address or token.
|
|
75
|
+
* - Remove all control characters (like `sanitizeText()`).
|
|
76
|
+
* - Strip all whitespace entirely (rather than collapsing runs to a single space like `sanitizeText()`).
|
|
77
|
+
*
|
|
78
|
+
* @example sanitizeWord("\x00 a b c "); // Returns `"abc"`
|
|
79
|
+
*/
|
|
80
|
+
export function sanitizeWord(str) {
|
|
81
|
+
return str
|
|
82
|
+
.replace(/[^\P{C}\s]/gu, "") // Strip control characters (except whitespace).
|
|
83
|
+
.replace(/\s+/gu, ""); // Strip all whitespace entirely.
|
|
84
|
+
}
|
|
72
85
|
/**
|
|
73
86
|
* Sanitize multiple lines of text.
|
|
74
87
|
* - Used when you're sanitising a multi-line input, e.g. a description for something.
|