@markuplint/shared 3.8.0 → 4.0.0-alpha.1
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/lib/functions.d.ts +1 -1
- package/lib/functions.js +9 -18
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -5
- package/lib/types.js +1 -2
- package/package.json +8 -3
- package/test/functions.spec.js +0 -18
package/lib/functions.d.ts
CHANGED
package/lib/functions.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
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");
|
|
1
|
+
import { decode as decodeHtmlEntities } from 'html-entities';
|
|
5
2
|
/**
|
|
6
3
|
* Converts a given value of string, string array, null, or undefined
|
|
7
4
|
* into an array of non-empty strings.
|
|
@@ -12,11 +9,10 @@ const html_entities_1 = require("html-entities");
|
|
|
12
9
|
* @param value The input value to be converted to a non-empty string array.
|
|
13
10
|
* @returns The resulting array of non-empty strings derived from the input value.
|
|
14
11
|
*/
|
|
15
|
-
function toNoEmptyStringArrayFromStringOrArray(value) {
|
|
16
|
-
const array = typeof value === 'string' ? [value] : value
|
|
12
|
+
export function toNoEmptyStringArrayFromStringOrArray(value) {
|
|
13
|
+
const array = typeof value === 'string' ? [value] : value ?? [];
|
|
17
14
|
return array.filter(noEmptyFilter);
|
|
18
15
|
}
|
|
19
|
-
exports.toNoEmptyStringArrayFromStringOrArray = toNoEmptyStringArrayFromStringOrArray;
|
|
20
16
|
/**
|
|
21
17
|
* Converts a given value of an item or an array of items into
|
|
22
18
|
* an array of non-nullable items.
|
|
@@ -25,12 +21,11 @@ exports.toNoEmptyStringArrayFromStringOrArray = toNoEmptyStringArrayFromStringOr
|
|
|
25
21
|
* @param value The input value to be converted to a non-nullable item array.
|
|
26
22
|
* @returns The resulting array of non-nullable items derived from the input value.
|
|
27
23
|
*/
|
|
28
|
-
function toNonNullableArrayFromItemOrArray(value) {
|
|
24
|
+
export function toNonNullableArrayFromItemOrArray(value) {
|
|
29
25
|
const array = Array.isArray(value) ? value : [value];
|
|
30
26
|
// @ts-ignore
|
|
31
27
|
return array.filter(nonNullableFilter);
|
|
32
28
|
}
|
|
33
|
-
exports.toNonNullableArrayFromItemOrArray = toNonNullableArrayFromItemOrArray;
|
|
34
29
|
/**
|
|
35
30
|
* A filter function for use with the `Array.filter` method,
|
|
36
31
|
* which determines if the given string item is non-empty.
|
|
@@ -38,10 +33,9 @@ exports.toNonNullableArrayFromItemOrArray = toNonNullableArrayFromItemOrArray;
|
|
|
38
33
|
* @param item The string item to be checked for non-emptiness.
|
|
39
34
|
* @returns Returns true if the item is a non-empty string, otherwise false.
|
|
40
35
|
*/
|
|
41
|
-
function noEmptyFilter(item) {
|
|
36
|
+
export function noEmptyFilter(item) {
|
|
42
37
|
return item !== '';
|
|
43
38
|
}
|
|
44
|
-
exports.noEmptyFilter = noEmptyFilter;
|
|
45
39
|
/**
|
|
46
40
|
* A filter function for use with the Array.filter method,
|
|
47
41
|
* which determines if the given item is non-nullable.
|
|
@@ -50,10 +44,9 @@ exports.noEmptyFilter = noEmptyFilter;
|
|
|
50
44
|
* @param item The item to be checked for non-nullability.
|
|
51
45
|
* @returns Returns true if the item is non-nullable, otherwise false.
|
|
52
46
|
*/
|
|
53
|
-
function nonNullableFilter(item) {
|
|
47
|
+
export function nonNullableFilter(item) {
|
|
54
48
|
return item != null;
|
|
55
49
|
}
|
|
56
|
-
exports.nonNullableFilter = nonNullableFilter;
|
|
57
50
|
/**
|
|
58
51
|
* Decodes the provided text by replacing HTML entities
|
|
59
52
|
* with their corresponding characters.
|
|
@@ -65,10 +58,9 @@ exports.nonNullableFilter = nonNullableFilter;
|
|
|
65
58
|
* @param text The input text containing HTML entities to be decoded.
|
|
66
59
|
* @returns The decoded text with HTML entities replaced by their corresponding characters.
|
|
67
60
|
*/
|
|
68
|
-
function decodeEntities(text) {
|
|
69
|
-
return (
|
|
61
|
+
export function decodeEntities(text) {
|
|
62
|
+
return decodeHtmlEntities(text, { level: 'html5' });
|
|
70
63
|
}
|
|
71
|
-
exports.decodeEntities = decodeEntities;
|
|
72
64
|
/**
|
|
73
65
|
* Decodes the provided URL string (href) using
|
|
74
66
|
* the `decodeURIComponent` function.
|
|
@@ -79,7 +71,7 @@ exports.decodeEntities = decodeEntities;
|
|
|
79
71
|
* @param href The URL string to be decoded.
|
|
80
72
|
* @returns The decoded URL string or the original href if a `URIError` occurs.
|
|
81
73
|
*/
|
|
82
|
-
function decodeHref(href) {
|
|
74
|
+
export function decodeHref(href) {
|
|
83
75
|
try {
|
|
84
76
|
return decodeURIComponent(href);
|
|
85
77
|
}
|
|
@@ -90,4 +82,3 @@ function decodeHref(href) {
|
|
|
90
82
|
throw e;
|
|
91
83
|
}
|
|
92
84
|
}
|
|
93
|
-
exports.decodeHref = decodeHref;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './functions';
|
|
2
|
-
export * from './types';
|
|
1
|
+
export * from './functions.js';
|
|
2
|
+
export * from './types.js';
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./functions"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
1
|
+
export * from './functions.js';
|
|
2
|
+
export * from './types.js';
|
package/lib/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/shared",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.1",
|
|
4
4
|
"description": "Shared functions for Markuplint",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"private": false,
|
|
9
|
-
"
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./lib/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
10
15
|
"types": "lib/index.d.ts",
|
|
11
16
|
"publishConfig": {
|
|
12
17
|
"access": "public"
|
|
@@ -21,5 +26,5 @@
|
|
|
21
26
|
"dependencies": {
|
|
22
27
|
"html-entities": "^2.4.0"
|
|
23
28
|
},
|
|
24
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "22502ee22a378ae766033d687dbc0443e5ed35dc"
|
|
25
30
|
}
|
package/test/functions.spec.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const { toNoEmptyStringArrayFromStringOrArray, decodeEntities } = require('../lib/functions');
|
|
2
|
-
|
|
3
|
-
test('toArrayFromStringOrArray', () => {
|
|
4
|
-
expect(toNoEmptyStringArrayFromStringOrArray('')).toStrictEqual([]);
|
|
5
|
-
expect(toNoEmptyStringArrayFromStringOrArray('a')).toStrictEqual(['a']);
|
|
6
|
-
expect(toNoEmptyStringArrayFromStringOrArray(['a'])).toStrictEqual(['a']);
|
|
7
|
-
expect(toNoEmptyStringArrayFromStringOrArray(['a', 'b'])).toStrictEqual(['a', 'b']);
|
|
8
|
-
expect(toNoEmptyStringArrayFromStringOrArray(['', ''])).toStrictEqual([]);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test('decodeEntities', () => {
|
|
12
|
-
expect(decodeEntities('•')).toBe('\u2022');
|
|
13
|
-
expect(decodeEntities('•')).toBe('\u2022');
|
|
14
|
-
expect(decodeEntities('•')).toBe('\u2022');
|
|
15
|
-
expect(decodeEntities('‣')).toBe('\u2023');
|
|
16
|
-
expect(decodeEntities('⁃')).toBe('\u2043');
|
|
17
|
-
expect(decodeEntities('⁃')).toBe('\u2043');
|
|
18
|
-
});
|