Registry / productivity / document-number-formatter

document-number-formatter

JSON →
library1.0.33jsnpmunverified

A lightweight TypeScript library for generating formatted document numbers such as bill numbers, invoice numbers, or custom identifiers. The current stable version is 1.0.33, and it is actively maintained with periodic updates. Key differentiators include support for date-based formatting (year, month, day), sequential value formatting with zero-padding, and fiscal year logic. It is designed for Node.js and browser environments and integrates easily with frameworks like Vue, React, and Angular. The library provides three main functions: formatDocumentNumber, fdnForDate, and formatDate. It is ESM and CJS compatible, ships TypeScript definitions, and has zero external dependencies.

npm install document-number-formatter
INSTALL
IMPORT
SIG · DOCUMENT-NUMBER-FO
D
document-number-formatter
productivityjavascriptv1.0.33
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

formatDocumentNumber
✓ import { formatDocumentNumber } from 'document-number-formatter'
✗ const formatDocumentNumber = require('document-number-formatter').formatDocumentNumber
Named export is available; default export does not exist. Use named import for ESM or destructure require for CJS.
fdnForDate
✓ import { fdnForDate } from 'document-number-formatter'
Named export for formatting numbers based on a specific date.
formatDate
✓ import { formatDate } from 'document-number-formatter'
Named export for formatting dates in a custom pattern.

Shows how to import and use the three main functions: formatDocumentNumber for generating numbers, fdnForDate for date-specific formatting, and formatDate for date-only formatting.

import { formatDocumentNumber, fdnForDate, formatDate } from 'document-number-formatter'; // Format with value and padding const result1 = formatDocumentNumber('INV/[YYYY]/[MM]/[val:size:6]', 123); console.log(result1); // e.g., INV/2023/11/000123 // Format with fiscal year const result2 = formatDocumentNumber('DNF/[YY=apr]-[YY+1=apr]/[val:size:5]', 42, 5, 'apr'); console.log(result2); // e.g., DNF/23-24/00042 // Format with date object const result3 = fdnForDate(new Date('2021-03-01'), 'BNO/[YYYY]/[MMM]/[val]', 789, 4); console.log(result3); // e.g., BNO/2021/MAR/0789 // Format date directly const result4 = formatDate('DD/MM/YYYY', '4', new Date('2020-03-28')); console.log(result4); // 28/03/2020
Debug
Known issues
gotchaThe [date:YYYY] format is removed in version 1.0.0. Use [YYYY] instead.
fix
Replace [date:YYYY] with [YYYY] in your pattern strings.
affects: >=1.0.0
gotchaThe val:size parameter has a maximum padding of 10 digits. Values larger than 9999999999 will overflow and produce incorrect output.
fix
Ensure the numeric value does not exceed the padding size (max 10). Use a larger format or split the value.
affects: >=1.0.0
gotchaFiscal year start month must be provided as a three-letter abbreviation (e.g., 'apr', 'jan'). Invalid abbreviations cause unexpected behavior.
fix
Use one of the recognized month abbreviations: jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: formatDocumentNumber is not a function
Attempting default import instead of named import.
fix
Use import { formatDocumentNumber } from 'document-number-formatter' instead of import formatDocumentNumber from 'document-number-formatter'.
Error: Invalid format string: unmatched bracket
Format string contains a ']' without a matching '['.
fix
Ensure every '[' has a corresponding ']'. To include a literal ']', do not use a preceding '['.
Error: Unknown format token: [date:YYYY]
Using the deprecated [date:YYYY] syntax removed in v1.0.0.
fix
Replace [date:YYYY] with [YYYY].
Upgrade
Version history
1.0.33latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
38 hits · last 30 days
node
34
Amazon
1
OpenAI (training)
1
Resources
document-number-formatter — npm install document-number-formatter · libregistry