@ekwo-ai/trial-balance

中文文档
0.25.2发布于 2026/11/13MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 3284

Reads a trial balance written as CSV — account, debit, credit — into the plain shape an opening balance is made of, in TypeScript: amounts as decimal strings, and what does not add up. Zero dependencies.

原始使用文档
文档目录4 节
  1. The file
  2. What it returns
  3. The open items beside it
  4. Where it goes

@ekwo-ai/trial-balance

Reads a trial balance written as CSV — one row per account, a debit and a credit, or one signed balance — into plain objects, in TypeScript, with no dependencies.

It is the one thing every accounting package prints and every spreadsheet saves, which makes it the way in for books that come from anywhere: the balances of the day the new books open on.

import { readTrialBalance } from '@ekwo-ai/trial-balance';

const books = readTrialBalance(bytesOrString);

books.opening;    // [{ account: '512000', debit: '8400.00', credit: '0.00', contact: null, … }, …]
books.accounts;   // [{ code: '512000', name: 'Bank', type: null }, …]
books.contacts;   // the parties a receivable or a payable row names
books.violations; // [{ rule: 'unbalanced', message: '…', row: null }] when it does not balance

The file

A header row, then one row per account. The columns are found by their name, without regard to case, and without the * some exports put on a required column:

ColumnNames accepted
accountaccount, account code, coderequired
namename, account nameoptional
debit, creditdebit, creditboth, or…
balancebalance…one signed balance, positive in debit
contactcontact, partyoptional: the customer or supplier of a receivable or payable row
contact namecontact name, party nameoptional
labellabel, descriptionoptional
  • A row with a debit and a credit is netted: a trial balance prints the totals of each side, and 100 in debit with 30 in credit opens at 70 in debit. A row that nets to zero opens nothing and is left out.
  • The separator is read from the header: the first of ,, ; and a tab it holds outside quotes. Fields may be quoted as RFC 4180 says.
  • The decimal mark is a point. A comma is read as one only in a file separated by something else, where it cannot be a separator of thousands. No thousands separator, no currency sign, no exponent: each is refused rather than read one way or the other.
  • The encoding is UTF-8, fatally. A file saved in Latin-1 is said to be so ({ encoding: 'iso-8859-1' }); it is never guessed, because every sequence of bytes is valid Latin-1.

What it returns

The shape declared in src/types.ts — accounts, contacts, entries, an opening balance, violations — which is, field for field, the shape every reader of an accounting export in this repository declares for itself. A trial balance fills opening and leaves entries empty. It says no currency and no date: the file has neither, and whatever takes the balance is told the day it opens on.

What does not balance comes back in violations, and the rows come back as written. What is not a trial balance at all — no account column, a debit column beside a balance column, an amount that is not one — is thrown as a BooksFileError with a code.

The open items beside it

The trial balance says what the receivable account holds; the aged balance printed beside it says who owes it, under which number. readOpenItems() reads that list, one row per invoice or credit note still open:

import { readOpenItems } from '@ekwo-ai/trial-balance';

const { items, contacts, violations } = readOpenItems(bytesOrString);

items; // [{ type: 'sale_invoice', number: 'F2025-0412', contact: 'C0001', amount: '1200.00',
       //    documentDate: '2025-12-12', dueDate: '2026-01-11', paymentReference: '+++090/9337/55493+++', … }]
ColumnNames accepted
typetype, document typerequired: sale_invoice, sale_credit_note, purchase_invoice or purchase_credit_note
numbernumber, document number, invoice numberrequired
contactcontact, partyrequired: the code the balance names the party by
contact namecontact name, party nameoptional
amountamount, open amount, amount openrequired: what is still open, positive — the type says the side
document datedocument date, issue date, daterequired, YYYY-MM-DD
due datedue dateoptional, YYYY-MM-DD
payment referencepayment reference, structured referenceoptional
supplier referencesupplier referenceoptional
labellabel, descriptionoptional

A day is written YYYY-MM-DD and nothing else: one written in digits only is read differently on each side of an ocean, and is refused rather than guessed. A row that lacks a required value comes back in violations and is left out; an unknown type, a signed amount or a day that is not one is thrown as a BooksFileError. Separator, decimal mark and encoding are read as for the balance.

Where it goes

It knows no chart of accounts. The codes are the ones the file wrote; which account of another chart each becomes is the importer's business. In Ekwo OS that is ekwo import trial-balance <file> --opening-date <day> [--open-items <file>], where the day is the first of a year or the day inside it the books were taken over, and each open item becomes a posted document.

MIT.

版本与发布记录

@ekwo-ai/trial-balance 共发布 28 个版本,首次发布于 2026/09/22;过去 12 个月发布了 28 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.25.2latest2026/11/13今天
0.25.02026/11/076 天前
0.24.12026/11/059 天前
0.24.02026/10/2816 天前
0.23.02026/10/2816 天前
0.22.02026/10/2816 天前

关于 @ekwo-ai/trial-balance 的常见问题

@ekwo-ai/trial-balance 是什么?

Reads a trial balance written as CSV — account, debit, credit — into the plain shape an opening balance is made of, in TypeScript: amounts as decimal strings, and what does not add up. Zero dependencies.

如何安装 @ekwo-ai/trial-balance?

在项目目录运行 npm install @ekwo-ai/trial-balance,或使用 pnpm add / yarn add / bun add。

@ekwo-ai/trial-balance 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ekwo-ai/trial-balance 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@ekwo-ai/trial-balance 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ekwo-ai/trial-balance 可以商用吗?

@ekwo-ai/trial-balance 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ekwo-ai/trial-balance 的下载量有多少?

根据 npm 官方下载统计,@ekwo-ai/trial-balance 在 2026/10/13 – 2026/11/11 这 30 天内被下载 3,284 次,日均约 109 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ekwo-ai/trial-balance 还在维护吗?

最新版本 0.25.2 发布于 2026/11/13(今天);至今共发布 28 个版本,其中过去 12 个月发布了 28 个;首次发布于 2026/09/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。