@celhive/tool.js 0.0.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/README.md +7 -0
- package/doc/.nojekyll +1 -0
- package/doc/assets/highlight.css +29 -0
- package/doc/assets/icons.css +1043 -0
- package/doc/assets/icons.png +0 -0
- package/doc/assets/icons@2x.png +0 -0
- package/doc/assets/main.js +52 -0
- package/doc/assets/search.js +1 -0
- package/doc/assets/style.css +1413 -0
- package/doc/assets/widgets.png +0 -0
- package/doc/assets/widgets@2x.png +0 -0
- package/doc/classes/MockStream.html +24 -0
- package/doc/index.html +11 -0
- package/doc/modules.html +11 -0
- package/lib/formatCitation.d.ts +6 -0
- package/lib/formatCitation.js +20 -0
- package/lib/formatCitation.js.map +1 -0
- package/lib/getPDFViewerUrl.d.ts +1 -0
- package/lib/getPDFViewerUrl.js +10 -0
- package/lib/getPDFViewerUrl.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +21 -0
- package/lib/index.js.map +1 -0
- package/lib/mendMarkdown.d.ts +6 -0
- package/lib/mendMarkdown.js +43 -0
- package/lib/mendMarkdown.js.map +1 -0
- package/lib/mockStream.d.ts +29 -0
- package/lib/mockStream.js +58 -0
- package/lib/mockStream.js.map +1 -0
- package/package.json +34 -0
- package/tsconfig.json +16 -0
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!DOCTYPE html><html class="default"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>MockStream | @celhive/tool.js</title><meta name="description" content="Documentation for @celhive/tool.js"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script async src="../assets/search.js" id="search-script"></script></head><body><script>document.body.classList.add(localStorage.getItem("tsd-theme") || "os")</script><header><div class="tsd-page-toolbar"><div class="container"><div class="table-wrap"><div class="table-cell" id="tsd-search" data-base=".."><div class="field"><label for="tsd-search-field" class="tsd-widget search no-caption">Search</label><input type="text" id="tsd-search-field"/></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@celhive/tool.js</a></div><div class="table-cell" id="tsd-widgets"><div id="tsd-filter"><a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a><div class="tsd-filter-group"><div class="tsd-select" id="tsd-filter-visibility"><span class="tsd-select-label">All</span><ul class="tsd-select-list"><li data-value="public">Public</li><li data-value="protected">Public/Protected</li><li data-value="private" class="selected">All</li></ul></div> <input type="checkbox" id="tsd-filter-inherited" checked/><label class="tsd-widget" for="tsd-filter-inherited">Inherited</label><input type="checkbox" id="tsd-filter-externals" checked/><label class="tsd-widget" for="tsd-filter-externals">Externals</label></div></div><a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a></div></div></div></div><div class="tsd-page-title"><div class="container"><ul class="tsd-breadcrumb"><li><a href="../modules.html">@celhive/tool.js</a></li><li><a href="MockStream.html">MockStream</a></li></ul><h1>Class MockStream</h1></div></div></header><div class="container container-main"><div class="row"><div class="col-8 col-content"><section class="tsd-panel tsd-comment"><div class="tsd-comment tsd-typography"><div class="lead">
|
|
2
|
+
<p>模拟 SSE 流式输出</p>
|
|
3
|
+
</div></div></section><section class="tsd-panel tsd-hierarchy"><h3>Hierarchy</h3><ul class="tsd-hierarchy"><li><span class="target">MockStream</span></li></ul></section><section class="tsd-panel-group tsd-index-group"><h2>Index</h2><section class="tsd-panel tsd-index-panel"><div class="tsd-index-content"><section class="tsd-index-section "><h3>Constructors</h3><ul class="tsd-index-list"><li class="tsd-kind-constructor tsd-parent-kind-class"><a href="MockStream.html#constructor" class="tsd-kind-icon">constructor</a></li></ul></section><section class="tsd-index-section tsd-is-private tsd-is-private-protected"><h3>Properties</h3><ul class="tsd-index-list"><li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><a href="MockStream.html#duration" class="tsd-kind-icon">duration</a></li><li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><a href="MockStream.html#outputLength" class="tsd-kind-icon">output<wbr/>Length</a></li><li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><a href="MockStream.html#str" class="tsd-kind-icon">str</a></li></ul></section><section class="tsd-index-section "><h3>Methods</h3><ul class="tsd-index-list"><li class="tsd-kind-method tsd-parent-kind-class"><a href="MockStream.html#start" class="tsd-kind-icon">start</a></li></ul></section></div></section></section><section class="tsd-panel-group tsd-member-group "><h2>Constructors</h2><section class="tsd-panel tsd-member tsd-kind-constructor tsd-parent-kind-class"><a id="constructor" class="tsd-anchor"></a><h3 class="tsd-anchor-link">constructor<a href="#constructor" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-constructor tsd-parent-kind-class"><li class="tsd-signature tsd-kind-icon">new <wbr/>Mock<wbr/>Stream<span class="tsd-signature-symbol">(</span>options<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">{ </span>duration<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">; </span>outputLength<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">; </span>str<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> }</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="MockStream.html" class="tsd-signature-type" data-tsd-kind="Class">MockStream</a></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/alex-reinfoce/herm-studio-tool.js/blob/1a098c9/src/mockStream.ts#L19">mockStream.ts:19</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
|
4
|
+
<p>创建一个模拟流式输出实例</p>
|
|
5
|
+
</div></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>options: <span class="tsd-signature-symbol">{ </span>duration<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">; </span>outputLength<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">; </span>str<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> }</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
|
|
6
|
+
<p>配置选项</p>
|
|
7
|
+
</div></div><ul class="tsd-parameters"><li class="tsd-parameter"><h5><span class="tsd-flag ts-flagOptional">Optional</span> duration<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">number</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
|
|
8
|
+
<p>每次输出的时间间隔,单位毫秒(默认值:100)</p>
|
|
9
|
+
</div></div></li><li class="tsd-parameter"><h5><span class="tsd-flag ts-flagOptional">Optional</span> output<wbr/>Length<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">number</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
|
|
10
|
+
<p>每次输出的字符数量(默认值:200)</p>
|
|
11
|
+
</div></div></li><li class="tsd-parameter"><h5>str<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
|
|
12
|
+
<p>需要输出的字符串</p>
|
|
13
|
+
</div></div></li></ul></li></ul><h4 class="tsd-returns-title">Returns <a href="MockStream.html" class="tsd-signature-type" data-tsd-kind="Class">MockStream</a></h4></li></ul></section></section><section class="tsd-panel-group tsd-member-group tsd-is-private tsd-is-private-protected"><h2>Properties</h2><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-private"><a id="duration" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagPrivate">Private</span> duration<a href="#duration" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">duration<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span><span class="tsd-signature-symbol"> = 0</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/alex-reinfoce/herm-studio-tool.js/blob/1a098c9/src/mockStream.ts#L10">mockStream.ts:10</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
|
14
|
+
<p>每次输出的时间间隔(毫秒)</p>
|
|
15
|
+
</div></div></section><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-private"><a id="outputLength" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagPrivate">Private</span> output<wbr/>Length<a href="#outputLength" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">output<wbr/>Length<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span><span class="tsd-signature-symbol"> = 0</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/alex-reinfoce/herm-studio-tool.js/blob/1a098c9/src/mockStream.ts#L8">mockStream.ts:8</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
|
16
|
+
<p>每次输出的字符数量</p>
|
|
17
|
+
</div></div></section><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-private"><a id="str" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagPrivate">Private</span> str<a href="#str" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">str<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> = ''</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/alex-reinfoce/herm-studio-tool.js/blob/1a098c9/src/mockStream.ts#L6">mockStream.ts:6</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
|
18
|
+
<p>需要输出的字符串</p>
|
|
19
|
+
</div></div></section></section><section class="tsd-panel-group tsd-member-group "><h2>Methods</h2><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class"><a id="start" class="tsd-anchor"></a><h3 class="tsd-anchor-link">start<a href="#start" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class"><li class="tsd-signature tsd-kind-icon">start<span class="tsd-signature-symbol">(</span>callback<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">(</span>data<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> => </span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">></span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/alex-reinfoce/herm-studio-tool.js/blob/1a098c9/src/mockStream.ts#L34">mockStream.ts:34</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
|
20
|
+
<p>开始模拟流式输出</p>
|
|
21
|
+
</div></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>callback: <span class="tsd-signature-symbol">(</span>data<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> => </span><span class="tsd-signature-type">void</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
|
|
22
|
+
<p>接收输出内容的回调函数</p>
|
|
23
|
+
</div></div><ul class="tsd-parameters"><li class="tsd-parameter-signature"><ul class="tsd-signatures tsd-kind-type-literal"><li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">(</span>data<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>data: <span class="tsd-signature-type">string</span></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">></span></h4><div><p>返回一个 Promise,当所有内容输出完成时,Promise 将解析为 true</p>
|
|
24
|
+
</div></li></ul></section></section></div><div class="col-4 col-menu menu-sticky-wrap menu-highlight"><nav class="tsd-navigation primary"><ul><li class=""><a href="../modules.html">Exports</a></li></ul></nav><nav class="tsd-navigation secondary menu-sticky"><ul><li class="current tsd-kind-class"><a href="MockStream.html" class="tsd-kind-icon">Mock<wbr/>Stream</a><ul><li class="tsd-kind-constructor tsd-parent-kind-class"><a href="MockStream.html#constructor" class="tsd-kind-icon">constructor</a></li><li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><a href="MockStream.html#duration" class="tsd-kind-icon">duration</a></li><li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><a href="MockStream.html#outputLength" class="tsd-kind-icon">output<wbr/>Length</a></li><li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><a href="MockStream.html#str" class="tsd-kind-icon">str</a></li><li class="tsd-kind-method tsd-parent-kind-class"><a href="MockStream.html#start" class="tsd-kind-icon">start</a></li></ul></li></ul></nav></div></div></div><footer class=""><div class="container"><h2>Legend</h2><div class="tsd-legend-group"><ul class="tsd-legend"><li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li><li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private property</span></li></ul></div><h2>Settings</h2><p>Theme <select id="theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></p></div></footer><div class="overlay"></div><script src="../assets/main.js"></script></body></html>
|
package/doc/index.html
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<!DOCTYPE html><html class="default"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>@celhive/tool.js</title><meta name="description" content="Documentation for @celhive/tool.js"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script async src="assets/search.js" id="search-script"></script></head><body><script>document.body.classList.add(localStorage.getItem("tsd-theme") || "os")</script><header><div class="tsd-page-toolbar"><div class="container"><div class="table-wrap"><div class="table-cell" id="tsd-search" data-base="."><div class="field"><label for="tsd-search-field" class="tsd-widget search no-caption">Search</label><input type="text" id="tsd-search-field"/></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">@celhive/tool.js</a></div><div class="table-cell" id="tsd-widgets"><div id="tsd-filter"><a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a><div class="tsd-filter-group"><div class="tsd-select" id="tsd-filter-visibility"><span class="tsd-select-label">All</span><ul class="tsd-select-list"><li data-value="public">Public</li><li data-value="protected">Public/Protected</li><li data-value="private" class="selected">All</li></ul></div> <input type="checkbox" id="tsd-filter-inherited" checked/><label class="tsd-widget" for="tsd-filter-inherited">Inherited</label><input type="checkbox" id="tsd-filter-externals" checked/><label class="tsd-widget" for="tsd-filter-externals">Externals</label></div></div><a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a></div></div></div></div><div class="tsd-page-title"><div class="container"><h1>@celhive/tool.js</h1></div></div></header><div class="container container-main"><div class="row"><div class="col-8 col-content"><div class="tsd-panel tsd-typography">
|
|
2
|
+
<a href="#herm-studiotooljs" id="herm-studiotooljs" style="color: inherit; text-decoration: none;">
|
|
3
|
+
<h1>@herm-studio/tool.js</h1>
|
|
4
|
+
</a>
|
|
5
|
+
|
|
6
|
+
<a href="#install" id="install" style="color: inherit; text-decoration: none;">
|
|
7
|
+
<h2>Install</h2>
|
|
8
|
+
</a>
|
|
9
|
+
<pre><code class="language-shell"><span class="hl-0">npm install @herm-studio/tool.js</span>
|
|
10
|
+
</code></pre>
|
|
11
|
+
</div></div><div class="col-4 col-menu menu-sticky-wrap menu-highlight"><nav class="tsd-navigation primary"><ul><li class="current"><a href="modules.html">Exports</a></li></ul></nav><nav class="tsd-navigation secondary menu-sticky"><ul><li class="tsd-kind-class"><a href="classes/MockStream.html" class="tsd-kind-icon">Mock<wbr/>Stream</a></li><li class="tsd-kind-function"><a href="modules.html#formatCitation" class="tsd-kind-icon">format<wbr/>Citation</a></li><li class="tsd-kind-function"><a href="modules.html#getPDFViewerUrl" class="tsd-kind-icon">getPDFViewer<wbr/>Url</a></li><li class="tsd-kind-function"><a href="modules.html#mendMarkdown" class="tsd-kind-icon">mend<wbr/>Markdown</a></li></ul></nav></div></div></div><footer class=""><div class="container"><h2>Legend</h2><div class="tsd-legend-group"><ul class="tsd-legend"><li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li><li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private property</span></li></ul></div><h2>Settings</h2><p>Theme <select id="theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></p></div></footer><div class="overlay"></div><script src="assets/main.js"></script></body></html>
|
package/doc/modules.html
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<!DOCTYPE html><html class="default"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>@celhive/tool.js</title><meta name="description" content="Documentation for @celhive/tool.js"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script async src="assets/search.js" id="search-script"></script></head><body><script>document.body.classList.add(localStorage.getItem("tsd-theme") || "os")</script><header><div class="tsd-page-toolbar"><div class="container"><div class="table-wrap"><div class="table-cell" id="tsd-search" data-base="."><div class="field"><label for="tsd-search-field" class="tsd-widget search no-caption">Search</label><input type="text" id="tsd-search-field"/></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">@celhive/tool.js</a></div><div class="table-cell" id="tsd-widgets"><div id="tsd-filter"><a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a><div class="tsd-filter-group"><div class="tsd-select" id="tsd-filter-visibility"><span class="tsd-select-label">All</span><ul class="tsd-select-list"><li data-value="public">Public</li><li data-value="protected">Public/Protected</li><li data-value="private" class="selected">All</li></ul></div> <input type="checkbox" id="tsd-filter-inherited" checked/><label class="tsd-widget" for="tsd-filter-inherited">Inherited</label><input type="checkbox" id="tsd-filter-externals" checked/><label class="tsd-widget" for="tsd-filter-externals">Externals</label></div></div><a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a></div></div></div></div><div class="tsd-page-title"><div class="container"><h1>@celhive/tool.js</h1></div></div></header><div class="container container-main"><div class="row"><div class="col-8 col-content"><section class="tsd-panel-group tsd-index-group"><h2>Index</h2><section class="tsd-panel tsd-index-panel"><div class="tsd-index-content"><section class="tsd-index-section "><h3>Classes</h3><ul class="tsd-index-list"><li class="tsd-kind-class"><a href="classes/MockStream.html" class="tsd-kind-icon">Mock<wbr/>Stream</a></li></ul></section><section class="tsd-index-section "><h3>Functions</h3><ul class="tsd-index-list"><li class="tsd-kind-function"><a href="modules.html#formatCitation" class="tsd-kind-icon">format<wbr/>Citation</a></li><li class="tsd-kind-function"><a href="modules.html#getPDFViewerUrl" class="tsd-kind-icon">getPDFViewer<wbr/>Url</a></li><li class="tsd-kind-function"><a href="modules.html#mendMarkdown" class="tsd-kind-icon">mend<wbr/>Markdown</a></li></ul></section></div></section></section><section class="tsd-panel-group tsd-member-group "><h2>Functions</h2><section class="tsd-panel tsd-member tsd-kind-function"><a id="formatCitation" class="tsd-anchor"></a><h3 class="tsd-anchor-link">format<wbr/>Citation<a href="#formatCitation" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-function"><li class="tsd-signature tsd-kind-icon">format<wbr/>Citation<span class="tsd-signature-symbol">(</span>str<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/alex-reinfoce/herm-studio-tool.js/blob/1a098c9/src/formatCitation.ts#L6">formatCitation.ts:6</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
|
2
|
+
<p>Formats the citation numbers in the given string.</p>
|
|
3
|
+
</div></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>str: <span class="tsd-signature-type">string</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
|
|
4
|
+
<p>The input string containing citation numbers.</p>
|
|
5
|
+
</div></div></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">string</span></h4><div><p>The formatted string with citation numbers wrapped in <span> elements.</p>
|
|
6
|
+
</div></li></ul></section><section class="tsd-panel tsd-member tsd-kind-function"><a id="getPDFViewerUrl" class="tsd-anchor"></a><h3 class="tsd-anchor-link">getPDFViewer<wbr/>Url<a href="#getPDFViewerUrl" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-function"><li class="tsd-signature tsd-kind-icon">getPDFViewer<wbr/>Url<span class="tsd-signature-symbol">(</span>previewPDFURL<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/alex-reinfoce/herm-studio-tool.js/blob/1a098c9/src/getPDFViewerUrl.ts#L1">getPDFViewerUrl.ts:1</a></li></ul></aside><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>previewPDFURL: <span class="tsd-signature-type">string</span></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">string</span></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-function"><a id="mendMarkdown" class="tsd-anchor"></a><h3 class="tsd-anchor-link">mend<wbr/>Markdown<a href="#mendMarkdown" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-function"><li class="tsd-signature tsd-kind-icon">mend<wbr/>Markdown<span class="tsd-signature-symbol">(</span>md<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/alex-reinfoce/herm-studio-tool.js/blob/1a098c9/src/mendMarkdown.ts#L6">mendMarkdown.ts:6</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
|
7
|
+
<p>修复 markdown 格式缺失问题</p>
|
|
8
|
+
</div></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>md: <span class="tsd-signature-type">string</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
|
|
9
|
+
<p>需要修复的 markdown 字符串</p>
|
|
10
|
+
</div></div></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">string</span></h4><div><p>string 修复后的 markdown 字符串</p>
|
|
11
|
+
</div></li></ul></section></section></div><div class="col-4 col-menu menu-sticky-wrap menu-highlight"><nav class="tsd-navigation primary"><ul><li class="current"><a href="modules.html">Exports</a></li></ul></nav><nav class="tsd-navigation secondary menu-sticky"><ul><li class="tsd-kind-class"><a href="classes/MockStream.html" class="tsd-kind-icon">Mock<wbr/>Stream</a></li><li class="tsd-kind-function"><a href="modules.html#formatCitation" class="tsd-kind-icon">format<wbr/>Citation</a></li><li class="tsd-kind-function"><a href="modules.html#getPDFViewerUrl" class="tsd-kind-icon">getPDFViewer<wbr/>Url</a></li><li class="tsd-kind-function"><a href="modules.html#mendMarkdown" class="tsd-kind-icon">mend<wbr/>Markdown</a></li></ul></nav></div></div></div><footer class=""><div class="container"><h2>Legend</h2><div class="tsd-legend-group"><ul class="tsd-legend"><li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li><li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private property</span></li></ul></div><h2>Settings</h2><p>Theme <select id="theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></p></div></footer><div class="overlay"></div><script src="assets/main.js"></script></body></html>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats the citation numbers in the given string.
|
|
3
|
+
* @param str The input string containing citation numbers.
|
|
4
|
+
* @returns The formatted string with citation numbers wrapped in <span> elements.
|
|
5
|
+
*/
|
|
6
|
+
export declare const formatCitation: (str: string) => string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatCitation = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Formats the citation numbers in the given string.
|
|
6
|
+
* @param str The input string containing citation numbers.
|
|
7
|
+
* @returns The formatted string with citation numbers wrapped in <span> elements.
|
|
8
|
+
*/
|
|
9
|
+
const formatCitation = (str) => {
|
|
10
|
+
let result = str.replace(/<span class="citation">[^0-9]*([0-9]+(?:,[0-9]+)*)[^0-9]*<\/?span>/g, (match, digits) => {
|
|
11
|
+
return digits
|
|
12
|
+
.split(',')
|
|
13
|
+
.map((num) => `<span class="citation">${num}</span>`)
|
|
14
|
+
.join('');
|
|
15
|
+
});
|
|
16
|
+
result = result.replace(/(#+ [^\n]+)\n(\s*<span class="citation">\d+<\/span>)/g, '$1 $2\n');
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
exports.formatCitation = formatCitation;
|
|
20
|
+
//# sourceMappingURL=formatCitation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatCitation.js","sourceRoot":"","sources":["../src/formatCitation.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACI,MAAM,cAAc,GAAG,CAAC,GAAW,EAAE,EAAE;IAC5C,IAAI,MAAM,GAAG,GAAG,CAAC,OAAO,CACtB,qEAAqE,EACrE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAChB,OAAO,MAAM;aACV,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,GAAW,EAAE,EAAE,CAAC,0BAA0B,GAAG,SAAS,CAAC;aAC5D,IAAI,CAAC,EAAE,CAAC,CAAC;IACd,CAAC,CACF,CAAC;IACF,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,uDAAuD,EAAE,SAAS,CAAC,CAAC;IAC5F,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAZW,QAAA,cAAc,kBAYzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getPDFViewerUrl: (previewPDFURL: string) => string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPDFViewerUrl = void 0;
|
|
4
|
+
const getPDFViewerUrl = (previewPDFURL) => {
|
|
5
|
+
const url = new URL('https://pdf-viewer.herm.studio');
|
|
6
|
+
url.searchParams.set('url', previewPDFURL);
|
|
7
|
+
return url.toString();
|
|
8
|
+
};
|
|
9
|
+
exports.getPDFViewerUrl = getPDFViewerUrl;
|
|
10
|
+
//# sourceMappingURL=getPDFViewerUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPDFViewerUrl.js","sourceRoot":"","sources":["../src/getPDFViewerUrl.ts"],"names":[],"mappings":";;;AAAO,MAAM,eAAe,GAAG,CAAC,aAAqB,EAAE,EAAE;IACvD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,gCAAgC,CAAC,CAAC;IACtD,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAC3C,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC,CAAA;AAJY,QAAA,eAAe,mBAI3B"}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./formatCitation"), exports);
|
|
18
|
+
__exportStar(require("./getPDFViewerUrl"), exports);
|
|
19
|
+
__exportStar(require("./mendMarkdown"), exports);
|
|
20
|
+
__exportStar(require("./mockStream"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC;AAChC,oDAAiC;AACjC,iDAA8B;AAC9B,+CAA4B"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mendMarkdown = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 修复 markdown 格式缺失问题
|
|
6
|
+
* @param md - 需要修复的 markdown 字符串
|
|
7
|
+
* @returns string 修复后的 markdown 字符串
|
|
8
|
+
*/
|
|
9
|
+
const mendMarkdown = (md) => {
|
|
10
|
+
const lines = md.split('\n');
|
|
11
|
+
let inCodeBlock = false;
|
|
12
|
+
const mendTitle = lines
|
|
13
|
+
.map((line) => {
|
|
14
|
+
// 检查是否是代码块的开始或结束
|
|
15
|
+
if (line.trim().startsWith('```')) {
|
|
16
|
+
inCodeBlock = !inCodeBlock; // 切换代码块状态
|
|
17
|
+
return line; // 直接返回代码块标记行
|
|
18
|
+
}
|
|
19
|
+
// 如果在代码块内,跳过处理
|
|
20
|
+
if (inCodeBlock) {
|
|
21
|
+
return line;
|
|
22
|
+
}
|
|
23
|
+
// 处理非代码块的标题行
|
|
24
|
+
const match = line.match(/^(\s*)(#+)(\s*)(.*)$/);
|
|
25
|
+
if (match) {
|
|
26
|
+
const [, leadingSpaces, hashes, spaces, content] = match;
|
|
27
|
+
if (hashes.length > 0 &&
|
|
28
|
+
spaces.length === 0 &&
|
|
29
|
+
!content.startsWith('#')) {
|
|
30
|
+
return `${leadingSpaces}${hashes} ${content}`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return line;
|
|
34
|
+
})
|
|
35
|
+
.join('\n');
|
|
36
|
+
const mendedTitle = mendTitle.trim();
|
|
37
|
+
const mendBold = mendedTitle.replace(/\*\*(.*?)\*\*/g, (match, p1) => {
|
|
38
|
+
return p1.includes('(') && p1.includes(')') ? `<b>${p1}</b>` : match;
|
|
39
|
+
});
|
|
40
|
+
return mendBold;
|
|
41
|
+
};
|
|
42
|
+
exports.mendMarkdown = mendMarkdown;
|
|
43
|
+
//# sourceMappingURL=mendMarkdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mendMarkdown.js","sourceRoot":"","sources":["../src/mendMarkdown.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACI,MAAM,YAAY,GAAG,CAAC,EAAU,EAAE,EAAE;IACzC,MAAM,KAAK,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7B,IAAI,WAAW,GAAG,KAAK,CAAC;IAExB,MAAM,SAAS,GAAG,KAAK;SACpB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACZ,iBAAiB;QACjB,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;YACjC,WAAW,GAAG,CAAC,WAAW,CAAC,CAAC,UAAU;YACtC,OAAO,IAAI,CAAC,CAAC,aAAa;SAC3B;QAED,eAAe;QACf,IAAI,WAAW,EAAE;YACf,OAAO,IAAI,CAAC;SACb;QAED,aAAa;QACb,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;QACjD,IAAI,KAAK,EAAE;YACT,MAAM,CAAC,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC;YACzD,IACE,MAAM,CAAC,MAAM,GAAG,CAAC;gBACjB,MAAM,CAAC,MAAM,KAAK,CAAC;gBACnB,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EACxB;gBACA,OAAO,GAAG,aAAa,GAAG,MAAM,IAAI,OAAO,EAAE,CAAC;aAC/C;SACF;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC;IAErC,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;QACnE,OAAO,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAxCW,QAAA,YAAY,gBAwCvB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 模拟 SSE 流式输出
|
|
3
|
+
*/
|
|
4
|
+
export declare class MockStream {
|
|
5
|
+
/** 需要输出的字符串 */
|
|
6
|
+
private str;
|
|
7
|
+
/** 每次输出的字符数量 */
|
|
8
|
+
private outputLength;
|
|
9
|
+
/** 每次输出的时间间隔(毫秒) */
|
|
10
|
+
private duration;
|
|
11
|
+
/**
|
|
12
|
+
* 创建一个模拟流式输出实例
|
|
13
|
+
* @param options - 配置选项
|
|
14
|
+
* @param options.str - 需要输出的字符串
|
|
15
|
+
* @param options.outputLength - 每次输出的字符数量(默认值:200)
|
|
16
|
+
* @param options.duration - 每次输出的时间间隔,单位毫秒(默认值:100)
|
|
17
|
+
*/
|
|
18
|
+
constructor(options: {
|
|
19
|
+
str: string;
|
|
20
|
+
outputLength?: number;
|
|
21
|
+
duration?: number;
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* 开始模拟流式输出
|
|
25
|
+
* @param callback - 接收输出内容的回调函数
|
|
26
|
+
* @returns 返回一个 Promise,当所有内容输出完成时,Promise 将解析为 true
|
|
27
|
+
*/
|
|
28
|
+
start(callback: (data: string) => void): Promise<boolean>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MockStream = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* 模拟 SSE 流式输出
|
|
15
|
+
*/
|
|
16
|
+
class MockStream {
|
|
17
|
+
/**
|
|
18
|
+
* 创建一个模拟流式输出实例
|
|
19
|
+
* @param options - 配置选项
|
|
20
|
+
* @param options.str - 需要输出的字符串
|
|
21
|
+
* @param options.outputLength - 每次输出的字符数量(默认值:200)
|
|
22
|
+
* @param options.duration - 每次输出的时间间隔,单位毫秒(默认值:100)
|
|
23
|
+
*/
|
|
24
|
+
constructor(options) {
|
|
25
|
+
/** 需要输出的字符串 */
|
|
26
|
+
this.str = '';
|
|
27
|
+
/** 每次输出的字符数量 */
|
|
28
|
+
this.outputLength = 0;
|
|
29
|
+
/** 每次输出的时间间隔(毫秒) */
|
|
30
|
+
this.duration = 0;
|
|
31
|
+
this.str = options.str;
|
|
32
|
+
this.outputLength = options.outputLength || 200;
|
|
33
|
+
this.duration = options.duration || 100;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 开始模拟流式输出
|
|
37
|
+
* @param callback - 接收输出内容的回调函数
|
|
38
|
+
* @returns 返回一个 Promise,当所有内容输出完成时,Promise 将解析为 true
|
|
39
|
+
*/
|
|
40
|
+
start(callback) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
let startIndex = 0;
|
|
44
|
+
while (startIndex < this.str.length) {
|
|
45
|
+
const endIndex = Math.min(startIndex + this.outputLength, this.str.length);
|
|
46
|
+
callback(this.str.slice(startIndex, endIndex));
|
|
47
|
+
startIndex = endIndex;
|
|
48
|
+
if (startIndex < this.str.length) {
|
|
49
|
+
yield new Promise(resolve => setTimeout(resolve, this.duration));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
resolve(true);
|
|
53
|
+
}));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.MockStream = MockStream;
|
|
58
|
+
//# sourceMappingURL=mockStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockStream.js","sourceRoot":"","sources":["../src/mockStream.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;GAEG;AACH,MAAa,UAAU;IAQrB;;;;;;OAMG;IACH,YAAY,OAIX;QAlBD,eAAe;QACP,QAAG,GAAW,EAAE,CAAA;QACxB,gBAAgB;QACR,iBAAY,GAAG,CAAC,CAAA;QACxB,oBAAoB;QACZ,aAAQ,GAAG,CAAC,CAAA;QAclB,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA;QACtB,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,GAAG,CAAA;QAC/C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,GAAG,CAAA;IACzC,CAAC;IAED;;;;OAIG;IACU,KAAK,CAAC,QAAgC;;YACjD,OAAO,IAAI,OAAO,CAAU,CAAO,OAAO,EAAE,EAAE;gBAC5C,IAAI,UAAU,GAAG,CAAC,CAAA;gBAClB,OAAO,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE;oBACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;oBAC1E,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAA;oBAC9C,UAAU,GAAG,QAAQ,CAAA;oBACrB,IAAI,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE;wBAChC,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAA;qBACjE;iBACF;gBACD,OAAO,CAAC,IAAI,CAAC,CAAA;YACf,CAAC,CAAA,CAAC,CAAA;QACJ,CAAC;KAAA;CACF;AA5CD,gCA4CC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@celhive/tool.js",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "npm run build && npm run doc && concurrently 'npm:watch-*'",
|
|
10
|
+
"build": "npm run test && tsc && npm run doc",
|
|
11
|
+
"test:watch": "vitest",
|
|
12
|
+
"test": "vitest --coverage run",
|
|
13
|
+
"doc": "typedoc",
|
|
14
|
+
"watch-doc": "onchange 'src/**/*.ts' './README.md' -- npm run doc",
|
|
15
|
+
"watch-preview": "live-server doc"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"concurrently": "^8.2.0",
|
|
19
|
+
"typedoc": "^0.22.12"
|
|
20
|
+
},
|
|
21
|
+
"main": "./lib/index.js",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@babel/preset-env": "^7.18.6",
|
|
24
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
25
|
+
"@vitest/coverage-istanbul": "^0.31.0",
|
|
26
|
+
"@vitest/ui": "^0.31.0",
|
|
27
|
+
"live-server": "^1.2.2",
|
|
28
|
+
"npm-run-all": "^4.1.5",
|
|
29
|
+
"onchange": "^7.1.0",
|
|
30
|
+
"typescript": "^4.5.1",
|
|
31
|
+
"vitest": "^0.31.0"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT"
|
|
34
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2016",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"forceConsistentCasingInFileNames": true,
|
|
7
|
+
"strict": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"outDir": "lib",
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"declaration": true,
|
|
12
|
+
"rootDir": "src"
|
|
13
|
+
},
|
|
14
|
+
"include": ["./src/**/*"],
|
|
15
|
+
"exclude": ["./src/test", "./lib/**/*"]
|
|
16
|
+
}
|