diff --git a/src/entities/_parse.ts b/src/entities/_parse.ts index d04514a..bb216d0 100644 --- a/src/entities/_parse.ts +++ b/src/entities/_parse.ts @@ -1,4 +1,4 @@ -import { gCharP, gDouble, gInt, gUInt32 } from './_g_types' +import type { gCharP, gDouble, gInt, gUInt32 } from './_g_types' const parseAsInt = (s: string): T => parseInt(s, 10) as T const parseAsString = (s: string) => s && (String(s) as T) diff --git a/src/entities/_serialize.ts b/src/entities/_serialize.ts index 52c1358..d24e0b9 100644 --- a/src/entities/_serialize.ts +++ b/src/entities/_serialize.ts @@ -1,5 +1,5 @@ import { sprintf } from 'printj' -import { gCharP, gDouble, gUInt32 } from './_g_types' +import type { gCharP, gDouble, gUInt32 } from './_g_types' export const hb_xml_attr_txt = (attrName: string, value: gCharP) => value === null || value === undefined diff --git a/src/entities/account.ts b/src/entities/account.ts index 8f72f5c..0613b57 100644 --- a/src/entities/account.ts +++ b/src/entities/account.ts @@ -7,7 +7,7 @@ import { hb_xml_attr_txt_crlf, hb_xml_tag, } from './_serialize' -import { gCharP, gDouble, gUInt32, gUShort } from './_g_types' +import type { gCharP, gDouble, gUInt32, gUShort } from './_g_types' export interface Account { key: gUInt32 @@ -50,7 +50,7 @@ export enum AccountType { //TYPE_EQUITY = 10 as gushort, // Capitaux propres } -export function parse({ attributes }: Node): Account { +export function parseAccount({ attributes }: Node): Account { return { key: atoi(attributes.key), flags: atoi(attributes.flags), @@ -69,7 +69,7 @@ export function parse({ attributes }: Node): Account { } } -export const serialize = (account: Account): string => +export const serializeAccount = (account: Account): string => hb_xml_tag( ' mem: aSplit.memo, })) -export const serialize = (archive: Archive): string => { +export const serializeArchive = (archive: Archive): string => { const tags = tags_toStr(archive.tags) const splits = archiveSplitsToSplits(archive.splits) return hb_xml_tag( diff --git a/src/entities/assign.ts b/src/entities/assign.ts index 663f1ce..be28646 100644 --- a/src/entities/assign.ts +++ b/src/entities/assign.ts @@ -1,9 +1,9 @@ import { Node } from 'xml-parser' -import { PayMode } from './payee' +import { PayMode } from './operation' import { atoi, parseGCharP } from './_parse' import { VolatileXHB } from '../index' import { hb_xml_attr_int, hb_xml_attr_txt, hb_xml_tag } from './_serialize' -import { gCharP, gUInt32, gUShort } from './_g_types' +import type { gCharP, gUInt32, gUShort } from './_g_types' export interface Assign { key: gUInt32 @@ -31,7 +31,7 @@ export enum AssignFlag { OVWMOD = (1 << 11) as gUShort, } -export function parse({ attributes }: Node, xhb: VolatileXHB): Assign { +export function parseAssign({ attributes }: Node, xhb: VolatileXHB): Assign { const entry: Assign = { key: atoi(attributes.key), flags: atoi(attributes.flags), @@ -53,7 +53,7 @@ export function parse({ attributes }: Node, xhb: VolatileXHB): Assign { return entry } -export const serialize = (assign: Assign): string => +export const serializeAssign = (assign: Assign): string => hb_xml_tag( ' Array.isArray(budget) ? budget - .filter((b) => b !== null || b !== undefined) + .filter((b) => b !== null && b !== undefined) .map((v, i) => sprintf('b%d="%s"', i, dtostr(v))) .join(' ') : '' -export const serialize = (category: Category): string => +export const serializeCategory = (category: Category): string => hb_xml_tag( ' +export const serializeCurrency = (currency: Currency): string => sprintf( '', currency.key, diff --git a/src/entities/index.ts b/src/entities/index.ts deleted file mode 100644 index ef80e5b..0000000 --- a/src/entities/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -export { Account, AccountFlag, AccountType } from './account' -export { Archive, ArchiveFlag, ArchiveStatus, ArchiveSplit } from './archive' -export { Category, CategoryFlag } from './category' -export { - Operation, - PayMode as OperationPayMode, - OperationFlag, - OperationSplit, -} from './operation' -export { Payee, PayMode as PayeePayMode } from './payee' -export { Properties } from './properties' -export { Tag } from './tag' -export { Versions } from './versions' diff --git a/src/entities/operation.ts b/src/entities/operation.ts index f08c4f4..c10da16 100644 --- a/src/entities/operation.ts +++ b/src/entities/operation.ts @@ -10,7 +10,7 @@ import { hb_xml_tag, tags_toStr, } from './_serialize' -import { gCharP, gDouble, gUInt32, gUShort } from './_g_types' +import type { gCharP, gDouble, gUInt32, gUShort } from './_g_types' export interface Operation { date: gUInt32 @@ -63,15 +63,7 @@ export enum OperationFlag { SPLIT = (1 << 8) as gUShort, } -export enum ArchiveStatus { - NONE, - CLEARED, - RECONCILED, - REMIND, - //VOID -} - -export function parse({ attributes }: Node): Operation { +export function parseOperation({ attributes }: Node): Operation { const tags: gCharP[] = attributes.tags ? parseGCharP(attributes.tags).split(' ') : [] @@ -123,7 +115,7 @@ const operationSplitsToSplits = (aSplits: OperationSplit[]): AttrSplit[] => mem: aSplit.memo, })) -export const serialize = (operation: Operation): string => { +export const serializeOperation = (operation: Operation): string => { const tags = tags_toStr(operation.tags) const splits = operationSplitsToSplits(operation.splits) return hb_xml_tag( diff --git a/src/entities/payee.ts b/src/entities/payee.ts index 586a528..dcaa24a 100644 --- a/src/entities/payee.ts +++ b/src/entities/payee.ts @@ -1,7 +1,7 @@ import { Node } from 'xml-parser' import { atoi, parseGCharP } from './_parse' import { hb_xml_attr_int, hb_xml_attr_txt, hb_xml_tag } from './_serialize' -import { gCharP, gUInt32, gUShort } from './_g_types' +import type { gCharP, gUInt32, gUShort } from './_g_types' export interface Payee { key: gUInt32 @@ -10,23 +10,7 @@ export interface Payee { category: gUInt32 } -export enum PayMode { - NONE = 0 as gUShort, - CCARD = 1 as gUShort, - CHECK = 2 as gUShort, - CASH = 3 as gUShort, - XFER = 4 as gUShort, - INTXFER = 5 as gUShort, - DCARD = 6 as gUShort, - REPEATPMT = 7 as gUShort, - EPAYMENT = 8 as gUShort, - DEPOSIT = 9 as gUShort, - FEE = 10 as gUShort, - DIRECTDEBIT = 11 as gUShort, - NUM_PAYMODE_MAX = 12 as gUShort, -} - -export function parse({ attributes }: Node): Payee { +export function parsePayee({ attributes }: Node): Payee { return { key: atoi(attributes.key), name: parseGCharP(attributes.name), @@ -35,7 +19,7 @@ export function parse({ attributes }: Node): Payee { } } -export const serialize = (payee: Payee): string => +export const serializePayee = (payee: Payee): string => hb_xml_tag( ' +export const serializeProperties = (properties: Properties): string => hb_xml_tag( ' +export const serializeTag = (tag: Tag): string => sprintf('', tag.key, tag.name) diff --git a/src/entities/versions.ts b/src/entities/versions.ts index 8b39948..e061190 100644 --- a/src/entities/versions.ts +++ b/src/entities/versions.ts @@ -1,19 +1,19 @@ import { Node } from 'xml-parser' import { parseGDouble, parseGInt } from './_parse' import { sprintf } from 'printj' -import { gDouble, gInt } from './_g_types' +import type { gDouble, gInt } from './_g_types' export interface Versions { file: gDouble data: gInt } -export function parse({ attributes }: Node): Versions { +export function parseVersions({ attributes }: Node): Versions { return { file: parseGDouble(attributes.v), data: parseGInt(attributes.d), } } -export const serialize = (versions: Versions) => +export const serializeVersions = (versions: Versions) => sprintf('', versions.file, versions.data) diff --git a/src/index.ts b/src/index.ts index 1c47f8f..34a9f45 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,53 +1,21 @@ import XMLParser, { Node } from 'xml-parser' import { - parse as parseProperties, + parseProperties, Properties, - serialize as serializeProperties, + serializeProperties, } from './entities/properties' -import { - Category, - parse as parseCategory, - serialize as serializeCategory, -} from './entities/category' -import { - parse as parsePayee, - Payee, - serialize as serializePayee, -} from './entities/payee' -import { - Assign, - parse as parseAssign, - serialize as serializeAssign, -} from './entities/assign' -import { - Account, - parse as parseAccount, - serialize as serializeAccount, -} from './entities/account' -import { - parse as parseVersions, - serialize as serializeVersions, - Versions, -} from './entities/versions' -import { - Currency, - parse as parseCurrency, - serialize as serializeCurrency, -} from './entities/currency' -import { - parse as parseTag, - serialize as serializeTag, - Tag, -} from './entities/tag' -import { - Archive, - parse as parseArchive, - serialize as serializeArchive, -} from './entities/archive' +import { Category, parseCategory, serializeCategory } from './entities/category' +import { parsePayee, Payee, serializePayee } from './entities/payee' +import { Assign, parseAssign, serializeAssign } from './entities/assign' +import { Account, parseAccount, serializeAccount } from './entities/account' +import { parseVersions, serializeVersions, Versions } from './entities/versions' +import { Currency, parseCurrency, serializeCurrency } from './entities/currency' +import { parseTag, serializeTag, Tag } from './entities/tag' +import { Archive, parseArchive, serializeArchive } from './entities/archive' import { Operation, - parse as parseOperation, - serialize as serializeOperation, + parseOperation, + serializeOperation, } from './entities/operation' export interface XHB { @@ -185,3 +153,17 @@ export const serialize = (xhb: XHB, options: SerializeOptions = {}): string => { .filter((line) => line && line.length) .join('\n') } + +export * from './entities/_g_types' +export * from './entities/_parse' +export * from './entities/_serialize' +export * from './entities/account' +export * from './entities/archive' +export * from './entities/assign' +export * from './entities/category' +export * from './entities/currency' +export * from './entities/operation' +export * from './entities/payee' +export * from './entities/properties' +export * from './entities/tag' +export * from './entities/versions'