├── .gitignore ├── tea.yaml ├── src ├── lang │ ├── en.json │ └── id.json └── index.js ├── test └── index.test.js ├── package.json ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Directories 2 | node_modules/ 3 | dist/ 4 | coverage/ 5 | .cache/ 6 | 7 | # Files 8 | .env 9 | .DS_Store -------------------------------------------------------------------------------- /tea.yaml: -------------------------------------------------------------------------------- 1 | # https://tea.xyz/what-is-this-file 2 | --- 3 | version: 1.0.0 4 | codeOwners: 5 | - '0x9BAac40A197bbb110ae5B2f31342D8d15D734832' 6 | quorum: 1 7 | -------------------------------------------------------------------------------- /src/lang/en.json: -------------------------------------------------------------------------------- 1 | { 2 | "January": "January", 3 | "February": "February", 4 | "March": "March", 5 | "April": "April", 6 | "May": "May", 7 | "June": "June", 8 | "July": "July", 9 | "August": "August", 10 | "September": "September", 11 | "October": "October", 12 | "November": "November", 13 | "December": "December" 14 | } -------------------------------------------------------------------------------- /src/lang/id.json: -------------------------------------------------------------------------------- 1 | { 2 | "January": "Januari", 3 | "February": "Februari", 4 | "March": "Maret", 5 | "April": "April", 6 | "May": "Mei", 7 | "June": "Juni", 8 | "July": "Juli", 9 | "August": "Agustus", 10 | "September": "September", 11 | "October": "Oktober", 12 | "November": "November", 13 | "December": "Desember" 14 | } -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const path = require('path'); 3 | 4 | const langPath = path.join(__dirname, 'lang/'); 5 | 6 | function formatDateLanguange(date, lang, is_cut = false) { 7 | const formatDate = new Date(date); 8 | const monthName = formatDate.toLocaleString('default', { month: 'long' }); 9 | const langData = JSON.parse(fs.readFileSync(langPath + lang + '.json', 'utf8')); 10 | const monthAbbreviation = langData[monthName]; 11 | var cutmonthAbbreviation = monthAbbreviation; 12 | if(is_cut === true) { 13 | cutmonthAbbreviation = cutmonthAbbreviation.substring(0, 3); 14 | } 15 | return formatDate.getDate().toString().padStart(2, '0') + ' ' + cutmonthAbbreviation + ' ' + formatDate.getFullYear(); 16 | } 17 | 18 | module.exports = { formatDateLanguange }; 19 | -------------------------------------------------------------------------------- /test/index.test.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | const { formatDateLanguange } = require('../src/index'); 3 | 4 | describe('Date Formatting', function() { 5 | describe('#formatDateLanguange()', function() { 6 | it('should return date in English format in full mode', function() { 7 | const date = '2024-02-25'; 8 | assert.strictEqual(formatDateLanguange(date, 'en'), '25 February 2024'); 9 | }); 10 | it('should return date in English format in short mode', function() { 11 | const date = '2024-02-25'; 12 | assert.strictEqual(formatDateLanguange(date, 'en', true), '25 Feb 2024'); 13 | }); 14 | it('should return date in Indonesian format in full mode', function() { 15 | const date = '2024-02-25'; 16 | assert.strictEqual(formatDateLanguange(date, 'id'), '25 Februari 2024'); 17 | }); 18 | it('should return date in Indonesian format in short mode', function() { 19 | const date = '2024-02-25'; 20 | assert.strictEqual(formatDateLanguange(date, 'id', true), '25 Feb 2024'); 21 | }); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "onedionys-date-languange", 3 | "version": "5.0.0", 4 | "description": "One Dionys (Date Languange) - Package used to make it easier for developers to format dates.", 5 | "main": "src/index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/onedionys/onedionys-date-languange.git" 15 | }, 16 | "keywords": [ 17 | "onedionys", 18 | "date-languange", 19 | "format-date-id", 20 | "format-date-en" 21 | ], 22 | "author": "One Dionys", 23 | "license": "ISC", 24 | "bugs": { 25 | "url": "https://github.com/onedionys/onedionys-date-languange/issues" 26 | }, 27 | "homepage": "https://github.com/onedionys/onedionys-date-languange#readme", 28 | "dependencies": { 29 | "@types/chai": "^4.3.12", 30 | "@types/mocha": "^10.0.6", 31 | "chai": "^5.1.0", 32 | "mocha": "^10.3.0" 33 | }, 34 | "devDependencies": { 35 | "chai": "^5.1.0", 36 | "mocha": "^10.3.0" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 ONE DIONYS 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
Package used to make it easier for developers to format dates 💖
4 | 5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |