-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from FSolM/dev
dev Pull Request
- Loading branch information
Showing
7 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# cDate Formatting | ||
### Classic Date Formatting for JavaScript | ||
|
||
This `npm` module focuses on the date formatting of the `new Date()` JS object. It parses the result to a legible `string` state for both data manipulation and display. | ||
|
||
**Currently it only parses the current date.** | ||
|
||
## Usage & Installation | ||
|
||
To use this module install it with either `npm` | ||
|
||
``` | ||
$ npm i cdate-formatting | ||
``` | ||
|
||
Or `yarn` | ||
|
||
``` | ||
$ yarn add cdate-formatting | ||
``` | ||
|
||
To use `cdate`, import it to your project | ||
|
||
```javascript | ||
import cdate from 'cdate-formatting'; | ||
|
||
const date = cdate(); | ||
// returns 'Feb 24 2020' as a string | ||
``` | ||
|
||
By default, `cdate` will return the current date in format *mm/dd/yy*, you can pass the function a string specifying the date order; it supports: | ||
|
||
- mm/dd/yy | ||
- dd/mm/yy | ||
- yy/mm/dd | ||
- yy/dd/mm | ||
|
||
You can also specify if you want a compact date and the full date passing an object with the attributes `compact` & `fullDate` as booleans. | ||
|
||
```javascript | ||
const nonCompactDate = cdate('mm/dd/yy', { compact: false, fullDate: false }); | ||
// February 24 2020 | ||
|
||
const compactFullDate = cdate('mm/dd/yy', { compact: true, fullDate: true }); | ||
// Mon, Feb 24 2020 | ||
|
||
const nonCompactFullDate = cdate('mm/dd/yy', { compact: false, fullDate: true }); | ||
// Monday, February 24 2020 | ||
``` | ||
|
||
If either the `format` of the date, or the `options` are wrong in some way, `cdate` will return `undefined` | ||
|
||
#### Created by: | ||
|
||
Carlos Sol: [@FSolM](https://github.com/FSolM) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./lib/cdate'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
import formatter from './helpers/formatter'; | ||
import getDays from './helpers/days'; | ||
|
||
export default (format = 'mm/dd/yy', options = { compact: true, fullDate: false }) => { | ||
if (typeof options.compact !== 'boolean' || typeof options.fullDate !== 'boolean') { | ||
console.error('You can only pass booleans in the options object'); | ||
return undefined; | ||
} | ||
format.toLowerCase(); | ||
const d = new Date().toString().split(' '); | ||
let date = formatter(d, format, options); | ||
if (options.fullDate) { | ||
return `${options.compact ? d[0] : getDays(d[0], true)}, ${date}`; | ||
} else { | ||
return date; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
const longDays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']; | ||
|
||
export default (monthString) => { | ||
switch (monthString) { | ||
case 'Mon': | ||
return longDays[0]; | ||
case 'Tue': | ||
return longDays[1]; | ||
case 'Wed': | ||
return longDays[2]; | ||
case 'Thu': | ||
return longDays[3]; | ||
case 'Fri': | ||
return longDays[4]; | ||
case 'Sat': | ||
return longDays[5]; | ||
case 'Sun': | ||
return longDays[6]; | ||
default: | ||
console.error("Couldn't convert Days to string"); | ||
return undefined; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
import getMonths from './months'; | ||
|
||
export default (d, format, compact) => { | ||
switch (format) { | ||
case 'mm/dd/yy': | ||
return `${compact ? d[1] : getMonths(d[1])} ${d[2]} ${d[3]}`; | ||
case 'dd/mm/yy': | ||
return `${d[2]} ${compact ? d[1] : getMonths(d[1])} ${d[3]}`; | ||
case 'yy/mm/dd': | ||
return `${d[3]} ${d[2]} ${compact ? d[1] : getMonths(d[1])}`; | ||
case 'yy/dd/mm': | ||
return `${d[3]} ${compact ? d[1] : getMonths(d[1])} ${d[2]}`; | ||
default: | ||
console.error('Seems like the date format is wrong'); | ||
return undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
const longMonths = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; | ||
|
||
export default (monthString) => { | ||
switch (monthString) { | ||
case 'Jan': | ||
return longMonths[0]; | ||
case 'Feb': | ||
return longMonths[1]; | ||
case 'Mar': | ||
return longMonths[2]; | ||
case 'Apr': | ||
return longMonths[3]; | ||
case 'May': | ||
return longMonths[4]; | ||
case 'Jun': | ||
return longMonths[5]; | ||
case 'Jul': | ||
return longMonths[6]; | ||
case 'Agu': | ||
return longMonths[7]; | ||
case 'Sep': | ||
return longMonths[8]; | ||
case 'Oct': | ||
return longMonths[9]; | ||
case 'Nov': | ||
return longMonths[10]; | ||
case 'Dic': | ||
return longMonths[11]; | ||
default: | ||
console.error("Couldn't convert Months to string"); | ||
return undefined; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "cdate-formatting", | ||
"version": "0.5.6", | ||
"description": "A simple Node package library for quick JS Date formatting", | ||
"main": "index.js", | ||
"type": "module", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/FSolM/cdate-formatting.git" | ||
}, | ||
"keywords": [ | ||
"Date Formatter", | ||
"Javascript Formatter", | ||
"Javascript Date Formatter" | ||
], | ||
"author": "FSolM <[email protected]>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/FSolM/cdate-formatting/issues" | ||
}, | ||
"homepage": "https://github.com/FSolM/cdate-formatting#readme" | ||
} |