1.0.33 ā€¢ Published 3 years ago

document-number-formatter v1.0.33

Weekly downloads
2
License
ISC
Repository
github
Last release
3 years ago

šŸ“ƒ Document Number Formatter #ļøāƒ£ šŸ˜ƒ

NPM Version Minified  Size Downloads License Language Repository Build Open Source Love svg1

This package is used to generate the formatted number like 'Bill Number' or other document number similar to 'Bill Number'

Installation and Integration

Install Using npm:

npm i document-number-formatter

Integrate In Node.js program:

var { formatDocumentNumber, fdnForDate, formatDate } = require('document-number-formatter')

Integrate In Vue/React/Angular program:

import { formatDocumentNumber, fdnForDate, formatDate } from 'document-number-formatter'

Suggestion

Use with Invoice Number{:target="_blank"} package for more convenient.

Examples :

āœ“ļø Click here to view notable explanation

// [date:YYYY] format is removed
console.log(formatDocumentNumber('DNF/[YY=apr]-[YY+1=apr]/[val:size:6]', 123))
console.log(formatDocumentNumber('BNO/[val]/[YY]-[YY+1]', 546, 8, 'apr'))
console.log(formatDocumentNumber('DNF/[YYYY=jan]/[MM]/[val]', 789, 5))
console.log(formatDocumentNumber('BNO/[YYYY]/[MMM]/[v]', 432, 5, 4))
console.log(formatDocumentNumber('[YYYY' + (false ? ']-01' : '=dec]-12' ) + '-01'))
console.log(formatDocumentNumber('[D]/[DD]/[dd]/[ddd]/[dddd]/[MMMM]/[W]'))
console.log(fdnForDate('01 Mar 2021', 'DNF/[YY]-[YY+1]/[val]', 123, 4, 'apr'))
console.log(formatDate('YYYY', '4', '28 Mar 2020'))

If todays date is '01 Nov 2020'

Output :

DNF/20-21/000123
BNO/00000546/20-21
DNF/2020/11/00789
BNO/2020/NOV/00432
2019-12-01
1/01/SU/SUN/SUNDAY/NOVEMBER/45
DNF/20-21/0123
2019

Docs for formatDocumentNumber():

String between '' and '' brackets will be taken to comput the result.

If todays date is '01 Feb 2020' If you want to print '[' bracket just use it between '' and '' brackets like '[[]' If you want to print ']' bracket just use like ']', but it should not have equalent '[' bracket

TypeSample Code ForExamplesOutputDesc
CalendarYearEg. 1: YY20'YY' will convert in to current year
Eg. 2: YYYY2020'YYYY' will returns full year
Eg. 3: YY+121One year added to the current Year
Eg. 4: YY=apr19As default January is the year start if you specify year start month like in the example, given month will be taken as start month of the year, if the current month is lessthan the given month it will consider it as previous year, this function will help on producing Financial year (or) Academic year document numbers.
Eg. 5: YY=419You can specify month in number also.
Eg. 6: YY+1=jan21You can combine '+1' and 'month' in single statement like this.
Eg. 7: YY,arg4: 'jan'21You can also specify start month as common by passing month as 4th argument
Eg. 8: YY,arg4: 121You can also specify start month as common by passing month as 4th argument as interger
Eg. 9: YY,arg4: '1'21You can also specify start month as common by passing month as 4th argument as string with interger value
CalendarMonthEg. 1: M2It will returns current month as one digit numerical format
Eg. 2: MM02It will returns current month as 2 digit numerical format
Eg. 3: MMMFEBIt will returns month as 3 character alphabetic format
Eg. 4: MMMMFEBRUARYIt will returns month as full name
CalendarWeekEg. 1: W5It will returns current week number as one digit numerical format
Eg. 2: WW05It will returns current week number as two digit numerical format
CalendarDateEg. 1: D1It will returns current date in one character
Eg. 2: DD01It will returns current date in two characters
CalendarDayEg. 1: ddSAIt will returns current week day in 2 character format
Eg. 2: ddd or DDDSATIt will returns current week day in 3 character format
Eg. 3: dddd or DDDDSATURDAYIt will returns current week day in full name
ValueValueEg. 1: val:size:5,arg2: 12300123It will leftpad two '0's to the value passed as second argument to maintain value size.
Eg. 2: val:size:8,arg2: 78900000789It will leftpad five '0's if value's size is 3.
Eg. 3: val or v,arg2: 789,arg3: 800000789It will leftpad '0's to the value by the size passed as third argument
Default value
Argsarg1: format (mandantory)Eg. 1: 'YY=apr'first arugment is format
arg2: value (optional)Eg. 1: 123'' (Empty String)second argument is value to format
Eg. 2: '456'value can be number or string. This argument is optional if you dont use 'val' based format in first argument
arg3: size (optional)Eg. 1: 40Size of the value should be in number, if the value length is smaller, '0's will leftpad to the value to match the size.
arg4: month (optional)Eg. 1: 'dec' (or) 'december''jan'To specify the start month of the year, to format the number. This argument is case insensitive.
Eg. 2: 12 (or) '12'You can specify the month start as number

