Global

Members

KNOWN_TOPICS

Description:
  • 已知主題對照表

    觀察者網無公開主題清單頁, 本表為手工整理(由首頁專題標籤與大頻道nav), 未涵蓋者請直接傳slug。 注意:同一中文名有多個slug時(如「财经」對應大頻道/economy與分頁欄目/CaiJing), 分頁欄目slug必須排在前面, 因lookupTopic採first-match; /economy等大頻道是「精選首頁」不分頁, /CaiJing等欄目才能以list_N.shtml翻頁全抓

Source:

已知主題對照表

觀察者網無公開主題清單頁, 本表為手工整理(由首頁專題標籤與大頻道nav), 未涵蓋者請直接傳slug。 注意:同一中文名有多個slug時(如「财经」對應大頻道/economy與分頁欄目/CaiJing), 分頁欄目slug必須排在前面, 因lookupTopic採first-match; /economy等大頻道是「精選首頁」不分頁, /CaiJing等欄目才能以list_N.shtml翻頁全抓

WDwdataHub

Description:
  • 資料下載中心

    各函數依資料來源分為三類: 綜合新聞(fetchRSS、fetchHackerNews、fetchAiNewsAggregator); 台股新聞與資料(fetchCnyes、fetchMoneydj、fetchStatementdog、fetchMops、fetchTwseStock、fetchTpexStock、fetchTwseMargin、fetchTpexMargin、fetchTwseT86、fetchTpex3insti、fetchTaifex、fetchTwDataHoliday); 中文評論網站(fetchAisixiang、fetchGuancha),此二者為物件,其內再含多個抓取函數

Source:

資料下載中心

各函數依資料來源分為三類: 綜合新聞(fetchRSS、fetchHackerNews、fetchAiNewsAggregator); 台股新聞與資料(fetchCnyes、fetchMoneydj、fetchStatementdog、fetchMops、fetchTwseStock、fetchTpexStock、fetchTwseMargin、fetchTpexMargin、fetchTwseT86、fetchTpex3insti、fetchTaifex、fetchTwDataHoliday); 中文評論網站(fetchAisixiang、fetchGuancha),此二者為物件,其內再含多個抓取函數

Example
詳見各fetch函數範例

fetchAisixiang

Description:
  • 抓取愛思想(aisixiang.com)

Source:

抓取愛思想(aisixiang.com)

Example
詳見fetchAuthorArticles、fetchKeywordArticles、fetchTitleArticles、fetchTopicArticles、fetchArticle範例

fetchGuancha

Description:
  • 抓取觀察者網(guancha.cn)

Source:

抓取觀察者網(guancha.cn)

Example
詳見fetchAuthorArticles、fetchTopicArticles、fetchArticle範例

Methods

assertTpexFieldShape(fields)

Description:
  • 驗證TPEX回傳fields是否仍為預期結構

    結構防呆(fail-loud), 驗證仍為「24欄、買進/賣出/買賣超循環×7」; 不符即拋錯(屬非暫時性錯誤故不重試), 避免API改版後靜默把外資的數字貼到投信頭上

Source:
Parameters:
Name Type Description
fields Array

輸入API回傳之欄名字串陣列

decodeEntities(str) → {String}

Description:
  • 解碼HTML實體

    支援具名實體(如&)、十進位數值實體(如')與十六進位數值實體(如'), 無對照之具名實體保留原字串不動

Source:
Example
import decodeEntities from './src/decodeEntities.mjs'

console.log(decodeEntities('a&bAB&unknown;'))
// => 'a&bAB&unknown;'
Parameters:
Name Type Description
str String

輸入含HTML實體之字串

Returns:

回傳解碼後字串,輸入非字串時回傳''

Type
String

extractAuthorFromContent(contentHtml) → {String|null}

Description:
  • 由正文第一段抽出作者署名

    觀察者網正文首段常見【文/观察者网 XXX】或【文/观察者网专栏作者 XXX,翻译/ XXX】

Source:
Parameters:
Name Type Description
contentHtml String

輸入正文區塊HTML字串

Returns:

回傳作者署名字串,無署名時回傳null

Type
String | null

extractDivContent(html, className) → {String|null}

Description:
  • 由HTML切出指定class之div內容

    以深度追蹤(depth tracking)配對div開閉標籤, 比僅取首個

可靠, 亦能正確切出0結果之空容器; 起始標籤採前綴比對, 故div上帶有其他屬性(如
)亦可命中

Source:
Example
import extractDivContent from './src/extractDivContent.mjs'

console.log(extractDivContent('<div class="ct">a<div>b</div>c</div>', 'ct'))
// => 'a<div>b</div>c'

console.log(extractDivContent('<div class="other">a</div>', 'ct'))
// => null
Parameters:
Name Type Description
html String

輸入HTML字串

className String

輸入div之class屬性字串

Returns:

回傳div內容字串,找不到起始標籤或標籤未閉合時回傳null

Type
String | null

extractHtmlTitle(html) → {String|null}

Description:
  • 由HTML抽出title標籤內容

Source:
Parameters:
Name Type Description
html String

輸入HTML字串

Returns:

回傳標題字串,無title標籤時回傳null

Type
String | null

extractPubTime(html) → {String|null}

Description:
  • 由HTML抽出發布時間

Source:
Parameters:
Name Type Description
html String

輸入HTML字串

Returns:

回傳發布時間字串,格式為'YYYY-MM-DD HH:mm:ss',無發布時間時回傳null

Type
String | null

extractTitle(html) → {String|null}

Description:
  • 由HTML抽出title標籤內容

Source:
Parameters:
Name Type Description
html String

輸入HTML字串

Returns:

回傳標題字串,無title標籤時回傳null

Type
String | null

(async) fetchAiNewsAggregator(optopt) → {Promise}

Description:
  • 抓取AI News Aggregator新聞

    由SuYxh/ai-news-aggregator專案之latest-24h.json取得近24小時AI新聞, 並轉為統一格式, 時間欄位一律轉為UTC+8之'YYYY-MM-DD HH:mm:ss'字串

Source:
Example
import fetchAiNewsAggregator from './src/fetchAiNewsAggregator.mjs'

