Files
accounted/scripts/generate-bas-account-numbers.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

57 lines
2.2 KiB
TypeScript

/**
* Regenerates lib/bookkeeping/bas-account-numbers.ts from the BAS chart.
*
* npx tsx scripts/generate-bas-account-numbers.ts # write
* npx tsx scripts/generate-bas-account-numbers.ts --check # exit 1 if stale
*
* The generated module is a sorted list of the ~1,276 standard account
* numbers (~9 KB) so client components can answer "is this a standard BAS
* account?" without the 315 KB data chunk. A unit test pins parity too.
*/
import fs from 'node:fs'
import path from 'node:path'
import { BAS_REFERENCE } from '../lib/bookkeeping/bas-data'
const OUT = path.resolve(__dirname, '..', 'lib', 'bookkeeping', 'bas-account-numbers.ts')
export function renderBasAccountNumbers(numbers: readonly string[]): string {
const sorted = [...new Set(numbers)].sort()
const rows: string[] = []
for (let i = 0; i < sorted.length; i += 12) {
rows.push(' ' + sorted.slice(i, i + 12).map((n) => `'${n}'`).join(', ') + ',')
}
return `// GENERATED by scripts/generate-bas-account-numbers.ts from lib/bookkeeping/bas-data.
// Do not edit by hand: run \`npx tsx scripts/generate-bas-account-numbers.ts\`.
//
// The sorted list of standard BAS account numbers (~9 KB) so client code can
// check membership without importing the full chart (315 KB uncompressed).
// lib/bookkeeping/__tests__/bas-account-numbers.test.ts pins parity.
export const BAS_ACCOUNT_NUMBERS: readonly string[] = [
${rows.join('\n')}
]
const BAS_ACCOUNT_NUMBER_SET: ReadonlySet<string> = new Set(BAS_ACCOUNT_NUMBERS)
/** Whether the number exists in the BAS chart (same answer as isStandardBASAccount). */
export function isStandardBASAccountNumber(accountNumber: string): boolean {
return BAS_ACCOUNT_NUMBER_SET.has(accountNumber)
}
`
}
if (require.main === module) {
const rendered = renderBasAccountNumbers(BAS_REFERENCE.map((a) => a.account_number))
if (process.argv.includes('--check')) {
const current = fs.existsSync(OUT) ? fs.readFileSync(OUT, 'utf8') : ''
if (current !== rendered) {
console.error('lib/bookkeeping/bas-account-numbers.ts is stale: run npx tsx scripts/generate-bas-account-numbers.ts')
process.exit(1)
}
console.log('bas-account-numbers.ts is up to date')
} else {
fs.writeFileSync(OUT, rendered)
console.log(`wrote ${OUT}`)
}
}