Docs for fdnForDate():

String between '' and '' brackets will be taken to comput the result.

You can pass your own js native date (or) date string as 1st arugment all arugments of formatDocumentNumber() can be used in this function also but it moved one step forward for example 'format'('YY') argument is 2nd argument in this function

TypeSample Code ForExamplesOutputDesc
CalendarJS DateEg. 1: (new Date(), 'YY')20If todays date is '01 Feb 2020'
Eg. 2: ('01 Feb 2020', 'WW')05or you can pass date as raw date string that can produce native JS date

Docs for formatDate():

If you want to format only the 'Calendar' based string not the value you can use this function If todays date is '01 Feb 2020'

TypeSample Code ForExamplesOutputDeafult ValueDesc
Argsarg1: format (mandantory)Eg. 1: 'YY=apr'19first arugment is format, you can use any calendar mention in 'Docs for formatDocumentNumber()' but with out '' and '' branckets, and you can use one format at a time.
arg2: month (optional)Eg. 1: 'dec', 'december', 12 or '12''jan'To specify the start month of the year, to format the number. This argument is case insensitive.
Calendararg3: currentDate (optional)Eg. 1: new Date()20new Date()If todays date is '01 Feb 2020'
Eg. 2: '01 Feb 2020'05or you can pass date as raw date string that can produce native JS date

Example and Explanation 1 :

Example :

var { formatDocumentNumber } = require('document-number-formatter')
console.log(formatDocumentNumber('DNF/[YY=apr]-[YY+1=apr]/[val:size:6]', 123))

If todays date is '28 Feb 2020'

Output :

DNF/19-20/000123

Above format 'DNF/19-20/' will continue from '01 Apr 2019' to '31 Mar 2020' and then it will turn into 'DNF/20-21/' from '01 Apr 2020'.

Explanation :

CodeExplanation
DNF/this is not in between square brackets so it printed as like given.
YY=aprthis is converted into '19'
-this character printed as same
YY+1=aprthis is converted into '20'
/this character printed as same
val:size:6this is converted into '000123' with the value of argument

Example and Explanation 2 :

Example :

var { formatDocumentNumber } = require('document-number-formatter')
console.log(formatDocumentNumber('DNF/[YY]-[YY+1]/[val]', 123, 6, 'apr'))

If todays date is '28 Feb 2020'

Output :

DNF/19-20/000123

Above format 'DNF/19-20/' will continue from '01 Apr 2019' to '31 Mar 2020' and then it will turn into 'DNF/20-21/' from '01 Apr 2020'.

Explanation :

CodeExplanation
DNF/this is not in between square brackets so it printed as like given.
YYthis is converted into '19' fourth argument month is 'apr'
-this character printed as same
YY+1this is converted into '20' fourth argument month is 'apr'
/this character printed as same
valthis is converted into '000123' with the second argument value and third argument size