let test = async () => {

    let rs = await fetchAiNewsAggregator()
    console.log(rs.length, rs[0])
    // => 120 { url: 'https://...', time: '2026-08-07 09:02:03', title: '...', description: '', from: 'Hacker News' }

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
url String <optional>
'https://raw.githubusercontent.com/SuYxh/ai-news-aggregator/refs/heads/main/data/latest-24h.json'

輸入來源網址字串,供測試或改指向鏡像時覆寫

timeout Integer <optional>
30000

輸入單次請求逾時毫秒整數,預設30000

maxRetries Integer <optional>
5

輸入最大重試次數整數,含初始共執行maxRetries+1次,預設5

baseDelayMs Integer <optional>
3000

輸入重試之線性退避基礎毫秒整數,預設3000

maxDelayMs Integer <optional>
15000

輸入重試之線性退避上限毫秒整數,預設15000

useShowLog Boolean <optional>
true

輸入是否顯示重試訊息布林值,預設true

Returns:

回傳Promise,resolve回傳新聞物件陣列,各物件為{url,time,title,description,from},抓取失敗時reject回傳錯誤物件

Type
Promise

(async) fetchAllListPages(slug, cfg) → {Promise}

Description:
  • 自動翻頁抓取全部列表頁

    逐頁抓//list_N.shtml, 適用於作者頁、欄目頁與主題集頁; 第1頁被302導向首頁代表slug不存在故拋錯, 後續頁被導向首頁或無新項目則視為到底

Source:
Parameters:
Name Type Description
slug String

輸入欄目或作者之slug字串

cfg Object

輸入已正規化之設定物件

Returns:

回傳Promise,resolve回傳{items,pages_fetched}

Type
Promise

(async) fetchAllSearchPages(buildUrl, parser, cfg) → {Promise}

Description:
  • 自動翻頁抓取全部列表頁

    由第1頁解析總頁數後逐頁抓取, 頁間延遲1秒; 該頁無新項目即停止翻頁, 並以MAX_PAGES為安全上限

Source:
Parameters:
Name Type Description
buildUrl function

輸入回傳指定頁碼網址之函數

parser function

輸入解析單頁HTML為項目陣列之函數

cfg Object

輸入已正規化之設定物件

Returns:

回傳Promise,resolve回傳{items,total_pages,pages_fetched}

Type
Promise

(async) fetchArticle(optopt) → {Promise}

Description:
  • 抓取愛思想單篇文章並轉為Markdown

    由article-content區塊切出正文轉Markdown, 並產生含title、source與created之YAML frontmatter; 標題會去除站名後綴, 例如「葛兆光:禅宗与中国文化_爱思想」轉為「葛兆光:禅宗与中国文化」

Source:
Example
import { fetchArticle } from './src/fetchAisixiang.mjs'

let test = async () => {

    let r = await fetchArticle({ aid: '146669' })
    console.log(r.status, r.title, r.chars)
    // => 'success' '葛兆光:禅宗与中国文化' 12345

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
aid String <optional>

輸入文章aid字串,與url擇一必填

url String <optional>

輸入文章網址字串,與aid擇一必填

baseUrl String <optional>
'https://www.aisixiang.com'

輸入網站根網址字串,供測試或改指向鏡像時覆寫

timeout Integer <optional>
30000

輸入單次請求逾時毫秒整數,預設30000

maxRetries Integer <optional>
5

輸入最大重試次數整數,預設5

pageDelayMs Integer <optional>
1000

輸入翻頁之頁間延遲毫秒整數,預設1000

maxPages Integer <optional>
50

輸入翻頁上限正整數,上限為50,預設50

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳結果物件{status,site,mode,url,title,chars,markdown},aid與url皆未給或解析失敗時reject回傳錯誤物件

Type
Promise

(async) fetchArticle(optopt) → {Promise}

Description:
  • 抓取觀察者網單篇文章並轉為Markdown

    由content all-txt區塊切出正文轉Markdown(保留圖片), 並產生含title、source、author、published與created之YAML frontmatter; 文章已下架時站方會302跳首頁, 本函數偵測此模式並回status為'error'且error為'article-not-found'

Source:
Example
import { fetchArticle } from './src/fetchGuancha.mjs'

let test = async () => {

    let r = await fetchArticle({ url: 'https://www.guancha.cn/internation/2026_04_29_815417.shtml' })
    console.log(r.status, r.title, r.chars)
    // => 'success' 'OPEC+宣布增產' 2345

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
url String

輸入文章網址字串

baseUrl String <optional>
'https://www.guancha.cn'

輸入網站根網址字串,供測試或改指向鏡像時覆寫

maxRetries Integer <optional>
5

輸入最大重試次數整數,預設5

pageDelayMs Integer <optional>
1000

輸入翻頁之頁間延遲毫秒整數,預設1000

maxPages Integer <optional>
50

輸入翻頁上限正整數,上限為50,預設50

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳結果物件{status,site,mode,url,title,author,published,chars,markdown},url非有效字串時reject回傳錯誤物件

Type
Promise

(async) fetchAuthorArticles(optopt) → {Promise}

Description:
  • 抓取愛思想指定作者之文章清單

    給name時先抓站方作者清單解析出slug再抓專欄頁(兩跳), 給slug則直接抓專欄頁; 查無此作者或該欄頁0篇時仍回status為'success'且count為0, 並以message說明, 以與抓取失敗區分

Source:
Example
import { fetchAuthorArticles } from './src/fetchAisixiang.mjs'

let test = async () => {

    let r = await fetchAuthorArticles({ name: '葛兆光' })
    console.log(r.status, r.count, r.resolved.slug)
    // => 'success' 123 'gezhaoguang'

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
name String <optional>

輸入作者中文名字串,與slug擇一必填

slug String <optional>

輸入作者slug字串,與name擇一必填

baseUrl String <optional>
'https://www.aisixiang.com'

輸入網站根網址字串,供測試或改指向鏡像時覆寫

timeout Integer <optional>
30000

輸入單次請求逾時毫秒整數,預設30000

maxRetries Integer <optional>
5

輸入最大重試次數整數,預設5

pageDelayMs Integer <optional>
1000

輸入翻頁之頁間延遲毫秒整數,預設1000

maxPages Integer <optional>
50

輸入翻頁上限正整數,上限為50,預設50

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳結果物件{status,site,mode,query,resolved,fetched_at,count,items},name與slug皆未給時reject回傳錯誤物件

Type
Promise

(async) fetchAuthorArticles(optopt) → {Promise}

Description:
  • 抓取觀察者網指定作者之文章清單

    給name時先抓首頁A-Z索引解析出slug再翻頁全抓(兩跳), 給slug則直接翻頁全抓; 查無此作者時仍回status為'success'且count為0, slug不存在(被302導向首頁)時回status為'error'

Source:
Example
import { fetchAuthorArticles } from './src/fetchGuancha.mjs'

let test = async () => {

    let r = await fetchAuthorArticles({ name: '安生' })
    console.log(r.status, r.count, r.resolved.slug)
    // => 'success' 120 'AnSheng'

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
name String <optional>

輸入作者中文名字串,與slug擇一必填

slug String <optional>

輸入作者slug字串,與name擇一必填

baseUrl String <optional>
'https://www.guancha.cn'

輸入網站根網址字串,供測試或改指向鏡像時覆寫

maxRetries Integer <optional>
5

輸入最大重試次數整數,預設5

pageDelayMs Integer <optional>
1000

輸入翻頁之頁間延遲毫秒整數,預設1000

maxPages Integer <optional>
50

輸入翻頁上限正整數,上限為50,預設50

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳結果物件{status,site,mode,query,resolved,fetched_at,count,items},name與slug皆未給時reject回傳錯誤物件

Type
Promise

(async) fetchAuthorsList(optopt) → {Promise}

Description:
  • 抓取愛思想專欄作者清單

    即時解析/thinktank/頁面, 回傳約960位專欄作者之slug與中文名

Source:
Example
import { fetchAuthorsList } from './src/fetchAisixiang.mjs'

let test = async () => {

    let rs = await fetchAuthorsList()
    console.log(rs.length, rs[0])
    // => 963 { slug: 'gezhaoguang', name: '葛兆光' }

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
baseUrl String <optional>
'https://www.aisixiang.com'

輸入網站根網址字串,供測試或改指向鏡像時覆寫

timeout Integer <optional>
30000

輸入單次請求逾時毫秒整數,預設30000

maxRetries Integer <optional>
5

輸入最大重試次數整數,預設5

pageDelayMs Integer <optional>
1000

輸入翻頁之頁間延遲毫秒整數,預設1000

maxPages Integer <optional>
50

輸入翻頁上限正整數,上限為50,預設50

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳作者物件陣列,各物件為{slug,name}

Type
Promise

(async) fetchAuthorsList(optopt) → {Promise}

Description:
  • 抓取觀察者網作者索引

    由首頁底部A-Z索引解析作者中文名與slug對照, 注意首頁索引僅含部分作者

Source:
Example
import { fetchAuthorsList } from './src/fetchGuancha.mjs'

let test = async () => {

    let rs = await fetchAuthorsList()
    console.log(rs.length, rs[0])
    // => 636 { slug: 'AnSheng', name: '安生', letter: 'A' }

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
baseUrl String <optional>
'https://www.guancha.cn'

輸入網站根網址字串,供測試或改指向鏡像時覆寫

maxRetries Integer <optional>
5

輸入最大重試次數整數,預設5

pageDelayMs Integer <optional>
1000

輸入翻頁之頁間延遲毫秒整數,預設1000

maxPages Integer <optional>
50

輸入翻頁上限正整數,上限為50,預設50

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳作者物件陣列,各物件為{slug,name,letter}

Type
Promise

(async) fetchCnyes(optopt) → {Promise}

Description:
  • 抓取鉅亨網台股新聞

    逐頁抓取鉅亨網tw_stock分類新聞直至達到targetTotal或無更多資料, 頁間預設間隔500毫秒以降低限流風險; 時間欄位一律轉為UTC+8之'YYYY-MM-DD HH:mm:ss'字串, 單筆publishAt缺漏或異常時該筆time退回空字串並記錄, 不影響其餘新聞

Source:
Example
import fetchCnyes from './src/fetchCnyes.mjs'

let test = async () => {

    let rs = await fetchCnyes({ targetTotal: 30 })
    console.log(rs.length, rs[0])
    // => 30 { time: '2026-08-07 09:02:03', title: '...', link: 'https://news.cnyes.com/news/id/1234567' }

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
url String <optional>
'https://api.cnyes.com/media/api/v1/newslist/category/tw_stock'

輸入新聞列表API網址字串,供測試或改指向鏡像時覆寫

targetTotal Integer <optional>
100

輸入目標新聞則數正整數,預設100

pageLimit Integer <optional>
30

輸入單頁請求則數正整數,預設30

daysBack Integer <optional>
10

輸入回溯天數正整數,預設10

pageDelayMs Integer <optional>
500

輸入頁間延遲毫秒整數,預設500

timeout Integer <optional>
30000

輸入單次請求逾時毫秒整數,預設30000

maxRetries Integer <optional>
10

輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10

baseDelayMs Integer <optional>
5000

輸入重試之線性退避基礎毫秒整數,預設5000

maxDelayMs Integer <optional>
30000

輸入重試之線性退避上限毫秒整數,預設30000

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳新聞物件陣列,各物件為{time,title,link},抓取失敗時reject回傳錯誤物件

Type
Promise

(async) fetchFuturesData(dateSlash, cfg) → {Promise}

Description:
  • 抓取台指期行情

Source:
Parameters:
Name Type Description
dateSlash String

輸入日期YYYY/MM/DD字串

cfg Object

輸入已正規化之設定物件

Returns:

回傳Promise,resolve回傳近月合約行情物件

Type
Promise

(async) fetchHackerNews(limitopt, optopt) → {Promise}

Description:
  • 抓取Hacker News最新文章

    先取newstories.json之ID清單, 再分批(每批10筆)取各篇詳情並轉為統一格式; 分批採Promise.allSettled, 單篇重試耗盡不會拖垮同批其他已成功文章; 僅保留type為story者, 無外部連結時以Hacker News站內討論頁網址替代

Source:
Example
import fetchHackerNews from './src/fetchHackerNews.mjs'

let test = async () => {

    let rs = await fetchHackerNews(5)
    console.log(rs.length, rs[0])
    // => 5 { url: 'https://...', time: '2026-08-07 09:02:03', title: '...', description: '', from: 'Hacker News' }

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
limit Integer <optional>
30

輸入取回文章數量正整數,非正整數時改用預設值,預設30

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
apiBase String <optional>
'https://hacker-news.firebaseio.com/v0'

輸入API根網址字串,供測試或改指向鏡像時覆寫

timeout Integer <optional>
30000

輸入單次請求逾時毫秒整數,預設30000

maxRetries Integer <optional>
5

輸入最大重試次數整數,含初始共執行maxRetries+1次,預設5

baseDelayMs Integer <optional>
3000

輸入重試之線性退避基礎毫秒整數,預設3000

maxDelayMs Integer <optional>
15000

輸入重試之線性退避上限毫秒整數,預設15000

useShowLog Boolean <optional>
true

輸入是否顯示重試訊息布林值,預設true

Returns:

回傳Promise,resolve回傳文章物件陣列,各物件為{url,time,title,description,from},抓取ID清單失敗時reject回傳錯誤物件

Type
Promise

(async) fetchHtml(url, cfg) → {Promise}

Description:
  • 抓取網頁原始HTML

    委派w-fetch-web之fetchWebByCurl(其本身內建重試與線性退避), 失敗時拋出帶reason與httpCode之錯誤

Source:
Parameters:
Name Type Description
url String

輸入待抓取網址字串

cfg Object

輸入已正規化之設定物件

Returns:

回傳Promise,resolve回傳原始HTML字串

Type
Promise

(async) fetchInstitutionalData(dateSlash, cfg) → {Promise}

Description:
  • 抓取三大法人期貨未平倉

Source:
Parameters:
Name Type Description
dateSlash String

輸入日期YYYY/MM/DD字串

cfg Object

輸入已正規化之設定物件

Returns:

回傳Promise,resolve回傳以foreign、trust、dealers為key之未平倉物件

Type
Promise

(async) fetchKeywordArticles(keyword, optopt) → {Promise}

Description:
  • 抓取愛思想指定關鍵字tag之文章清單

    走站方keywords搜尋並自動翻頁全抓; 站方搜尋只認簡體, 呼叫端負責簡體化

Source:
Example
import { fetchKeywordArticles } from './src/fetchAisixiang.mjs'

let test = async () => {

    let r = await fetchKeywordArticles('老庄')
    console.log(r.status, r.count)
    // => 'success' 42

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
keyword String

輸入關鍵字字串

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
baseUrl String <optional>
'https://www.aisixiang.com'

輸入網站根網址字串,供測試或改指向鏡像時覆寫

timeout Integer <optional>
30000

輸入單次請求逾時毫秒整數,預設30000

maxRetries Integer <optional>
5

輸入最大重試次數整數,預設5

pageDelayMs Integer <optional>
1000

輸入翻頁之頁間延遲毫秒整數,預設1000

maxPages Integer <optional>
50

輸入翻頁上限正整數,上限為50,預設50

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳結果物件{status,site,mode,query,resolved,fetched_at,count,items},keyword非有效字串時reject回傳錯誤物件

Type
Promise

(async) fetchKeywordArticles(keyword, optopt) → {Promise}

Description:
  • 抓取觀察者網指定關鍵字之文章清單

    站方搜尋API(s.guancha.cn/main/search-v2)由sojson.v4混淆並走MD5簽名, 純curl路徑無法支援, 故本函數一律回status為'error'且error為'unsupported-by-curl', 並於message建議改用作者或主題slug

Source:
Example
import { fetchKeywordArticles } from './src/fetchGuancha.mjs'

let test = async () => {

    let r = await fetchKeywordArticles('人工智能')
    console.log(r.status, r.error)
    // => 'error' 'unsupported-by-curl'

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
keyword String

輸入關鍵字字串

opt Object <optional>
{}

輸入設定物件,預設{}

Returns:

回傳Promise,resolve回傳結果物件{status,site,mode,query,fetched_at,error,message},keyword非有效字串時reject回傳錯誤物件

Type
Promise

(async) fetchMoneydj(optopt) → {Promise}

Description:
  • 抓取MoneyDJ台股新聞

    逐頁抓取MoneyDJ台股新聞(MB06)列表, 頁間隨機延遲1至3秒以降低被封鎖風險; 單頁抓取失敗(重試耗盡)時記錄並跳過該頁, 不中斷整體抓取; 全部頁面皆0筆時拋出錯誤

Source:
Example
import fetchMoneydj from './src/fetchMoneydj.mjs'

let test = async () => {

    let rs = await fetchMoneydj({ totalPages: 2 })
    console.log(rs.length, rs[0])
    // => 60 { time: '08/07 09:02', title: '...', link: 'https://www.moneydj.com/kmdj/news/...' }

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
baseUrl String <optional>
'https://www.moneydj.com/kmdj/news/newsreallist.aspx?a=mb06&index1='

輸入列表頁網址前綴字串,頁碼會直接串接於後,供測試或改指向鏡像時覆寫

totalPages Integer <optional>
50

輸入要抓取的頁數正整數,預設50

timeout Integer <optional>
30000

輸入單次請求逾時毫秒整數,預設30000

maxRetries Integer <optional>
10

輸入每頁最大重試次數整數,含初始共執行maxRetries+1次,預設10

baseDelayMs Integer <optional>
5000

輸入重試基礎延遲毫秒整數,預設5000

maxDelayMs Integer <optional>
30000

輸入重試最大延遲毫秒整數,預設30000

pageDelayMs Integer <optional>

輸入頁間延遲毫秒整數,未給時採隨機1000至3000毫秒

onPageDone function <optional>

輸入每頁完成時之回呼函數,傳入(pageIndex,itemCount,totalPages)

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳新聞物件陣列,各物件為{time,title,link},抓取到0筆時reject回傳錯誤物件

Type
Promise

(async) fetchMops(optopt) → {Promise}

Description:
  • 抓取公開資訊觀測站(MOPS)今日重大訊息

    以playwright啟動本機Chrome(channel為'chrome', 可由環境變數CHROME_PATH指定執行檔)開啟MOPS重大訊息頁, 再於頁面context內逐一查詢上市、上櫃、興櫃與公開發行之今日重大訊息; 單一市場別失敗時記錄於該筆之error並續抓其餘市場別, 由hasError告知是否有失敗

Source:
Example
import fetchMops from './src/fetchMops.mjs'

let test = async () => {

    let r = await fetchMops()
    console.log(r.hasError, r.results.length, r.results[0].market)
    // => false 4 '上市'

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
pageUrl String <optional>
'https://mops.twse.com.tw/mops/#/web/t146sb10'

輸入MOPS重大訊息頁網址字串,供測試或改指向鏡像時覆寫

apiUrl String <optional>
'https://mops.twse.com.tw/mops/api/t146sb10'

輸入MOPS查詢API網址字串,供測試或改指向鏡像時覆寫

maxRetries Integer <optional>
10

輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳結果物件{results,hasError},results各筆為{market,marketKind,data,error,timestamp},瀏覽器啟動失敗時reject回傳錯誤物件

Type
Promise

(async) fetchOnce(url, cfg) → {Promise}

Description:
  • 單次抓取, HTTP非2xx時拋出帶statusCode之錯誤

Source:
Parameters:
Name Type Description
url String

輸入待抓取網址字串

cfg Object

輸入已正規化之設定物件

Returns:

回傳Promise,resolve回傳解析後資料

Type
Promise

(async) fetchPCRatio(dateSlash, cfg) → {Promise}

Description:
  • 抓取Put/Call Ratio

Source:
Parameters:
Name Type Description
dateSlash String

輸入日期YYYY/MM/DD字串

cfg Object

輸入已正規化之設定物件

Returns:

回傳Promise,resolve回傳Put/Call Ratio物件

Type
Promise

(async) fetchRSS(rssUrl, optopt) → {Promise}

Description:
  • 抓取RSS訂閱源

    支援RSS與Atom, 並轉為統一格式, 時間欄位一律轉為UTC+8之'YYYY-MM-DD HH:mm:ss'字串; 因YouTube等站台之RSS會回傳暫時性404, 故404亦納入重試範圍(僅fetch模式)。

    部分站台(如以TLS指紋阻擋非瀏覽器用戶端者)對node內建fetch回403、對curl回200, 此時可指定opt.method為'curl'改走系統curl, 或'auto'先curl失敗再退回fetch; curl模式需系統PATH內有curl, 且重試退避由w-fetch-web內建(3至15秒線性), opt之baseDelayMs、maxDelayMs與retryStatus於curl模式不生效, 極短之feed(小於100字元)會被curl模式判為empty-response

Source:
Example
import fetchRSS from './src/fetchRSS.mjs'

let test = async () => {

    let rs = await fetchRSS('https://www.ptt.cc/atom/Gossiping.xml')
    console.log(rs.length, rs[0])
    // => 20 { url: 'https://...', time: '2026-08-07 09:02:03', title: '...', description: '...', from: '...' }

    //擋node fetch之站台改走curl, 並取feed內嵌全文
    let rs2 = await fetchRSS('https://alphaarchitect.com/feed', { method: 'curl', withContent: true })
    console.log(rs2.length, rs2[0].content.length)
    // => 5 2093

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
rssUrl String

輸入RSS網址字串,須為http或https

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
method String <optional>
'fetch'

輸入抓取方式字串,可為'fetch'(node內建fetch)、'curl'(系統curl)、'auto'(curl優先失敗退回fetch),預設'fetch'

withContent Boolean <optional>
false

輸入是否於各項目附加content欄布林值,true時依content:encoded、content、summary、description之優先序取feed內嵌全文並去除HTML標籤與實體,預設false

timeout Integer <optional>
30000

輸入單次請求逾時毫秒整數,預設30000

maxRetries Integer <optional>
5

輸入最大重試次數整數,含初始共執行maxRetries+1次,預設5

baseDelayMs Integer <optional>
3000

輸入重試之線性退避基礎毫秒整數(僅fetch模式生效),預設3000

maxDelayMs Integer <optional>
15000

輸入重試之線性退避上限毫秒整數(僅fetch模式生效),預設15000

useShowLog Boolean <optional>
true

輸入是否顯示重試訊息布林值,預設true

Returns:

回傳Promise,resolve回傳項目物件陣列,各物件為{url,time,title,description,from},withContent為true時另含content欄,網址無效或抓取失敗時reject回傳錯誤物件

Type
Promise

(async) fetchStatementdog(optopt) → {Promise}

Description:
  • 抓取財報狗最新新聞

    以cheerio解析財報狗最新新聞頁, 主要selector失效時自動改用通用結構備援selector; 相對路徑連結會補上來源網址之origin, 抓取到0筆時視為版型改變而拋出錯誤(不重試)

Source:
Example
import fetchStatementdog from './src/fetchStatementdog.mjs'

let test = async () => {

    let rs = await fetchStatementdog()
    console.log(rs.length, rs[0])
    // => 30 { time: '2026-08-07', title: '...', link: 'https://statementdog.com/news/...' }

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
url String <optional>
'https://statementdog.com/news/latest'

輸入新聞頁網址字串,供測試或改指向鏡像時覆寫

timeout Integer <optional>
30000

輸入單次請求逾時毫秒整數,預設30000

maxRetries Integer <optional>
10

輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10

baseDelayMs Integer <optional>
5000

輸入重試之線性退避基礎毫秒整數,預設5000

maxDelayMs Integer <optional>
30000

輸入重試之線性退避上限毫秒整數,預設30000

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳新聞物件陣列,各物件為{time,title,link},抓取失敗或解析到0筆時reject回傳錯誤物件

Type
Promise

(async) fetchTaifex(dateStr, optopt) → {Promise}

Description:
  • 抓取期交所(TAIFEX)台指期相關資料

    序列抓取台指期行情、三大法人期貨未平倉與Put/Call Ratio共三支CSV(每支間隔1秒以降低限流風險); 期交所CSV為Big5(MS950)編碼, 由本函數解碼; 三支之中任一支失敗僅記錄於errors, 三支全失敗才拋錯

Source:
Example
import fetchTaifex from './src/fetchTaifex.mjs'

let test = async () => {

    let r = await fetchTaifex('20260807')
    console.log(r.date, r.futures.tx.close, r.pcRatio.ratio, r.errors)
    // => '20260807' 23456 108.5 []

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
dateStr String

輸入日期YYYYMMDD字串

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
baseUrl String <optional>
'https://www.taifex.com.tw'

輸入期交所根網址字串,供測試或改指向鏡像時覆寫

timeout Integer <optional>
15000

輸入單次請求逾時毫秒整數,預設15000

maxRetries Integer <optional>
10

輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10

baseDelayMs Integer <optional>
5000

輸入重試之線性退避基礎毫秒整數,預設5000

maxDelayMs Integer <optional>
30000

輸入重試之線性退避上限毫秒整數,預設30000

interRequestDelayMs Integer <optional>
1000

輸入三支CSV之間隔毫秒整數,預設1000

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳結果物件{date,futures,institutional,pcRatio,errors},日期無效或三支資料全失敗時reject回傳錯誤物件

Type
Promise

(async) fetchTargetWithRetry(page, target, cfg) → {Promise}

Description:
  • 於瀏覽器頁面內以fetch呼叫MOPS查詢API並自動重試

    需於MOPS頁面context內發送請求(同源且帶站方cookie), 故採page.evaluate而非node端直接請求; 重試條件為HTTP 5xx、403、429或網路錯誤, application-level錯誤(如MOPS code 500)屬非暫時性故不重試

Source:
Parameters:
Name Type Description
page Object

輸入playwright之page物件

target Object

輸入目標物件,內含name、marketKind、url與payload

cfg Object

輸入已正規化之設定物件

Returns:

回傳Promise,resolve回傳{json,raw}或{error,retryable}

Type
Promise

(async) fetchTitleArticles(keyword, optopt) → {Promise}

Description:
  • 抓取愛思想指定標題關鍵字之文章清單

    走站方title搜尋並自動翻頁全抓; 站方搜尋只認簡體, 呼叫端負責簡體化

Source:
Example
import { fetchTitleArticles } from './src/fetchAisixiang.mjs'

let test = async () => {

    let r = await fetchTitleArticles('禅宗与中国文化')
    console.log(r.status, r.count)
    // => 'success' 3

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
keyword String

輸入標題關鍵字字串

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
baseUrl String <optional>
'https://www.aisixiang.com'

輸入網站根網址字串,供測試或改指向鏡像時覆寫

timeout Integer <optional>
30000

輸入單次請求逾時毫秒整數,預設30000

maxRetries Integer <optional>
5

輸入最大重試次數整數,預設5

pageDelayMs Integer <optional>
1000

輸入翻頁之頁間延遲毫秒整數,預設1000

maxPages Integer <optional>
50

輸入翻頁上限正整數,上限為50,預設50

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳結果物件{status,site,mode,query,resolved,fetched_at,count,items},keyword非有效字串時reject回傳錯誤物件

Type
Promise

(async) fetchTitleArticles(keyword, optopt) → {Promise}

Description:
  • 抓取觀察者網指定標題關鍵字之文章清單

    站方無分「標題」與「全文」搜尋(兩者同源), 與fetchKeywordArticles同因簽名混淆而不可用, 故本函數一律回status為'error'且error為'unsupported-by-curl'

Source:
Example
import { fetchTitleArticles } from './src/fetchGuancha.mjs'

let test = async () => {

    let r = await fetchTitleArticles('人工智能')
    console.log(r.status, r.error)
    // => 'error' 'unsupported-by-curl'

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
keyword String

輸入標題關鍵字字串

opt Object <optional>
{}

輸入設定物件,預設{}

Returns:

回傳Promise,resolve回傳結果物件{status,site,mode,query,fetched_at,error,message},keyword非有效字串時reject回傳錯誤物件

Type
Promise

(async) fetchTopicArticles(optopt) → {Promise}

Description:
  • 抓取愛思想指定策展主題之文章清單

    給keyword時先抓站方主題清單解析出id再抓主題頁(兩跳), 給id則直接抓主題頁並自動翻頁全抓; 查無此主題時仍回status為'success'且count為0, 並以message建議改用fetchKeywordArticles(本函數不自動轉向)

Source:
Example
import { fetchTopicArticles } from './src/fetchAisixiang.mjs'

let test = async () => {

    let r = await fetchTopicArticles({ keyword: '大数据' })
    console.log(r.status, r.count, r.resolved.id)
    // => 'success' 60 '301'

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyword String <optional>

輸入主題名稱字串,與id擇一必填

id String <optional>

輸入主題id字串,與keyword擇一必填

baseUrl String <optional>
'https://www.aisixiang.com'

輸入網站根網址字串,供測試或改指向鏡像時覆寫

timeout Integer <optional>
30000

輸入單次請求逾時毫秒整數,預設30000

maxRetries Integer <optional>
5

輸入最大重試次數整數,預設5

pageDelayMs Integer <optional>
1000

輸入翻頁之頁間延遲毫秒整數,預設1000

maxPages Integer <optional>
50

輸入翻頁上限正整數,上限為50,預設50

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳結果物件{status,site,mode,query,resolved,fetched_at,count,items},keyword與id皆未給時reject回傳錯誤物件

Type
Promise

(async) fetchTopicArticles(optopt) → {Promise}

Description:
  • 抓取觀察者網指定主題之文章清單

    給name時先查KNOWN_TOPICS對照表解析出slug再翻頁全抓, 給slug則直接翻頁全抓; 主題不在對照表時fail-fast回status為'error'且error為'topic-not-in-table'

Source:
Example
import { fetchTopicArticles } from './src/fetchGuancha.mjs'

let test = async () => {

    let r = await fetchTopicArticles({ name: '财经' })
    console.log(r.status, r.resolved.slug, r.count)
    // => 'success' 'CaiJing' 300

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
name String <optional>

輸入主題中文名字串,與slug擇一必填

slug String <optional>

輸入主題slug字串,與name擇一必填

baseUrl String <optional>
'https://www.guancha.cn'

輸入網站根網址字串,供測試或改指向鏡像時覆寫

maxRetries Integer <optional>
5

輸入最大重試次數整數,預設5

pageDelayMs Integer <optional>
1000

輸入翻頁之頁間延遲毫秒整數,預設1000

maxPages Integer <optional>
50

輸入翻頁上限正整數,上限為50,預設50

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳結果物件{status,site,mode,query,resolved,fetched_at,count,items},name與slug皆未給時reject回傳錯誤物件

Type
Promise

(async) fetchTopicsList(optopt) → {Promise}

Description:
  • 抓取愛思想策展主題清單

    即時解析/zhuanti/頁面, 回傳約800個策展主題之id、名稱與分類(学科、事件、人物)

Source:
Example
import { fetchTopicsList } from './src/fetchAisixiang.mjs'

let test = async () => {

    let rs = await fetchTopicsList()
    console.log(rs.length, rs[0])
    // => 803 { id: '301', name: '大数据', category: '学科' }

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
baseUrl String <optional>
'https://www.aisixiang.com'

輸入網站根網址字串,供測試或改指向鏡像時覆寫

timeout Integer <optional>
30000

輸入單次請求逾時毫秒整數,預設30000

maxRetries Integer <optional>
5

輸入最大重試次數整數,預設5

pageDelayMs Integer <optional>
1000

輸入翻頁之頁間延遲毫秒整數,預設1000

maxPages Integer <optional>
50

輸入翻頁上限正整數,上限為50,預設50

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳主題物件陣列,各物件為{id,name,category}

Type
Promise

(async) fetchTpex3insti(dateStr, stockCodesopt, optopt) → {Promise}

Description:
  • 抓取櫃買中心(TPEX)上櫃三大法人買賣超

    抓取指定日之上櫃三大法人買賣超(含自營商避險), 因API之fields為裸欄名且重複, 故以固定位置對應語意欄名; 套位置對應前先驗證欄位結構, 不符即拋錯以避免產生錯置之財務資料

Source:
Example
import fetchTpex3insti from './src/fetchTpex3insti.mjs'

let test = async () => {

    let r = await fetchTpex3insti('20260807', ['6488'])
    console.log(r.source, r.data.length, r.data[0]['代號'])
    // => 'tpex' 1 '6488'

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
dateStr String

輸入日期YYYYMMDD字串

stockCodes Array <optional>

輸入股票代號字串陣列,省略或空陣列表示全市場

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
baseUrl String <optional>
'https://www.tpex.org.tw'

輸入櫃買中心根網址字串,供測試或改指向鏡像時覆寫

timeout Integer <optional>
15000

輸入單次請求逾時毫秒整數,預設15000

maxRetries Integer <optional>
10

輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10

baseDelayMs Integer <optional>
5000

輸入重試之線性退避基礎毫秒整數,預設5000

maxDelayMs Integer <optional>
30000

輸入重試之線性退避上限毫秒整數,預設30000

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳結果物件{source,date,data},日期無效、無資料或欄位結構不符時reject回傳錯誤物件

Type
Promise

(async) fetchTpexMargin(dateStr, stockCodesopt, optopt) → {Promise}

Description:
  • 抓取櫃買中心(TPEX)上櫃融資融券

    抓取指定日之上櫃個股融資融券餘額並轉為結構化資料, 可指定股票代號陣列過濾; 選表以欄位同時含「資餘額」與「券餘額」比對, 失敗則退而取第一張有資料表, 並鎖定index6與index14兩錨點欄位驗證佈局, 不符即fail-loud, 避免固定index解析在API改版後靜默產生錯誤資料

Source:
Example
import fetchTpexMargin from './src/fetchTpexMargin.mjs'

let test = async () => {

    let r = await fetchTpexMargin('20260807', ['6488'])
    console.log(r.source, r.count, r.data[0].code)
    // => 'tpex_margin' 1 '6488'

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
dateStr String

輸入日期YYYYMMDD字串

stockCodes Array <optional>

輸入股票代號字串陣列,省略或空陣列表示全市場

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
baseUrl String <optional>
'https://www.tpex.org.tw'

輸入櫃買中心根網址字串,供測試或改指向鏡像時覆寫

timeout Integer <optional>
15000

輸入單次請求逾時毫秒整數,預設15000

maxRetries Integer <optional>
10

輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10

baseDelayMs Integer <optional>
5000

輸入重試之線性退避基礎毫秒整數,預設5000

maxDelayMs Integer <optional>
30000

輸入重試之線性退避上限毫秒整數,預設30000

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳結果物件{source,date,count,data},日期無效、無資料、欄位佈局不符或指定個股查無資料時reject回傳錯誤物件

Type
Promise

(async) fetchTpexStock(dateStr, stockCodesopt, optopt) → {Promise}

Description:
  • 抓取櫃買中心(TPEX)上櫃股價

    抓取指定日之上櫃股票行情, 可指定股票代號陣列過濾; 選表優先以標題含「行情」比對, 避免未來新增其他資料表時誤抓, 並驗證欄數以避免API改版後靜默讀錯欄

Source:
Example
import fetchTpexStock from './src/fetchTpexStock.mjs'

let test = async () => {

    let r = await fetchTpexStock('20260807', ['6488'])
    console.log(r.source, r.count)
    // => 'tpex' 1

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
dateStr String

輸入日期YYYYMMDD字串

stockCodes Array <optional>

輸入股票代號字串陣列,例如['6499','6610'],省略或空陣列表示全市場

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
baseUrl String <optional>
'https://www.tpex.org.tw'

輸入櫃買中心根網址字串,供測試或改指向鏡像時覆寫

timeout Integer <optional>
15000

輸入單次請求逾時毫秒整數,預設15000

maxRetries Integer <optional>
10

輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10

baseDelayMs Integer <optional>
5000

輸入重試之線性退避基礎毫秒整數,預設5000

maxDelayMs Integer <optional>
30000

輸入重試之線性退避上限毫秒整數,預設30000

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳結果物件{source,date,count,data},日期無效、無資料或指定個股查無資料時reject回傳錯誤物件

Type
Promise

(async) fetchTwDataHoliday(checkDateopt, optopt) → {Promise}

Description:
  • 抓取台灣證券市場休市日期

    由證交所開放資料平台取得當年度休市日期清單, 排除交易日標記與結算作業日, 並依日期去重與排序; 給定checkDate時另回傳該日是否為休市日

Source:
Example
import fetchTwDataHoliday from './src/fetchTwDataHoliday.mjs'

let test = async () => {

    let r = await fetchTwDataHoliday('20260101')
    console.log(r.dataYear, r.totalHolidays, r.isHoliday, r.holidayName)
    // => '2026' 15 true '中華民國開國紀念日'

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
checkDate String <optional>

輸入待查詢日期YYYYMMDD字串,非合法YYYYMMDD時略過單日比對

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
url String <optional>
'https://openapi.twse.com.tw/v1/holidaySchedule/holidaySchedule'

輸入API網址字串,供測試或改指向鏡像時覆寫

timeout Integer <optional>
30000

輸入單次請求逾時毫秒整數,預設30000

maxRetries Integer <optional>
10

輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10

baseDelayMs Integer <optional>
5000

輸入重試之線性退避基礎毫秒整數,預設5000

maxDelayMs Integer <optional>
30000

輸入重試之線性退避上限毫秒整數,預設30000

useShowLog Boolean <optional>
true

輸入是否顯示重試訊息布林值,預設true

Returns:

回傳Promise,resolve回傳結果物件{dataYear,totalHolidays,holidays},有給checkDate時另含{checkDate,isHoliday,holidayName},API回傳非JSON或空陣列時reject回傳錯誤物件

Type
Promise

(async) fetchTwseMargin(dateStr, stockCodesopt, optopt) → {Promise}

Description:
  • 抓取證交所(TWSE)上市融資融券

    抓取指定日之上市個股融資融券餘額並轉為結構化資料, 可指定股票代號陣列過濾; 選表先以標題「融資融券彙總」精確比對, 失敗則退而以欄位同時含「融資」與「融券」比對, 提升schema改版容忍度

Source:
Example
import fetchTwseMargin from './src/fetchTwseMargin.mjs'

let test = async () => {

    let r = await fetchTwseMargin('20260807', ['2330'])
    console.log(r.source, r.count, r.data[0].code, r.data[0].marginBalance)
    // => 'twse_margin' 1 '2330' 12345

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
dateStr String

輸入日期YYYYMMDD字串

stockCodes Array <optional>

輸入股票代號字串陣列,省略或空陣列表示全市場

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
baseUrl String <optional>
'https://www.twse.com.tw'

輸入證交所根網址字串,供測試或改指向鏡像時覆寫

timeout Integer <optional>
15000

輸入單次請求逾時毫秒整數,預設15000

maxRetries Integer <optional>
10

輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10

baseDelayMs Integer <optional>
5000

輸入重試之線性退避基礎毫秒整數,預設5000

maxDelayMs Integer <optional>
30000

輸入重試之線性退避上限毫秒整數,預設30000

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳結果物件{source,date,count,data},日期無效、API錯誤或指定個股查無資料時reject回傳錯誤物件

Type
Promise

(async) fetchTwseStock(dateStr, stockCodeopt, optopt) → {Promise}

Description:
  • 抓取證交所(TWSE)上市股價

    指定stockCode時走STOCK_DAY取個股日成交資訊(該API回傳整月資料, 本函數過濾為指定日單筆); 未指定或指定為'all'時走MI_INDEX取全市場收盤資料

Source:
Example
import fetchTwseStock from './src/fetchTwseStock.mjs'

let test = async () => {

    let r = await fetchTwseStock('20260807', '2330')
    console.log(r.stat, r.data.length)
    // => 'OK' 1

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
dateStr String

輸入日期YYYYMMDD字串

stockCode String <optional>

輸入股票代號字串,例如'2330',省略或給'all'表示全市場

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
baseUrl String <optional>
'https://www.twse.com.tw'

輸入證交所根網址字串,供測試或改指向鏡像時覆寫

timeout Integer <optional>
10000

輸入單次請求逾時毫秒整數,預設10000

maxRetries Integer <optional>
10

輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10

baseDelayMs Integer <optional>
5000

輸入重試之線性退避基礎毫秒整數,預設5000

maxDelayMs Integer <optional>
30000

輸入重試之線性退避上限毫秒整數,預設30000

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳證交所API原始資料物件,內含fields與data等欄位,日期無效、API回傳非OK或指定日無交易資料時reject回傳錯誤物件

Type
Promise

(async) fetchTwseT86(dateStr, stockCodesopt, optopt) → {Promise}

Description:
  • 抓取證交所(TWSE)上市三大法人買賣超

    抓取指定日之上市三大法人買賣超(T86), 以API回傳之fields為key轉為物件陣列, 可指定股票代號陣列過濾

Source:
Example
import fetchTwseT86 from './src/fetchTwseT86.mjs'

let test = async () => {

    let r = await fetchTwseT86('20260807', ['2330'])
    console.log(r.source, r.data.length, r.data[0]['證券代號'])
    // => 'twse' 1 '2330'

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
dateStr String

輸入日期YYYYMMDD字串

stockCodes Array <optional>

輸入股票代號字串陣列,省略或空陣列表示全市場

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
baseUrl String <optional>
'https://www.twse.com.tw'

輸入證交所根網址字串,供測試或改指向鏡像時覆寫

timeout Integer <optional>
15000

輸入單次請求逾時毫秒整數,預設15000

maxRetries Integer <optional>
10

輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10

baseDelayMs Integer <optional>
5000

輸入重試之線性退避基礎毫秒整數,預設5000

maxDelayMs Integer <optional>
30000

輸入重試之線性退避上限毫秒整數,預設30000

useShowLog Boolean <optional>
true

輸入是否顯示過程訊息布林值,預設true

Returns:

回傳Promise,resolve回傳結果物件{source,date,data},日期無效或API錯誤時reject回傳錯誤物件

Type
Promise

(async) fetchWithRetry(url, optopt) → {Promise}

Description:
  • 以node內建fetch抓取資料並自動重試

    特點: HTTP 5xx與429及網路層錯誤(含逾時)會自動重試,採線性退避baseDelayMs*attempt並以maxDelayMs為上限; HTTP 4xx(429除外)預設不重試,可由opt.retryStatus指定額外可重試狀態碼(如403、404); responseType為'json'時先取原始文字再自行JSON.parse,令維護頁面能產生可讀錯誤訊息

Source:
Example
import fetchWithRetry from './src/fetchWithRetry.mjs'

let test = async () => {

    let r = await fetchWithRetry('https://hacker-news.firebaseio.com/v0/item/1.json')
    console.log(r.type, r.by)
    // => 'story' 'pg'

}
await test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
url String

輸入待抓取網址字串

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
method String <optional>
'GET'

輸入HTTP方法字串,預設'GET'

headers Object <optional>
{}

輸入額外HTTP標頭物件,未指定User-Agent時自動補預設值,預設{}

body String <optional>
null

輸入請求主體字串,預設null代表無主體

responseType String <optional>
'json'

輸入回應解析方式字串,可為'json'、'text'、'arrayBuffer',預設'json'

encoding String <optional>
''

輸入responseType為'text'時之解碼字串,例如'big5',預設''代表utf-8

timeout Integer <optional>
30000

輸入單次請求逾時毫秒整數,預設30000

maxRetries Integer <optional>
10

輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10

baseDelayMs Integer <optional>
5000

輸入線性退避之基礎毫秒整數,預設5000

maxDelayMs Integer <optional>
30000

輸入線性退避之上限毫秒整數,預設30000

retryStatus Array <optional>
[]

輸入額外視為可重試之HTTP狀態碼陣列,例如[403],預設[]

label String <optional>
''

輸入重試訊息前綴字串,預設''

useShowLog Boolean <optional>
true

輸入是否顯示重試訊息布林值,預設true

Returns:

回傳Promise,resolve回傳解析後資料,responseType為'json'時回物件、'text'時回字串、'arrayBuffer'時回ArrayBuffer,重試耗盡或遇不可重試錯誤時reject回傳錯誤物件

Type
Promise

getCfg(optopt) → {Object}

Description:
  • 正規化本模組共用設定

Source:
Parameters:
Name Type Attributes Default Description
opt Object <optional>
{}

輸入設定物件,預設{}

Returns:

回傳已正規化之設定物件,內含baseUrl、showLog與optFetch

Type
Object

getCfg(optopt) → {Object}

Description:
  • 正規化本模組共用設定

Source:
Parameters:
Name Type Attributes Default Description
opt Object <optional>
{}

輸入設定物件,預設{}

Returns:

回傳已正規化之設定物件,內含baseUrl、showLog與optFetch

Type
Object

getOptFetch(optopt, dfltopt) → {Object}

Description:
  • 正規化抓取設定

    各抓取函數之timeout、maxRetries、baseDelayMs、maxDelayMs與showLog皆可由呼叫端覆寫, 未給者取該函數之預設值, 再未給者取全域預設值; responseType、encoding、headers、retryStatus與label屬各函數固有特性, 僅由dflt指定不開放覆寫

Source:
Example
import getOptFetch from './src/getOptFetch.mjs'

console.log(getOptFetch({ maxRetries: 2 }, { timeout: 15000, label: 'abc' }))
// => { timeout: 15000, maxRetries: 2, baseDelayMs: 5000, maxDelayMs: 30000, useShowLog: true, label: 'abc' }
Parameters:
Name Type Attributes Default Description
opt Object <optional>
{}

輸入呼叫端設定物件,預設{}

dflt Object <optional>
{}

輸入各抓取函數之預設值物件,預設{}

Returns:

回傳可直接傳入fetchWithRetry之設定物件,另含showLog供呼叫端判斷是否輸出過程訊息

Type
Object

getPayload(marketKind) → {Object}

Description:
  • 組出單一市場別之API查詢payload

Source:
Parameters:
Name Type Description
marketKind String

輸入市場別字串,可為'sii'、'otc'、'rotc'、'pub'

Returns:

回傳API查詢payload物件

Type
Object

(async) getXml(rssUrl, method, cfg) → {Promise}

Description:
  • 依method分派取回XML

Source:
Parameters:
Name Type Description
rssUrl String

輸入RSS網址字串

method String

輸入抓取方式字串,可為'fetch'、'curl'、'auto'

cfg Object

輸入已正規化之抓取設定物件

Returns:

回傳Promise,resolve回傳XML字串

Type
Promise

(async) getXmlByCurl(rssUrl, cfg) → {Promise}

Description:
  • 以curl取回XML

    委派w-fetch-web之fetchWebByCurl, 失敗時拋出帶statusCode之錯誤(與fetchWithRetry之錯誤形狀一致, 供上層統一處理)。 注意: fetchWebByCurl之參數名為timeoutMs(非timeout), 且其重試退避為內建之3至15秒線性, 故opt之baseDelayMs、maxDelayMs與retryStatus於curl模式不生效

Source:
Parameters:
Name Type Description
rssUrl String

輸入RSS網址字串

cfg Object

輸入已正規化之抓取設定物件

Returns:

回傳Promise,resolve回傳XML字串

Type
Promise

htmlToMarkdown(html, optopt) → {String}

Description:
  • HTML轉Markdown

    採正則式逐項轉換, 不引入DOM解析器, 適用於已切出之正文區塊; 先移除script、style與註解, 再轉換標題、粗體、斜體、換行、連結與段落, 最後清除殘留標籤並收斂空行

Source:
Example
import htmlToMarkdown from './src/htmlToMarkdown.mjs'

console.log(htmlToMarkdown('<p>a<b>b</b></p><p>c</p>'))
// => 'a**b**\n\nc'

console.log(htmlToMarkdown('<p><img src="a.png" /></p>', { image: true }))
// => '![](a.png)'
Parameters:
Name Type Attributes Default Description
html String

輸入HTML字串

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
image Boolean <optional>
false

輸入是否將img標籤轉為Markdown圖片語法布林值,預設false代表直接移除

Returns:

回傳Markdown字串,輸入非字串時回傳''

Type
String

isHomepageHtml(html) → {Boolean}

Description:
  • 偵測HTML是否為觀察者網首頁

    判準為首頁底部含A-Z作者索引之

    [A-Z]
    標記(真正的作者欄頁、欄目頁與主題集頁皆無此區塊), 用以識別「請求被302導向首頁」之情形

Source:
Parameters:
Name Type Description
html String

輸入HTML字串

Returns:

回傳是否為首頁之布林值

Type
Boolean

isNonHolidayEntry(entry) → {Boolean}

Description:
  • 判斷條目是否為非假日條目

    應排除者有二類: 交易日標記(「國曆新年開始交易日」「農曆春節前最後交易日」「農曆春節後開始交易日」); 結算作業日(「市場無交易,僅辦理結算交割作業」)

Source:
Parameters:
Name Type Description
entry Object

輸入API回傳之單筆條目物件

Returns:

回傳是否為非假日條目之布林值

Type
Boolean

isRetryableError(err, retryStatus) → {Boolean}

Description:
  • 判斷錯誤是否值得重試

    有statusCode(即HTTP層錯誤)時, 5xx與429視為暫時性, 其餘由retryStatus指定; 無statusCode(即網路層錯誤)時, 由錯誤碼、AbortError與undici暫時性錯誤判斷

Source:
Parameters:
Name Type Description
err Error

輸入錯誤物件

retryStatus Array

輸入額外視為可重試之HTTP狀態碼陣列

Returns:

回傳是否可重試布林值

Type
Boolean

isYmd(dateStr) → {Boolean}

Description:
  • 判斷是否為合法之YYYYMMDD日期字串

    除檢核8碼數字格式外, 另檢核日曆合法性, 例如20260230雖為8碼數字但該日不存在

Source:
Example
import isYmd from './src/isYmd.mjs'

console.log(isYmd('20260807'), isYmd('20260230'), isYmd('2026-08-07'), isYmd(20260807))
// => true false false false
Parameters:
Name Type Description
dateStr String

輸入日期字串

Returns:

回傳是否為合法YYYYMMDD日期字串之布林值

Type
Boolean

lookupAuthor(authors, name) → {Object|null}

Description:
  • 由作者清單查找指定中文名之作者

    本函數不轉繁簡, 呼叫端須自行使用站方登錄字形(通常為簡體)

Source:
Example
import { lookupAuthor } from './src/fetchAisixiang.mjs'

console.log(lookupAuthor([{ slug: 'gezhaoguang', name: '葛兆光' }], '葛兆光'))
// => { slug: 'gezhaoguang', name: '葛兆光' }
Parameters:
Name Type Description
authors Array

輸入作者物件陣列

name String

輸入作者中文名字串

Returns:

回傳作者物件,查無時回傳null

Type
Object | null

lookupAuthor(authors, name) → {Object|null}

Description:
  • 由作者清單查找指定中文名之作者

    本函數不轉繁簡, 呼叫端須自行使用站方登錄字形(簡體)

Source:
Example
import { lookupAuthor } from './src/fetchGuancha.mjs'

console.log(lookupAuthor([{ slug: 'AnSheng', name: '安生' }], '安生'))
// => { slug: 'AnSheng', name: '安生' }
Parameters:
Name Type Description
authors Array

輸入作者物件陣列

name String

輸入作者中文名字串

Returns:

回傳作者物件,查無時回傳null

Type
Object | null

lookupTopic(topics, name) → {Object|null}

Description:
  • 由主題清單查找指定名稱之主題

Source:
Example
import { lookupTopic } from './src/fetchAisixiang.mjs'

console.log(lookupTopic([{ id: '301', name: '大数据' }], '大数据'))
// => { id: '301', name: '大数据' }
Parameters:
Name Type Description
topics Array

輸入主題物件陣列

name String

輸入主題名稱字串

Returns:

回傳主題物件,查無時回傳null

Type
Object | null

lookupTopic(name) → {Object|null}

Description:
  • 由已知主題對照表查找指定名稱之主題

    採first-match, 故同名時分頁版slug優先(見KNOWN_TOPICS說明)

Source:
Example
import { lookupTopic } from './src/fetchGuancha.mjs'

console.log(lookupTopic('财经'))
// => { slug: 'CaiJing', name: '财经' }
Parameters:
Name Type Description
name String

輸入主題名稱字串

Returns:

回傳主題物件,查無時回傳null

Type
Object | null

parseAuthorColumnPage(html, baseUrl) → {Array}

Description:
  • 解析作者專欄頁之文章清單

    專欄頁以h3標記分類(论文、时评、随笔等), 分類區塊內為/data/.html之文章連結

Source:
Parameters:
Name Type Description
html String

輸入作者專欄頁HTML字串

baseUrl String

輸入網站根網址字串

Returns:

回傳文章物件陣列,各物件為{aid,url,title,category}

Type
Array

parseAuthorIndex(html) → {Array}

Description:
  • 由首頁底部A-Z索引解析作者對照

Source:
Parameters:
Name Type Description
html String

輸入首頁HTML字串

Returns:

回傳作者物件陣列,各物件為{slug,name,letter}

Type
Array

parseCSV(csvText) → {Array}

Description:
  • 解析CSV文字為物件陣列

    以首列為欄名, 支援尾端逗號、引號欄位, 並去除前後空白

Source:
Parameters:
Name Type Description
csvText String

輸入CSV文字字串

Returns:

回傳物件陣列,資料不足2列時回傳[]

Type
Array

parseCSVLine(line) → {Array}

Description:
  • 解析單行CSV

    支援含逗號之引號欄位與""跳脫雙引號(RFC 4180子集, 足以涵蓋期交所未來欄位變動)

Source:
Parameters:
Name Type Description
line String

輸入CSV單行字串

Returns:

回傳欄位字串陣列

Type
Array

parseIntComma(str) → {Number}

Description:
  • 含千分位逗號之字串轉整數

    證交所與櫃買中心之數值欄位皆以逗號分隔千分位, 且缺值以'-'或空字串表示; 非字串者原樣回傳(該類API之數值欄位偶為number), 無法轉為整數者回傳0

Source:
Example
import parseIntComma from './src/parseIntComma.mjs'

console.log(parseIntComma('1,234,567'), parseIntComma('-'), parseIntComma(''), parseIntComma(12))
// => 1234567 0 0 12
Parameters:
Name Type Description
str String

輸入含千分位逗號之數值字串

Returns:

回傳整數,非字串輸入時原樣回傳,無法轉換時回傳0

Type
Number

parseListPage(html, baseUrl) → {Array}

Description:
  • 解析列表頁之文章清單

    列表頁slug與文章URL slug通常不同(作者頁同slug, 主題集頁用各自作者slug, 欄目頁用大頻道slug), 故本函數不限定文章URL之slug, 抽出所有符合//<YYYY_MM_DD>_.shtml模式之連結

Source:
Parameters:
Name Type Description
html String

輸入列表頁HTML字串

baseUrl String

輸入網站根網址字串

Returns:

回傳文章物件陣列,各物件為{url,title,slug}

Type
Array

parseNum(str) → {Number|null}

Description:
  • 含千分位逗號之字串轉數值

    與parseIntComma不同, 本函數保留小數並以null表達缺值, 供期交所價格與比率欄位使用

Source:
Parameters:
Name Type Description
str String

輸入數值字串

Returns:

回傳數值,為'-'、空字串或無法轉換時回傳null

Type
Number | null

parseSearchResults(html, baseUrl) → {Array}

Description:
  • 解析搜尋結果頁之文章清單

    精確切出search_list區塊再解析, 避免0結果時誤抓側邊欄連結

Source:
Parameters:
Name Type Description
html String

輸入搜尋結果頁HTML字串

baseUrl String

輸入網站根網址字串

Returns:

回傳文章物件陣列,各物件為{aid,url,title,author}

Type
Array

parseSearchTotalPages(html) → {Integer}

Description:
  • 由list_page區塊解析最大頁碼

Source:
Parameters:
Name Type Description
html String

輸入列表頁HTML字串

Returns:

回傳總頁數整數,無分頁區塊時回傳1

Type
Integer

parseZhuantiArticles(html, baseUrl) → {Array}

Description:
  • 解析策展主題頁之文章清單

    主題頁之連結無title屬性, 標題在anchor內文, 格式為作者:標題

Source:
Parameters:
Name Type Description
html String

輸入主題頁HTML字串

baseUrl String

輸入網站根網址字串

Returns:

回傳文章物件陣列,各物件為{aid,url,title,author}

Type
Array

pickPint(opt, dflt, key, fallback) → {Integer}

Description:
  • 取得正整數設定值

Source:
Parameters:
Name Type Description
opt Object

輸入呼叫端設定物件

dflt Object

輸入各抓取函數之預設值物件

key String

輸入設定鍵名字串

fallback Integer

輸入無設定時之預設整數

Returns:

回傳正整數

Type
Integer

rocToWestern(rocDate) → {String}

Description:
  • 民國日期YYYMMDD轉西元日期YYYYMMDD

Source:
Parameters:
Name Type Description
rocDate String

輸入民國日期字串,年份位數不限

Returns:

回傳西元日期YYYYMMDD字串

Type
String

safeFilename(name) → {String}

Description:
  • 字串轉安全檔名

    將Windows與POSIX皆不允許之字元(/:*?"<>|)替換為底線, 並截斷至200字元以避開檔名長度上限

Source:
Example
import safeFilename from './src/safeFilename.mjs'

console.log(safeFilename('a/b:c*d?e'))
// => 'a_b_c_d_e'
Parameters:
Name Type Description
name String

輸入檔名字串

Returns:

回傳安全檔名字串

Type
String

stripHtml(html) → {String}

Description:
  • 去除HTML標籤與實體, 保留段落換行

    與htmlToMarkdown不同, 本函數輸出純文字(不產生Markdown標記), 供feed內嵌全文等 「只要內文、不要格式」之場景使用; 先移除script與style, 再將段落類閉合標籤與br轉為換行, 最後清除殘留標籤並解碼實體

Source:
Example
import stripHtml from './src/stripHtml.mjs'

console.log(stripHtml('<p>第一段<b>粗體</b></p><p>第二段&amp;實體</p>'))
// => '第一段粗體\n第二段&實體'
Parameters:
Name Type Description
html String

輸入HTML字串

Returns:

回傳純文字字串,輸入非字串時回傳''

Type
String

toDatetimeUTC8(value) → {String}

Description:
  • 時間轉UTC+8之日期時間字串

    可接受ISO時間字串、RFC822時間字串、純日期字串、unix秒數(Number, 非毫秒)或Date物件, 一律輸出台灣時間'YYYY-MM-DD HH:mm:ss', 且不受執行環境時區影響。

    兩類輸入之時區語意不同, 故分開處理: 帶有時刻資訊者(ISO、RFC822、unix秒數、Date)代表一個絕對時點, 換算為UTC+8之當地時刻; 純日期字串本身不含時點, 直接視為UTC+8當日之00:00:00, 不因執行環境時區而位移日期 (否則在UTC+14環境下'2024'會被解為2023-12-31)。

Source:
Example
import toDatetimeUTC8 from './src/toDatetimeUTC8.mjs'

console.log(toDatetimeUTC8('2026-08-07T01:02:03Z'))
// => '2026-08-07 09:02:03'

console.log(toDatetimeUTC8(1786000000))
// => '2026-08-06 15:06:40'

console.log(toDatetimeUTC8('2024'), toDatetimeUTC8('20260807'))
// => '2024-01-01 00:00:00' '2026-08-07 00:00:00'

console.log(toDatetimeUTC8('abc'), toDatetimeUTC8(''), toDatetimeUTC8(null))
// => '' '' ''
Parameters:
Name Type Description
value String | Number | Date

輸入ISO或RFC822時間字串、純日期字串、unix秒數或Date物件

Returns:

回傳UTC+8之日期時間字串,格式為'YYYY-MM-DD HH:mm:ss',輸入為空或無法解析時回傳''

Type
String

toRocDate(dateStr) → {String}

Description:
  • 西元YYYYMMDD日期字串轉民國日期字串

    民國年為西元年減1911, 月與日保留原始2碼不補零亦不去零, 以符合證交所與櫃買中心API之查詢格式

Source:
Example
import toRocDate from './src/toRocDate.mjs'

console.log(toRocDate('20260807'), toRocDate('19110101'))
// => '115/08/07' '0/01/01'
Parameters:
Name Type Description
dateStr String

輸入西元日期YYYYMMDD字串

Returns:

回傳民國日期字串,格式為'YYY/MM/DD',輸入非有效字串時回傳''

Type
String