@ citetyle/ 类型
Citestyle生态系统的TypeScript类型定义. 覆盖了CSL-JSON数据结构,编译了样式模块,引用注册,以及所有公共API.
当使用任意类型时自动获得这些类型 @citestyle/* 软件包——每个软件包 exports 地图包括 types 条件在这里。 直接安装此软件包, 只当您需要导入类型而无需拖入运行时的软件包 .
安装
npm install -D @citestyle/types
类型
CSL- JSON 数据
| 类型 | 说明 |
CslItem | 包含所有标准 SSL- JSON 字段( 70+) 的引用项, 加 year-suffix 和扩展字段的索引签名 |
CslName | 名称对象 : family, (中文(简体) ), given, (中文(简体) ), non-dropping-particle, (中文(简体) ), dropping-particle, (中文(简体) ), suffix, (中文(简体) ), literal |
CslDate | 日期对象 : date-parts, (中文(简体) ), literal, (中文(简体) ), raw, (中文(简体) ), season, (中文(简体) ), circa |
CslItemType | 40+ CPL 项目类型字符串的结合 |
编译样式模块
| 类型 | 说明 |
CompiledStyle | 编译的样式模块 : meta, (中文(简体) ), bibliography(), (中文(简体) ), citation(), (中文(简体) ), bibliographySort() |
StyleMeta | 样式元数据 : id, (中文(简体) ), title, (中文(简体) ), class,解析设置,崩溃模式,分隔符 |
FormattedEntry | 文献目录产出: { text, html, parts, links } |
FormattedCitation | 引用输出 : { text, html } |
书记官处
| 类型 | 说明 |
Registry | 登记册接口 : addItems(), (中文(简体) ), getItem(), (中文(简体) ), cite(), (中文(简体) ), getBibliography(), (中文(简体) ), size |
RegistryOptions | 备选方案 createRegistry()数字 : subsequentAuthorSubstitute |
CiteRef | 引文参考: id, (中文(简体) ), item, (中文(简体) ), locator, (中文(简体) ), label, (中文(简体) ), prefix, (中文(简体) ), suffix |
FormatContext | 运行时背景传递到样式函数 : _secOpts, (中文(简体) ), _disambig |
DisambiguationContext | 平地分解状态 : addNames, (中文(简体) ), addGivenname, (中文(简体) ), givenname |
编译器
| 类型 | 说明 |
CompileOptions | 备选方案 compile()数字 : locale, (中文(简体) ), format |
CompileResult | 编译器输出 : { code, meta } |
| 类型 | 说明 |
NameFormatConfig | 配置用于 formatNames(): et-al,粒子,排序顺序,初始化 |
DateFormatConfig | 配置用于 formatDate(): 日期、月份、范围 |
ValidationResult | 产出 validateItem()数字 : { valid, warnings } |
使用量
import type { CslItem, CslName, FormattedEntry, CompiledStyle } from '@citestyle/types'
const item: CslItem = {
id: '1',
type: 'article-journal',
title: 'A groundbreaking study',
author: [{ family: 'Smith', given: 'Jane' }],
issued: { 'date-parts': [[2024, 6]] },
'container-title': 'Nature',
DOI: '10.1038/example',
}
function formatBibliography(style: CompiledStyle, items: CslItem[]): FormattedEntry[] {
return items.map(item => style.bibliography!(item))
}
import type { Registry, CiteRef, FormattedCitation } from '@citestyle/types'
function citeItems(registry: Registry, ids: string[]): FormattedCitation {
const cites: CiteRef[] = ids.map(id => ({ id }))
return registry.cite(cites)
}