foreslash 0.3.0 → 0.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Change Log
2
2
 
3
+ ## Version 0.3.1 - 2025-08-14
4
+
5
+ Unstable version
6
+
7
+ - Feat 🥥 Functions added: `indent` and so forth
8
+ - Use GitHub Actions to automate the npm publish/github release process
9
+ - Other fixes and improvements
10
+
11
+ 不稳定版本
12
+
13
+ - 功能 🥥 添加函数: `indent` 等
14
+ - 使用 GitHub Actions 实现自动化 npm 发版/github release 流程
15
+ - 其他修复与优化
16
+
3
17
  ## Version 0.3.0 - 2025-07-01
4
18
 
5
19
  Unstable version
package/LICENSE CHANGED
@@ -1,9 +1,127 @@
1
- Copyright (c) 2024-2025 moushu
2
- foreslash is licensed under Mulan PSL v2.
3
- You can use this software according to the terms and conditions of the Mulan PSL v2.
4
- You may obtain a copy of Mulan PSL v2 at:
5
- http://license.coscl.org.cn/MulanPSL2
6
- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7
- EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8
- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9
- See the Mulan PSL v2 for more details.
1
+ 木兰宽松许可证, 第2版
2
+
3
+ 木兰宽松许可证, 第2版
4
+ 2020年1月 http://license.coscl.org.cn/MulanPSL2
5
+
6
+
7
+ 您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束:
8
+
9
+ 0. 定义
10
+
11
+ “软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。
12
+
13
+ “贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。
14
+
15
+ “贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。
16
+
17
+ “法人实体”是指提交贡献的机构及其“关联实体”。
18
+
19
+ “关联实体”是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。
20
+
21
+ 1. 授予版权许可
22
+
23
+ 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。
24
+
25
+ 2. 授予专利许可
26
+
27
+ 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。
28
+
29
+ 3. 无商标许可
30
+
31
+ “本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。
32
+
33
+ 4. 分发限制
34
+
35
+ 您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。
36
+
37
+ 5. 免责声明与责任限制
38
+
39
+ “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。
40
+
41
+ 6. 语言
42
+ “本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。
43
+
44
+ 条款结束
45
+
46
+ 如何将木兰宽松许可证,第2版,应用到您的软件
47
+
48
+ 如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步:
49
+
50
+ 1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字;
51
+
52
+ 2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中;
53
+
54
+ 3, 请将如下声明文本放入每个源文件的头部注释中。
55
+
56
+ Copyright (c) 2024-2025 moushu
57
+ foreslash is licensed under Mulan PSL v2.
58
+ You can use this software according to the terms and conditions of the Mulan PSL v2.
59
+ You may obtain a copy of Mulan PSL v2 at:
60
+ http://license.coscl.org.cn/MulanPSL2
61
+ THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
62
+ See the Mulan PSL v2 for more details.
63
+
64
+
65
+ Mulan Permissive Software License,Version 2
66
+
67
+ Mulan Permissive Software License,Version 2 (Mulan PSL v2)
68
+ January 2020 http://license.coscl.org.cn/MulanPSL2
69
+
70
+ Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions:
71
+
72
+ 0. Definition
73
+
74
+ Software means the program and related documents which are licensed under this License and comprise all Contribution(s).
75
+
76
+ Contribution means the copyrightable work licensed by a particular Contributor under this License.
77
+
78
+ Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License.
79
+
80
+ Legal Entity means the entity making a Contribution and all its Affiliates.
81
+
82
+ Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity.
83
+
84
+ 1. Grant of Copyright License
85
+
86
+ Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not.
87
+
88
+ 2. Grant of Patent License
89
+
90
+ Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken.
91
+
92
+ 3. No Trademark License
93
+
94
+ No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4.
95
+
96
+ 4. Distribution Restriction
97
+
98
+ You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software.
99
+
100
+ 5. Disclaimer of Warranty and Limitation of Liability
101
+
102
+ THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
103
+
104
+ 6. Language
105
+
106
+ THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL.
107
+
108
+ END OF THE TERMS AND CONDITIONS
109
+
110
+ How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software
111
+
112
+ To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps:
113
+
114
+ i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner;
115
+
116
+ ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package;
117
+
118
+ iii Attach the statement to the appropriate annotated syntax at the beginning of each source file.
119
+
120
+
121
+ Copyright (c) 2024-2025 moushu
122
+ foreslash is licensed under Mulan PSL v2.
123
+ You can use this software according to the terms and conditions of the Mulan PSL v2.
124
+ You may obtain a copy of Mulan PSL v2 at:
125
+ http://license.coscl.org.cn/MulanPSL2
126
+ THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
127
+ See the Mulan PSL v2 for more details.
package/lib/index.cmn.cjs CHANGED
@@ -1306,6 +1306,45 @@ function caseSnake(str, keepLetterCase = false, keepNumber = true) {
1306
1306
  return _caseConvert(tokens, '_', keepLetterCase ? ({ code }) => code : ({ code }) => code.toLowerCase());
1307
1307
  }
