abbrev-weekday-range
v1.0.0
Published
Utility method to abbreviate a range of weekdays
Downloads
399
Maintainers
Readme
abbrev-weekday-range
Utility method for abbreviating an array of numeric days of the week.
Installation
Install using npm:
$ npm install abbrev-weekday-range
Usage
Note: This function assumes the array of weekdays given contain the values 0 through 6 (0 = Sunday), are in ascending order, and contain no duplicates.
var abbrevDays = require('abbrev-weekday-range');
abbrevDays([1, 2, 3, 4, 5]); // 'Mon-Fri'
abbrevDays([0, 6]); // 'Sun, Sat'
abbrevDays([1, 2, 3, 5]); // 'Mon-Wed, Fri'
abbrevDays([1, 2, 3, 4, 5], { format: 'narrow' }); // 'M-F'
abbrevDays([1, 2, 3, 4, 5], { format: 'long' }); // 'Monday-Friday'
Options
format
(default: short)
Format to use when generating range. Supported formats:
- "narrow" ("S", "M", "T", "W", "T", "F", "S")
- "shorter" ("Su", "M", "Tu", "W", "Th", "F", "Sa")
- "short" ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
- "long" ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
For further customization, format
can also be specified as an array of
abbreviations, or as a function that recieves a numeric weekday and returns
a string.
License
MIT