@markuplint/shared 3.5.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017-2019 Yusuke Hirao
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # @markuplint/shared
2
+
3
+ [![npm version](https://badge.fury.io/js/%40markuplint%2Fshared.svg)](https://www.npmjs.com/package/@markuplint/shared)
4
+
5
+ ## Install
6
+
7
+ [`markuplint`](https://www.npmjs.com/package/markuplint) package includes this package.
8
+
9
+ <details>
10
+ <summary>If you are installing purposely, how below:</summary>
11
+
12
+ ```shell
13
+ $ npm install @markuplint/shared
14
+
15
+ $ yarn add @markuplint/shared
16
+ ```
17
+
18
+ </details>
@@ -0,0 +1,61 @@
1
+ import type { Nullable } from './types';
2
+ /**
3
+ * Converts a given value of string, string array, null, or undefined
4
+ * into an array of non-empty strings.
5
+ *
6
+ * If a string is provided, it wraps it into an array. If null or undefined
7
+ * is provided, an empty array is returned.
8
+ *
9
+ * @param value The input value to be converted to a non-empty string array.
10
+ * @returns The resulting array of non-empty strings derived from the input value.
11
+ */
12
+ export declare function toNoEmptyStringArrayFromStringOrArray(value: string | readonly string[] | null | undefined): readonly string[];
13
+ /**
14
+ * Converts a given value of an item or an array of items into
15
+ * an array of non-nullable items.
16
+ *
17
+ * @template T The type of the items in the input value.
18
+ * @param value The input value to be converted to a non-nullable item array.
19
+ * @returns The resulting array of non-nullable items derived from the input value.
20
+ */
21
+ export declare function toNonNullableArrayFromItemOrArray<T>(value: T | readonly T[]): readonly NonNullable<T>[];
22
+ /**
23
+ * A filter function for use with the `Array.filter` method,
24
+ * which determines if the given string item is non-empty.
25
+ *
26
+ * @param item The string item to be checked for non-emptiness.
27
+ * @returns Returns true if the item is a non-empty string, otherwise false.
28
+ */
29
+ export declare function noEmptyFilter(item: string): item is string;
30
+ /**
31
+ * A filter function for use with the Array.filter method,
32
+ * which determines if the given item is non-nullable.
33
+ *
34
+ * @template T The type of the items in the array.
35
+ * @param item The item to be checked for non-nullability.
36
+ * @returns Returns true if the item is non-nullable, otherwise false.
37
+ */
38
+ export declare function nonNullableFilter<T>(item: Nullable<T>): item is T;
39
+ /**
40
+ * Decodes the provided text by replacing HTML entities
41
+ * with their corresponding characters.
42
+ *
43
+ * The decoding process uses the 'html5' (HTML Standard) level.
44
+ *
45
+ * Unknown entities are left as they are.
46
+ *
47
+ * @param text The input text containing HTML entities to be decoded.
48
+ * @returns The decoded text with HTML entities replaced by their corresponding characters.
49
+ */
50
+ export declare function decodeEntities(text: string): string;
51
+ /**
52
+ * Decodes the provided URL string (href) using
53
+ * the `decodeURIComponent` function.
54
+ *
55
+ * If a `URIError` is encountered,
56
+ * the original href is returned. Any other errors are propagated.
57
+ *
58
+ * @param href The URL string to be decoded.
59
+ * @returns The decoded URL string or the original href if a `URIError` occurs.
60
+ */
61
+ export declare function decodeHref(href: string): string;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeHref = exports.decodeEntities = exports.nonNullableFilter = exports.noEmptyFilter = exports.toNonNullableArrayFromItemOrArray = exports.toNoEmptyStringArrayFromStringOrArray = void 0;
4
+ const html_entities_1 = require("html-entities");
5
+ /**
6
+ * Converts a given value of string, string array, null, or undefined
7
+ * into an array of non-empty strings.
8
+ *
9
+ * If a string is provided, it wraps it into an array. If null or undefined
10
+ * is provided, an empty array is returned.
11
+ *
12
+ * @param value The input value to be converted to a non-empty string array.
13
+ * @returns The resulting array of non-empty strings derived from the input value.
14
+ */
15
+ function toNoEmptyStringArrayFromStringOrArray(value) {
16
+ const array = typeof value === 'string' ? [value] : value !== null && value !== void 0 ? value : [];
17
+ return array.filter(noEmptyFilter);
18
+ }
19
+ exports.toNoEmptyStringArrayFromStringOrArray = toNoEmptyStringArrayFromStringOrArray;
20
+ /**
21
+ * Converts a given value of an item or an array of items into
22
+ * an array of non-nullable items.
23
+ *
24
+ * @template T The type of the items in the input value.
25
+ * @param value The input value to be converted to a non-nullable item array.
26
+ * @returns The resulting array of non-nullable items derived from the input value.
27
+ */
28
+ function toNonNullableArrayFromItemOrArray(value) {
29
+ const array = Array.isArray(value) ? value : [value];
30
+ // @ts-ignore
31
+ return array.filter(nonNullableFilter);
32
+ }
33
+ exports.toNonNullableArrayFromItemOrArray = toNonNullableArrayFromItemOrArray;
34
+ /**
35
+ * A filter function for use with the `Array.filter` method,
36
+ * which determines if the given string item is non-empty.
37
+ *
38
+ * @param item The string item to be checked for non-emptiness.
39
+ * @returns Returns true if the item is a non-empty string, otherwise false.
40
+ */
41
+ function noEmptyFilter(item) {
42
+ return item !== '';
43
+ }
44
+ exports.noEmptyFilter = noEmptyFilter;
45
+ /**
46
+ * A filter function for use with the Array.filter method,
47
+ * which determines if the given item is non-nullable.
48
+ *
49
+ * @template T The type of the items in the array.
50
+ * @param item The item to be checked for non-nullability.
51
+ * @returns Returns true if the item is non-nullable, otherwise false.
52
+ */
53
+ function nonNullableFilter(item) {
54
+ return item != null;
55
+ }
56
+ exports.nonNullableFilter = nonNullableFilter;
57
+ /**
58
+ * Decodes the provided text by replacing HTML entities
59
+ * with their corresponding characters.
60
+ *
61
+ * The decoding process uses the 'html5' (HTML Standard) level.
62
+ *
63
+ * Unknown entities are left as they are.
64
+ *
65
+ * @param text The input text containing HTML entities to be decoded.
66
+ * @returns The decoded text with HTML entities replaced by their corresponding characters.
67
+ */
68
+ function decodeEntities(text) {
69
+ return (0, html_entities_1.decode)(text, { level: 'html5' });
70
+ }
71
+ exports.decodeEntities = decodeEntities;
72
+ /**
73
+ * Decodes the provided URL string (href) using
74
+ * the `decodeURIComponent` function.
75
+ *
76
+ * If a `URIError` is encountered,
77
+ * the original href is returned. Any other errors are propagated.
78
+ *
79
+ * @param href The URL string to be decoded.
80
+ * @returns The decoded URL string or the original href if a `URIError` occurs.
81
+ */
82
+ function decodeHref(href) {
83
+ try {
84
+ return decodeURIComponent(href);
85
+ }
86
+ catch (e) {
87
+ if (e instanceof URIError) {
88
+ return href;
89
+ }
90
+ throw e;
91
+ }
92
+ }
93
+ exports.decodeHref = decodeHref;
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './functions';
2
+ export * from './types';
package/lib/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./functions"), exports);
5
+ tslib_1.__exportStar(require("./types"), exports);
package/lib/types.d.ts ADDED
@@ -0,0 +1 @@
1
+ export type Nullable<T> = T | null | undefined;
package/lib/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@markuplint/shared",
3
+ "version": "3.5.0",
4
+ "description": "Shared functions for Markuplint",
5
+ "repository": "git@github.com:markuplint/markuplint.git",
6
+ "author": "Yusuke Hirao <yusukehirao@me.com>",
7
+ "license": "MIT",
8
+ "private": false,
9
+ "main": "lib/index.js",
10
+ "types": "lib/index.d.ts",
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "typedoc": {
15
+ "entryPoint": "./src/index.ts"
16
+ },
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "clean": "tsc --build --clean"
20
+ },
21
+ "dependencies": {
22
+ "html-entities": "^2.3.3"
23
+ },
24
+ "gitHead": "715dd53d3b1064a9bcf616c1533921cad9e3b187"
25
+ }