1308
1308
 
1309
+ function dedent(str, option, indentStr) {
1310
+ if (typeof option === 'number' || indentStr) {
1311
+ return _dedent(str, option || 2, indentStr || ' ');
1312
+ }
1313
+ else {
1314
+ const { count = 2, indentStr = ' ' } = option || {};
1315
+ return _dedent(str, count, indentStr);
1316
+ }
1317
+ }
1318
+ function _dedent(str, count, indentStr) {
1319
+ return str
1320
+ .split('\n')
1321
+ .map((s) => {
1322
+ let i = count;
1323
+ while (s && s.startsWith(indentStr) && i > 0) {
1324
+ s = s.slice(indentStr.length);
1325
+ i--;
1326
+ }
1327
+ return s;
1328
+ })
1329
+ .join('\n');
1330
+ }
1331
+
1332
+ function indent(str, option, indentStr) {
1333
+ if (typeof option === 'number' || indentStr) {
1334
+ return _indent(str, option || 2, indentStr || ' ', true);
1335
+ }
1336
+ else {
1337
+ const { count = 2, indentStr = ' ', ignoreEmptyLine = true } = option || {};
1338
+ return _indent(str, count, indentStr, ignoreEmptyLine);
1339
+ }
1340
+ }
1341
+ function _indent(str, count, indentStr, ignoreEmptyLine) {
1342
+ return str
1343
+ .split('\n')
1344
+ .map((s) => `${s || !ignoreEmptyLine ? indentStr.repeat(count) : ''}${s}`)
1345
+ .join('\n');
1346
+ }
1347
+
1309
1348
  function splitWords(str) {
1310
1349
  return _splitVar(str).map(({ code }) => code);
1311
1350
  }
@@ -2018,6 +2057,7 @@ exports.clamp = clamp;
2018
2057
  exports.compose = compose;
2019
2058
  exports.curry = _curryMore;
2020
2059
  exports.debounce = debounce;
2060
+ exports.dedent = dedent;
2021
2061
  exports.deepClone = deepClone;
2022
2062
  exports.deepMerge = deepMerge;
2023
2063
  exports.defer = defer;
@@ -2026,6 +2066,7 @@ exports.getAcceptableExtByMIME = getAcceptableExtByMIME;
2026
2066
  exports.getAcceptableMIMEByExt = getAcceptableMIMEByExt;
2027
2067
  exports.getGlobalThis = getGlobalThis;
2028
2068
  exports.getTag = getTag;
2069
+ exports.indent = indent;
2029
2070
  exports.isArray = isArray;
2030
2071
  exports.isArrayBuffer = isArrayBuffer;
2031
2072
  exports.isArrayLike = isArrayLike;
package/lib/index.d.ts CHANGED
@@ -196,8 +196,7 @@ declare function retry<T>(asyncFunction: RetryFunction<T>, option?: RetryOption)
196
196
  */
197
197
  declare function sleep(time?: number): Promise<unknown>;
198
198
 
199
- type TryitResultType<Res, Err> = [undefined, Res] | [Err, undefined];
200
- type TryitResult<Res, Err extends Error> = Res extends Promise<infer R> ? Promise<TryitResultType<R, Err>> : TryitResultType<Res, Err>;
199
+ type TryitResult<Res, Err> = [undefined, Res] | [Err, undefined];
201
200
  /**
202
201
  * 将一个函数处理为 `error-first` 的函数
203
202
  * @param fn 需要处理的函数, 可以是异步函数
@@ -207,11 +206,6 @@ type TryitResult<Res, Err extends Error> = Res extends Promise<infer R> ? Promis
207
206
  * 如果出现异常则 `result` 为 `undefined`, `error` 是原函数抛出的错误
208
207
  * @example
209
208
  * ```js
210
- * // Sync Function
211
- * const normalFn = () => { return 1 }
212
- * const errorFn = () => { throw new Error('1') }
213
- * tryit(normalFn)() // [undefined, 1]
214
- * tryit(errorFn)() // [Error('1'), undefined]
215
209
  * // Async Function
216
210
  * const normalAsyncFn = () => { return Promise.resolve(1) }
217
211
  * const errorAsyncFn = () => { return Promise.reject('1') }
@@ -220,6 +214,24 @@ type TryitResult<Res, Err extends Error> = Res extends Promise<infer R> ? Promis
220
214
  * ```
221
215
  * @version 0.2.0
222
216
  */
