Skip to content

📖 笔落写作开放JavaScript扩展函数

为了让用户在脚本中更方便地操作字符串,本 APP 内置了一些 扩展方法全局函数
这些方法在用户脚本运行时会自动注入,无需额外引入。


🔤 字符串扩展

1. startsWith(str)

判断字符串是否以指定内容开头。

js
"笔落写作".startsWith("笔落")  // true
"笔落写作".startsWith("写作")  // false

2. endsWith(str)

判断字符串是否以指定内容结尾。

js
"hello.js".endsWith(".js")   // true
"hello.js".endsWith(".ts")   // false

3. contains(subStr)

判断字符串中是否包含指定内容。

js
"今天写了300字".contains("300")   // true
"今天写了300字".contains("500")   // false

4. firstChar

获取字符串的第一个字符。

js
"写作之路".firstChar   // "写"
"".firstChar           // "" (空字符串)

5. lastChar

获取字符串的最后一个字符。

js
"写作之路".lastChar   // "路"
"".lastChar           // "" (空字符串)

🌍 全局函数

1. contactString(...args)

拼接多个字符串,返回合并后的结果。

js
contactString("笔落", "写作", "平台") 
// "笔落写作平台"

2. buildTemplateString(defaultValue)

生成一个带模板占位符的字符串。

js
buildTemplateString("章节标题") 
// "{{章节标题}}"

常用于需要动态替换的场景。


📚 提示

这些方法和函数会自动注入到用户脚本中,无需手动导入