@a9i5k4/dsh-literature 0.2.9 → 0.2.11

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/lib/index.js CHANGED
@@ -1774,13 +1774,46 @@ __export(cite_exports, {
1774
1774
  stripItalic: () => stripItalic,
1775
1775
  toSegments: () => toSegments
1776
1776
  });
1777
- function authorsList(record, { max = 99, ellipsis = ", et al." } = {}) {
1777
+ function apaInitials(firstName) {
1778
+ const s = String(firstName ?? "").trim();
1779
+ if (!s) return "";
1780
+ return s.charAt(0).toUpperCase() + ".";
1781
+ }
1782
+ function apaAuthors(record) {
1778
1783
  const list = record.authors ?? [];
1779
1784
  if (!list.length) return "";
1780
- const names = list.map((a) => [a.lastName, a.firstName].filter(Boolean).join(", "));
1781
- if (names.length === 1) return names[0];
1782
- if (names.length <= max) return names.slice(0, -1).join(", ") + ", & " + names[names.length - 1];
1783
- return names.slice(0, max).join(", ") + ellipsis;
1785
+ const name2 = (a) => {
1786
+ if (CJK.test(a.lastName ?? "") || CJK.test(a.firstName ?? "")) return `${a.lastName ?? ""}${a.firstName ?? ""}`;
1787
+ return [a.lastName, apaInitials(a.firstName)].filter(Boolean).join(", ");
1788
+ };
1789
+ if (list.length === 1) return name2(list[0]);
1790
+ if (list.length <= 20) {
1791
+ const names = list.map(name2);
1792
+ return names.slice(0, -1).join(", ") + ", & " + names[names.length - 1];
1793
+ }
1794
+ return list.slice(0, 19).map(name2).join(", ") + ", \u2026 " + name2(list[list.length - 1]);
1795
+ }
1796
+ function mlaAuthors(record) {
1797
+ const list = record.authors ?? [];
1798
+ if (!list.length) return "";
1799
+ const inverted = (a) => [a.lastName, a.firstName].filter(Boolean).join(", ");
1800
+ const upright = (a) => [a.firstName, a.lastName].filter(Boolean).join(" ");
1801
+ if (list.length === 1) return inverted(list[0]);
1802
+ if (list.length === 2) return inverted(list[0]) + ", and " + upright(list[1]);
1803
+ return inverted(list[0]) + ", et al";
1804
+ }
1805
+ function chicagoAuthors(record) {
1806
+ const list = record.authors ?? [];
1807
+ if (!list.length) return "";
1808
+ const inverted = (a) => [a.lastName, a.firstName].filter(Boolean).join(", ");
1809
+ const upright = (a) => [a.firstName, a.lastName].filter(Boolean).join(" ");
1810
+ if (list.length === 1) return inverted(list[0]);
1811
+ if (list.length === 2) return inverted(list[0]) + ", and " + upright(list[1]);
1812
+ if (list.length <= 10) {
1813
+ const parts = [inverted(list[0]), ...list.slice(1, -1).map(upright)];
1814
+ return parts.join(", ") + ", and " + upright(list[list.length - 1]);
1815
+ }
1816
+ return list.slice(0, 7).map(inverted).join(", ") + ", et al";
1784
1817
  }
1785
1818
  function authorsShort(record) {
1786
1819
  const list = record.authors ?? [];
@@ -1800,8 +1833,8 @@ function doiUrl(record) {
1800
1833
  return record.doi ? `https://doi.org/${record.doi}` : record.url ?? "";
1801
1834
  }
1802
1835
  function apa(record) {
1803
- const authors2 = authorsList(record, { max: 20 });
1804
- const who = authors2 ? `${authors2}. ` : "";
1836
+ const authors2 = apaAuthors(record);
1837
+ const who = authors2 ? `${authors2} ` : "";
1805
1838
  const year = `(${yearStr(record)}). `;
1806
1839
  const title = (record.title ?? "Untitled").trim();
1807
1840
  if (record.itemType === "journalArticle" || record.itemType === "preprint") {
@@ -1833,10 +1866,16 @@ function apa(record) {
1833
1866
  }
1834
1867
  function gb(record) {
1835
1868
  const list = record.authors ?? [];
1869
+ const cjk = (s) => /[\u4e00-\u9fff]/.test(s ?? "");
1870
+ const gbName = (a) => {
1871
+ if (cjk(a.lastName) || cjk(a.firstName)) return `${a.lastName ?? ""}${a.firstName ?? ""}`;
1872
+ const ini = String(a.firstName ?? "").trim();
1873
+ return [a.lastName, ini ? ini.charAt(0).toUpperCase() : ""].filter(Boolean).join(" ");
1874
+ };
1836
1875
  let who;
1837
1876
  if (!list.length) who = "";
1838
- else if (list.length <= 3) who = list.map((a) => `${a.lastName}${a.firstName ? " " + a.firstName : ""}`).join(", ");
1839
- else who = `${list.slice(0, 3).map((a) => `${a.lastName}${a.firstName ? " " + a.firstName : ""}`).join(", ")}, \u7B49`;
1877
+ else if (list.length <= 3) who = list.map(gbName).join(", ");
1878
+ else who = `${list.slice(0, 3).map(gbName).join(", ")}, \u7B49`;
1840
1879
  const whoPart = who ? `${who}. ` : "";
1841
1880
  const title = (record.title ?? "").trim();
1842
1881
  const year = yearStr(record);
@@ -1865,8 +1904,8 @@ function gb(record) {
1865
1904
  return `${whoPart}${title}[Z]. ${year}.`.trim();
1866
1905
  }
1867
1906
  function mla(record) {
1868
- const list = record.authors ?? [];
1869
- const who = list.length ? list.map((a) => `${a.lastName}, ${a.firstName ?? ""}`.trim()).join(", ") + ". " : "";
1907
+ const who0 = mlaAuthors(record);
1908
+ const who = who0 ? who0 + ". " : "";
1870
1909
  const title = (record.title ?? "Untitled").trim();
1871
1910
  if (record.itemType === "journalArticle" || record.itemType === "preprint") {
1872
1911
  const journal = record.container ? ` *${record.container}*, ` : "";
@@ -1884,8 +1923,8 @@ function mla(record) {
1884
1923
  return `${who}"${title}." ${record.publisher ?? ""} ${yearStr(record)}.`.trim();
1885
1924
  }
1886
1925
  function chicago(record) {
1887
- const list = record.authors ?? [];
1888
- const who = list.length ? list.map((a) => `${a.firstName ?? ""} ${a.lastName ?? ""}`.trim()).join(", ") + ". " : "";
1926
+ const who0 = chicagoAuthors(record);
1927
+ const who = who0 ? who0 + ". " : "";
1889
1928
  const title = (record.title ?? "Untitled").trim();
1890
1929
  if (record.itemType === "journalArticle" || record.itemType === "preprint") {
1891
1930
  const journal = record.container ? ` *${record.container}*` : "";
@@ -1990,14 +2029,15 @@ function authorsShortGb(record) {
1990
2029
  if (!list.length) return "\u4F5A\u540D";
1991
2030
  if (list.length === 1) return list[0].lastName;
1992
2031
  if (list.length === 2) return `${list[0].lastName}\u3001${list[1].lastName}`;
1993
- return `${list[0].lastName}\u7B49`;
2032
+ return `${list[0].lastName} \u7B49`;
1994
2033
  }
1995
2034
  function listStyles() {
1996
2035
  return Object.entries(STYLES).map(([id, s]) => ({ id, label: s.label }));
1997
2036
  }
1998
- var STYLES;
2037
+ var CJK, STYLES;
1999
2038
  var init_cite = __esm({
2000
2039
  "src/node/cite.js"() {
2040
+ CJK = /[\u4e00-\u9fff]/;
2001
2041
  STYLES = {
2002
2042
  apa: { label: "APA 7th", format: apa },
2003
2043
  gb: { label: "GB/T 7714-2015", format: gb },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a9i5k4/dsh-literature",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "description": "DSH Literature 文献侧窗:在 DeepSeek Harness 侧边栏识别 DOI/arXiv/标题、抓取元数据与全文、写入本地文献库或导出目录,并提供内置 PDF 阅读器(缩放/翻页/目录/搜索/高亮/笔记)。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",