217
+ declare function tryit<Args extends any[], Res, Err extends Error>(fn: (...args: Args) => Promise<Res>): (...args: Args) => Promise<TryitResult<Res, Err>>;
218
+ /**
219
+ * 将一个函数处理为 `error-first` 的函数
220
+ * @param fn 需要处理的函数, 可以是异步函数
221
+ * @returns 处理过的函数, 调用后返回一个 `error-first` 的元组 `[error, result]`;\
222
+ * 如果原函数是异步函数, 则返回值会是 `Promise<[error, result]>`;\
223
+ * 如果运行正常则 `result` 是原函数的返回值, `error` 为 `undefined`;\
224
+ * 如果出现异常则 `result` 为 `undefined`, `error` 是原函数抛出的错误
225
+ * @example
226
+ * ```js
227
+ * // Sync Function
228
+ * const normalFn = () => { return 1 }
229
+ * const errorFn = () => { throw new Error('1') }
230
+ * tryit(normalFn)() // [undefined, 1]
231
+ * tryit(errorFn)() // [Error('1'), undefined]
232
+ * ```
233
+ * @version 0.2.0
234
+ */
223
235
  declare function tryit<Args extends any[], Res, Err extends Error>(fn: (...args: Args) => Res): (...args: Args) => TryitResult<Res, Err>;
224
236
 
