@zwa73/utils 1.0.275 → 1.0.277
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { MPromise } from '@zwa73/js-utils';
|
|
1
2
|
import type { stringify } from 'yaml';
|
|
2
3
|
type ExtractBlockOpt = {
|
|
3
4
|
/**要提取的标题 必须为 "# 标题" 的格式 */
|
|
@@ -10,16 +11,25 @@ type FromArg = {
|
|
|
10
11
|
content?: string;
|
|
11
12
|
};
|
|
12
13
|
/**Markdown解析器 */
|
|
13
|
-
export declare class Markdown {
|
|
14
|
-
|
|
14
|
+
export declare class Markdown<D extends Record<string, any> = Record<string, any>> {
|
|
15
|
+
/**yaml数据 */
|
|
16
|
+
data?: D | undefined;
|
|
17
|
+
/**md文本内容 */
|
|
15
18
|
content?: string | undefined;
|
|
16
19
|
private constructor();
|
|
17
20
|
/**从内容文本构建Md */
|
|
18
|
-
static parse(ctx?: string): Promise<Markdown
|
|
21
|
+
static parse(ctx?: string): Promise<Markdown<Record<string, any>>>;
|
|
19
22
|
/**从文件构建Md */
|
|
20
|
-
static fromFile(filepath: string): Promise<Markdown
|
|
23
|
+
static fromFile(filepath: string): Promise<Markdown<Record<string, any>>>;
|
|
21
24
|
/**从数据构建 */
|
|
22
|
-
static from(arg?: FromArg): Markdown
|
|
25
|
+
static from(arg?: FromArg): Markdown<Record<string, any>>;
|
|
26
|
+
/**辅助构建文本 */
|
|
27
|
+
static buildContent(obj: Record<string, (() => MPromise<string | undefined>) | string | undefined>): Promise<string>;
|
|
28
|
+
/**辅助构建代码块
|
|
29
|
+
* @param content - 代码内容
|
|
30
|
+
* @param lang - 代码块语言类型
|
|
31
|
+
*/
|
|
32
|
+
static buildCodeBlock(content: string, lang?: string): Promise<string>;
|
|
23
33
|
/**输出md文本 */
|
|
24
34
|
stringify(opt: Exclude<Parameters<typeof stringify>[2], string | number>): Promise<string>;
|
|
25
35
|
/**根据标题提取块
|
|
@@ -24,7 +24,11 @@ const getYaml = async () => {
|
|
|
24
24
|
class Markdown {
|
|
25
25
|
data;
|
|
26
26
|
content;
|
|
27
|
-
constructor(
|
|
27
|
+
constructor(
|
|
28
|
+
/**yaml数据 */
|
|
29
|
+
data,
|
|
30
|
+
/**md文本内容 */
|
|
31
|
+
content) {
|
|
28
32
|
this.data = data;
|
|
29
33
|
this.content = content;
|
|
30
34
|
}
|
|
@@ -42,9 +46,34 @@ class Markdown {
|
|
|
42
46
|
static from(arg = {}) {
|
|
43
47
|
return new Markdown(arg.data, arg.content);
|
|
44
48
|
}
|
|
49
|
+
/**辅助构建文本 */
|
|
50
|
+
static async buildContent(obj) {
|
|
51
|
+
return Promise.all(Object.entries(obj).map(async ([k, v]) => {
|
|
52
|
+
const vtxt = typeof v == 'function' ? await v() : v;
|
|
53
|
+
if (vtxt != undefined && vtxt.length > 0)
|
|
54
|
+
return `${k}\n${vtxt}`;
|
|
55
|
+
return undefined;
|
|
56
|
+
})).then(p => p.filter(v => v != undefined).join('\n\n'));
|
|
57
|
+
}
|
|
58
|
+
/**辅助构建代码块
|
|
59
|
+
* @param content - 代码内容
|
|
60
|
+
* @param lang - 代码块语言类型
|
|
61
|
+
*/
|
|
62
|
+
static async buildCodeBlock(content, lang) {
|
|
63
|
+
return '```' + (lang ?? '') + content + '```';
|
|
64
|
+
}
|
|
45
65
|
/**输出md文本 */
|
|
46
66
|
async stringify(opt) {
|
|
47
|
-
const
|
|
67
|
+
const fxopt = Object.assign({
|
|
68
|
+
blockQuote: false,
|
|
69
|
+
doubleQuotedAsJSON: true,
|
|
70
|
+
singleQuote: true,
|
|
71
|
+
defaultStringType: "QUOTE_SINGLE",
|
|
72
|
+
defaultKeyType: "PLAIN",
|
|
73
|
+
lineWidth: 0,
|
|
74
|
+
minContentWidth: 0,
|
|
75
|
+
}, opt);
|
|
76
|
+
const yamlText = Object.values(this.data ?? {}).length > 0 ? `---\n${(await getYaml()).stringify(this.data, fxopt)}---\n` : '';
|
|
48
77
|
return `${yamlText}${this.content}`;
|
|
49
78
|
//return (await getMatter()).stringify(this.content,this.data);
|
|
50
79
|
}
|
package/dist/UtilFunctions.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { JsFunc } from "@zwa73/js-utils";
|
|
2
2
|
import type { LogLevel } from "./UtilInterfaces";
|
|
3
|
-
export type { PromiseRetries, PromiseRetryResult } from "@zwa73/js-utils";
|
|
4
3
|
declare const HashAlgorithmList: readonly ["RSA-MD5", "RSA-RIPEMD160", "RSA-SHA1", "RSA-SHA1-2", "RSA-SHA224", "RSA-SHA256", "RSA-SHA3-224", "RSA-SHA3-256", "RSA-SHA3-384", "RSA-SHA3-512", "RSA-SHA384", "RSA-SHA512", "RSA-SHA512/224", "RSA-SHA512/256", "RSA-SM3", "blake2b512", "blake2s256", "id-rsassa-pkcs1-v1_5-with-sha3-224", "id-rsassa-pkcs1-v1_5-with-sha3-256", "id-rsassa-pkcs1-v1_5-with-sha3-384", "id-rsassa-pkcs1-v1_5-with-sha3-512", "md5", "md5-sha1", "md5WithRSAEncryption", "ripemd", "ripemd160", "ripemd160WithRSA", "rmd160", "sha1", "sha1WithRSAEncryption", "sha224", "sha224WithRSAEncryption", "sha256", "sha256WithRSAEncryption", "sha3-224", "sha3-256", "sha3-384", "sha3-512", "sha384", "sha384WithRSAEncryption", "sha512", "sha512-224", "sha512-224WithRSAEncryption", "sha512-256", "sha512-256WithRSAEncryption", "sha512WithRSAEncryption", "shake128", "shake256", "sm3", "sm3WithRSAEncryption", "ssl3-md5", "ssl3-sha1"];
|
|
5
4
|
export type HashAlgorithm = typeof HashAlgorithmList[number];
|
|
6
5
|
/**执行选项 */
|
|
@@ -49,3 +48,4 @@ declare class _UtilFunc {
|
|
|
49
48
|
}
|
|
50
49
|
export declare const UtilFunc: import("@zwa73/modular-mixer").ComposedClass<typeof _UtilFunc, typeof JsFunc, "__jsUtils", "prototype" | "preset" | "assignOption" | "genUUID" | "getTime" | "initField" | "initObject" | "afterward" | "sleep" | "getNeverResolvedPromise" | "retryPromise" | "timelimitPromise" | "mapEntries" | "eachField" | "stringifyJToken" | "sortJToken" | "assertType" | "assertLiteral" | "deepClone" | "isSafeNumber" | "dedent" | "throwError" | "getStack" | "getFuncLoc" | "cachePool" | "memoize" | "asyncize" | "lazyFunction" | "splitToChunk" | "mergeFromChunk" | "structEqual" | "concurrent" | "dynamicImport" | "createInjectable" | "createAsyncProxy" | "checkSharpSchema" | "unwarpReadonly" | "outcome" | "extractOutcome" | "success" | "failed" | "match" | "isStatus" | "eitherize" | "parseSrtTime" | "formatSrtTime" | "parseSrt" | "createSrt" | "ivk" | "range" | "s2l" | "l2s">;
|
|
51
50
|
export type UtilFunc = typeof UtilFunc;
|
|
51
|
+
export {};
|
package/dist/UtilHttp.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import http from 'http';
|
|
2
|
-
import type { LogLevel } from "@zwa73/js-utils";
|
|
2
|
+
import type { LogLevel, PromiseRetries } from "@zwa73/js-utils";
|
|
3
3
|
import { PromiseQueue } from "@zwa73/js-utils";
|
|
4
4
|
import FormData from "form-data";
|
|
5
|
-
import type { PromiseRetries } from "./UtilFunctions";
|
|
6
5
|
import type { AnyString, JToken, MPromise, PartialOption, StatusVerifyFn } from "./UtilInterfaces";
|
|
7
6
|
/**网络请求返回值 */
|
|
8
7
|
export type RequestResult<T> = {
|