225
237
  interface PromiseLikeConstructor {
@@ -1264,6 +1276,74 @@ declare function caseKebab(str: string, keepLetterCase?: boolean, keepNumber?: b
1264
1276
  */
1265
1277
  declare function caseSnake(str: string, keepLetterCase?: boolean, keepNumber?: boolean): string;
1266
1278
 
1279
+ /**
1280
+ * 给一个多行的字符串清除缩进效果
1281
+ * @param str 需要处理的字符串
1282
+ * @param count 缩进数量, 默认为 `2`
1283
+ * @param indentStr 缩进字符串, 默认为 ` `(一个空格)
1284
+ * @returns 处理过的字符串
1285
+ * @example
1286
+ * ```js
1287
+ * dedent(` a\n b\n c`) // `a\nb\n c`
1288
+ * dedent(`*a\n**b\n****c`, 3, '*') // `a\nb\n*c`
1289
+ * ```
1290
+ * @version 0.3.1
1291
+ */
1292
+ declare function dedent(str: string, count?: number | null, indentStr?: string): string;
1293
+ /**
1294
+ * 给一个多行的字符串清除缩进效果
1295
+ * @param str 需要处理的字符串
1296
+ * @param option 缩进效果配置
1297
+ * - `count` 缩进数量, 默认为 `2`
1298
+ * - `indentStr` 缩进字符串, 默认为 ` `(一个空格)
1299
+ * @returns 处理过的字符串
1300
+ * @example
1301
+ * ```js
1302
+ * dedent(` a\n b\n c`) // `a\nb\n c`
1303
+ * dedent(`*a\n**b\n****c`, { count: 3, indentStr: '*' }) // `a\nb\n*c`
1304
+ * ```
1305
+ * @version 0.3.1
1306
+ */
1307
+ declare function dedent(str: string, option?: {
1308
+ count?: number;
1309
+ indentStr?: string;
1310
+ }): string;
1311
+
1312
+ /**
1313
+ * 给一个多行的字符串添加缩进效果
1314
+ * @param str 需要处理的字符串
1315
+ * @param count 缩进数量, 默认为 `2`
1316
+ * @param indentStr 缩进字符串, 默认为 ` `(一个空格)
1317
+ * @returns 处理过的字符串
1318
+ * @example
1319
+ * ```js
1320
+ * indent(`a\nb\n c`) // ` a\n b\n c`
1321
+ * indent(`a\nb\n c`, 1, '*') // `*a\n*b\n* c`
1322
+ * ```
1323
+ * @version 0.3.1
1324
+ */
1325
+ declare function indent(str: string, count?: number | null, indentStr?: string): string;
1326
+ /**
1327
+ * 给一个多行的字符串添加缩进效果
1328
+ * @param str 需要处理的字符串
1329
+ * @param option 缩进效果配置
1330
+ * - `count` 缩进数量, 默认为 `2`
1331
+ * - `indentStr` 缩进字符串, 默认为 ` `(一个空格)
1332
+ * - `ignoreEmptyLine` 是否忽略空行, 默认为是
1333
+ * @returns 处理过的字符串
1334
+ * @example
1335
+ * ```js
1336
+ * indent(`a\nb\n c`) // ` a\n b\n c`
1337
+ * indent(`a\nb\n c`, { count: 1, indentStr: '*' }) // `*a\n*b\n* c`
1338
+ * ```
1339
+ * @version 0.3.1
1340
+ */
1341
+ declare function indent(str: string, option?: {
1342
+ count?: number;
1343
+ indentStr?: string;
1344
+ ignoreEmptyLine?: boolean;
1345
+ }): string;
1346
+
1267
1347
  /**
1268
1348
  * 分割单词, 适用于分割、转换变量名的场景
1269
1349
  * - 任何非英文字母、数字的字符均会视为分割符
@@ -1906,5 +1986,5 @@ declare function throttle<T extends any[]>(fn: (...args: T) => any, delay: numbe
1906
1986
  reset: () => void;
1907
1987
  };
1908
1988
 
1909
- export { $$Empty, _, acceptableFileName, acceptableFileType, camelCase, capitalize, caseCamel, caseConvert, caseKebab, casePascal, caseSnake, clamp, compose, _curryMore as curry, debounce, deepClone, deepMerge, defer, fastClone, getAcceptableExtByMIME, getAcceptableMIMEByExt, getGlobalThis, getTag, isArray, isArrayBuffer, isArrayLike, isBigInt, isBigInt64Array, isBigUint64Array, isBlob, isBoolean, isBuffer, isDataView, isDate, isEmpty, isFile, isFloat32Array, isFloat64Array, isFormData, isFunction, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isMap, isMergeEmptyPlaceholder, isNil, isNull, isNumber, isObject, isPlaceholder, isPrimitive, isPromise, isPromiseLike, isRegExp, isSet, isString, isSymbol, isTypedArray, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isWeakMap, isWeakSet, isWrapperBigInt, isWrapperBoolean, isWrapperNumber, isWrapperObject, isWrapperString, isWrapperSymbol, kebabCase, memo, noop, not, parallel, pascalCase, pass, passWith, pipe, randomBase32String, randomChoice, randomHexString, randomInt, randomIntFloor, randomString, range, remove, retry, shuffle, sleep, snakeCase, splitWords, throttle, titleCase, tryit, ulid, uncapitalize, uuidNil, uuidV4, withResolvers };
1989
+ export { $$Empty, _, acceptableFileName, acceptableFileType, camelCase, capitalize, caseCamel, caseConvert, caseKebab, casePascal, caseSnake, clamp, compose, _curryMore as curry, debounce, dedent, deepClone, deepMerge, defer, fastClone, getAcceptableExtByMIME, getAcceptableMIMEByExt, getGlobalThis, getTag, indent, isArray, isArrayBuffer, isArrayLike, isBigInt, isBigInt64Array, isBigUint64Array, isBlob, isBoolean, isBuffer, isDataView, isDate, isEmpty, isFile, isFloat32Array, isFloat64Array, isFormData, isFunction, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isMap, isMergeEmptyPlaceholder, isNil, isNull, isNumber, isObject, isPlaceholder, isPrimitive, isPromise, isPromiseLike, isRegExp, isSet, isString, isSymbol, isTypedArray, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isWeakMap, isWeakSet, isWrapperBigInt, isWrapperBoolean, isWrapperNumber, isWrapperObject, isWrapperString, isWrapperSymbol, kebabCase, memo, noop, not, parallel, pascalCase, pass, passWith, pipe, randomBase32String, randomChoice, randomHexString, randomInt, randomIntFloor, randomString, range, remove, retry, shuffle, sleep, snakeCase, splitWords, throttle, titleCase, tryit, ulid, uncapitalize, uuidNil, uuidV4, withResolvers };
1910
1990
  export type { BaseMargeType, CloneOptions, CustomCloner, MergeOption, MergeStrategy, MergeStrategyFunction, MergeType, MergeTypeStrategy, RangeOptions, SourceMergeType, TargetMergeType, TypedArray };
package/lib/index.mjs CHANGED
@@ -1304,6 +1304,45 @@ function caseSnake(str, keepLetterCase = false, keepNumber = true) {
1304
1304
  return _caseConvert(tokens, '_', keepLetterCase ? ({ code }) => code : ({ code }) => code.toLowerCase());
1305
1305
  }
1306
1306
 
1307
+ function dedent(str, option, indentStr) {
1308
+ if (typeof option === 'number' || indentStr) {
1309
+ return _dedent(str, option || 2, indentStr || ' ');
1310
+ }
1311
+ else {
1312
+ const { count = 2, indentStr = ' ' } = option || {};
1313
+ return _dedent(str, count, indentStr);
1314
+ }
1315
+ }
1316
+ function _dedent(str, count, indentStr) {
1317
+ return str
1318
+ .split('\n')
1319
+ .map((s) => {
1320
+ let i = count;
1321
+ while (s && s.startsWith(indentStr) && i > 0) {
1322
+ s = s.slice(indentStr.length);
1323
+ i--;
1324
+ }
1325
+ return s;
1326
+ })
1327
+ .join('\n');
1328
+ }
1329
+
1330
+ function indent(str, option, indentStr) {
1331
+ if (typeof option === 'number' || indentStr) {
1332
+ return _indent(str, option || 2, indentStr || ' ', true);
1333
+ }
1334
+ else {
1335
+ const { count = 2, indentStr = ' ', ignoreEmptyLine = true } = option || {};
1336
+ return _indent(str, count, indentStr, ignoreEmptyLine);
1337
+ }
1338
+ }
1339
+ function _indent(str, count, indentStr, ignoreEmptyLine) {
1340
+ return str
1341
+ .split('\n')
1342
+ .map((s) => `${s || !ignoreEmptyLine ? indentStr.repeat(count) : ''}${s}`)
1343
+ .join('\n');
1344
+ }
1345
+
1307
1346
  function splitWords(str) {
1308
1347
  return _splitVar(str).map(({ code }) => code);
1309
1348
  }
@@ -2001,4 +2040,4 @@ function throttle(fn, delay, options) {
2001
2040
  return _throttle(fn, delay, Object.assign({ trailing: false, leading: true }, options));
2002
2041
  }
2003
2042
 
2004
- export { $$Empty, _, acceptableFileName, acceptableFileType, camelCase, capitalize, caseCamel, caseConvert, caseKebab, casePascal, caseSnake, clamp, compose, _curryMore as curry, debounce, deepClone, deepMerge, defer, fastClone, getAcceptableExtByMIME, getAcceptableMIMEByExt, getGlobalThis, getTag, isArray, isArrayBuffer, isArrayLike, isBigInt, isBigInt64Array, isBigUint64Array, isBlob, isBoolean, isBuffer, isDataView, isDate, isEmpty, isFile, isFloat32Array, isFloat64Array, isFormData, isFunction, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isMap, isMergeEmptyPlaceholder, isNil, isNull, isNumber, isObject, isPlaceholder, isPrimitive, isPromise, isPromiseLike, isRegExp, isSet, isString, isSymbol, isTypedArray, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isWeakMap, isWeakSet, isWrapperBigInt, isWrapperBoolean, isWrapperNumber, isWrapperObject, isWrapperString, isWrapperSymbol, kebabCase, memo, noop, not, parallel, pascalCase, pass, passWith, pipe, randomBase32String, randomChoice, randomHexString, randomInt, randomIntFloor, randomString, range, remove, retry, shuffle, sleep, snakeCase, splitWords, throttle, titleCase, tryit, ulid, uncapitalize, uuidNil, uuidV4, withResolvers };
2043
+ export { $$Empty, _, acceptableFileName, acceptableFileType, camelCase, capitalize, caseCamel, caseConvert, caseKebab, casePascal, caseSnake, clamp, compose, _curryMore as curry, debounce, dedent, deepClone, deepMerge, defer, fastClone, getAcceptableExtByMIME, getAcceptableMIMEByExt, getGlobalThis, getTag, indent, isArray, isArrayBuffer, isArrayLike, isBigInt, isBigInt64Array, isBigUint64Array, isBlob, isBoolean, isBuffer, isDataView, isDate, isEmpty, isFile, isFloat32Array, isFloat64Array, isFormData, isFunction, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isMap, isMergeEmptyPlaceholder, isNil, isNull, isNumber, isObject, isPlaceholder, isPrimitive, isPromise, isPromiseLike, isRegExp, isSet, isString, isSymbol, isTypedArray, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isWeakMap, isWeakSet, isWrapperBigInt, isWrapperBoolean, isWrapperNumber, isWrapperObject, isWrapperString, isWrapperSymbol, kebabCase, memo, noop, not, parallel, pascalCase, pass, passWith, pipe, randomBase32String, randomChoice, randomHexString, randomInt, randomIntFloor, randomString, range, remove, retry, shuffle, sleep, snakeCase, splitWords, throttle, titleCase, tryit, ulid, uncapitalize, uuidNil, uuidV4, withResolvers };
package/lib/index.umd.js CHANGED
@@ -1310,6 +1310,45 @@ See the Mulan PSL v2 for more details.
1310
1310
  return _caseConvert(tokens, '_', keepLetterCase ? ({ code }) => code : ({ code }) => code.toLowerCase());
1311
1311
  }
1312
1312
 
1313
+ function dedent(str, option, indentStr) {
1314
+ if (typeof option === 'number' || indentStr) {
1315
+ return _dedent(str, option || 2, indentStr || ' ');
1316
+ }
1317
+ else {
1318
+ const { count = 2, indentStr = ' ' } = option || {};
1319
+ return _dedent(str, count, indentStr);
1320
+ }
1321
+ }
1322
+ function _dedent(str, count, indentStr) {
1323
+ return str
1324
+ .split('\n')
1325
+ .map((s) => {
1326
+ let i = count;
1327
+ while (s && s.startsWith(indentStr) && i > 0) {
1328
+ s = s.slice(indentStr.length);
1329
+ i--;
1330
+ }
1331
+ return s;
1332
+ })
1333
+ .join('\n');
1334
+ }
1335
+
1336
+ function indent(str, option, indentStr) {
1337
+ if (typeof option === 'number' || indentStr) {
1338
+ return _indent(str, option || 2, indentStr || ' ', true);
1339
+ }
1340
+ else {
1341
+ const { count = 2, indentStr = ' ', ignoreEmptyLine = true } = option || {};
1342
+ return _indent(str, count, indentStr, ignoreEmptyLine);
1343
+ }
1344
+ }
1345
+ function _indent(str, count, indentStr, ignoreEmptyLine) {
1346
+ return str
1347
+ .split('\n')
1348
+ .map((s) => `${s || !ignoreEmptyLine ? indentStr.repeat(count) : ''}${s}`)
1349
+ .join('\n');
1350
+ }
1351
+
1313
1352
  function splitWords(str) {
1314
1353
  return _splitVar(str).map(({ code }) => code);
1315
1354
  }
@@ -2022,6 +2061,7 @@ See the Mulan PSL v2 for more details.
2022
2061
  exports.compose = compose;
2023
2062
  exports.curry = _curryMore;
2024
2063
  exports.debounce = debounce;
2064
+ exports.dedent = dedent;
2025
2065
  exports.deepClone = deepClone;
2026
2066
  exports.deepMerge = deepMerge;
2027
2067
  exports.defer = defer;
@@ -2030,6 +2070,7 @@ See the Mulan PSL v2 for more details.
2030
2070
  exports.getAcceptableMIMEByExt = getAcceptableMIMEByExt;
2031
2071
  exports.getGlobalThis = getGlobalThis;
2032
2072
  exports.getTag = getTag;
2073
+ exports.indent = indent;
2033
2074
  exports.isArray = isArray;
2034
2075
  exports.isArrayBuffer = isArrayBuffer;
2035
2076
  exports.isArrayLike = isArrayLike;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreslash",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Foreslash is a Javascript utilities lib which contains plenty of practical functions.",
5
5
  "author": "moushu",
6
6
  "license": "Mulan PSL v2",
@@ -45,10 +45,8 @@
45
45
  "foreslash",
46
46
  "lib",
47
47
  "util",
48
- "utilities",
49
48
  "typescript",
50
- "functional",
51
- "modules"
49
+ "functional"
52
50
  ],
53
51
  "devDependencies": {
54
52
  "@rollup/plugin-typescript": "^12.1.2",
@@ -57,6 +55,7 @@
57
55
  "jest-environment-jsdom": "^29.7.0",
58
56
  "rollup": "^4.38.0",
59
57
  "rollup-plugin-dts": "^6.2.1",
58
+ "sass-embedded": "^1.90.0",
60
59
  "ts-jest": "^29.2.5",
61
60
  "tslib": "^2.7.0",
62
61
  "typescript": "^5.5.4",