Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ We provide security updates and support for the latest stable release of the 'no
If you discover a security vulnerability within the project, we encourage you to report it the maintainers immediately. Promptly reporting security issues helps us protect our users and take appropriate actions to address the vulnerability. To report a security vulnerability, please follow these steps:

1. Email at aj3sshh@gmail.com or sugatbajracharya49@gmail.com with a detailed description of the vulnerability. Please include the following information:

- Description of the vulnerability, including steps to reproduce if applicable
- Version of the node-nepali-datetime package affected
- Any potential mitigations or workarounds
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
node-version: [18, 20, 22]
node-version: [22, 24]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 22
node-version: 24
registry-url: 'https://registry.npmjs.org'
if: ${{ steps.release.outputs.release_created }}

Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{".":"1.5.0"}
{".":"2.0.0"}
4 changes: 0 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ To set up the project on your local machine, follow these steps:
```

4. **Verify your setup**:

- Run the example script to test the library:

```bash
Expand Down Expand Up @@ -72,7 +71,6 @@ We welcome and appreciate pull requests from the community. To contribute:
2. **Write tests** for your changes if applicable.
3. **Follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)** for commit messages.
Examples:

- `feat: add JSON parser`
- `fix(parser): resolve parsing issue`

Expand All @@ -83,12 +81,10 @@ We welcome and appreciate pull requests from the community. To contribute:
```

5. **Create a Pull Request**:

- Open a pull request from your branch to the `main` branch of the original repository.
- Provide a clear and concise description of the changes, along with relevant context.

6. **Review & Feedback**:

- Participate in the code review process and address any feedback promptly.

## License
Expand Down
5,691 changes: 2,735 additions & 2,956 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nepali-datetime",
"version": "1.5.0",
"version": "2.0.0",
"description": "A Node project designed to support native JavaScript-like features for Nepali dates. It includes features such as 'NepaliDate' for Nepali date support and 'dateConverter' for date conversions.",
"exports": {
".": {
Expand Down Expand Up @@ -58,21 +58,21 @@
"author": "OpenSource Nepal",
"license": "GPL-3.0",
"devDependencies": {
"@commitlint/cli": "^19.6.1",
"@commitlint/config-conventional": "^19.6.0",
"@types/jest": "^29.5.4",
"@types/node": "^22.10.2",
"@commitlint/cli": "^20.4.0",
"@commitlint/config-conventional": "^20.4.0",
"@types/jest": "^30.0.0",
"@types/node": "^25.1.0",
"husky": "^9.1.7",
"jest": "^29.7.0",
"lint-staged": "^15.2.11",
"prettier": "^3.4.2",
"ts-jest": "^29.2.5",
"jest": "^30.2.0",
"lint-staged": "^16.2.7",
"prettier": "^3.8.1",
"ts-jest": "^29.4.6",
"ts-node": "^10.9.2",
"tslib": "^2.8.1",
"typescript": "^5.7.2",
"unbuild": "^3.0.1"
"typescript": "^5.9.3",
"unbuild": "^3.6.1"
},
"engines": {
"node": ">=18"
"node": ">=22"
}
}
53 changes: 40 additions & 13 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const OLD_UTC_OFFSET_IN_MS = 19800000 // 5 hours 40 minutes in ms
export const TIMEZONE_TRANSITION_TIMESTAMP = 504901800000
export const TIMEZONE_TRANSITION_DATE_REFERENCE = new Date(1986, 0, 1, 0, 15)

export const NEPALI_MONTHS_EN = [
export const NEPALI_MONTHS_EN: readonly string[] = [
'Baisakh',
'Jestha',
'Asar',
Expand All @@ -26,7 +26,7 @@ export const NEPALI_MONTHS_EN = [
'Chaitra',
]

export const NEPALI_MONTHS_SHORT_EN = [
export const NEPALI_MONTHS_SHORT_EN: readonly string[] = [
'Bai',
'Jes',
'Asa',
Expand All @@ -41,7 +41,7 @@ export const NEPALI_MONTHS_SHORT_EN = [
'Cha',
]

export const NEPALI_MONTHS_NE = [
export const NEPALI_MONTHS_NE: readonly string[] = [
'बैशाख',
'जेठ',
'असार',
Expand All @@ -56,7 +56,7 @@ export const NEPALI_MONTHS_NE = [
'चैत्र',
]

export const NEPALI_MONTHS_SHORT_NE = [
export const NEPALI_MONTHS_SHORT_NE: readonly string[] = [
'बै',
'जे',
'अ',
Expand All @@ -71,7 +71,7 @@ export const NEPALI_MONTHS_SHORT_NE = [
'चै',
]

export const ENGLISH_MONTHS_EN = [
export const ENGLISH_MONTHS_EN: readonly string[] = [
'January',
'February',
'March',
Expand All @@ -86,7 +86,7 @@ export const ENGLISH_MONTHS_EN = [
'December',
]

export const ENGLISH_MONTHS_SHORT_EN = [
export const ENGLISH_MONTHS_SHORT_EN: readonly string[] = [
'Jan',
'Feb',
'Mar',
Expand All @@ -101,7 +101,7 @@ export const ENGLISH_MONTHS_SHORT_EN = [
'Dec',
]

export const ENGLISH_MONTHS_NE = [
export const ENGLISH_MONTHS_NE: readonly string[] = [
'जनवरी',
'फेब्रुअरी',
'मार्च',
Expand All @@ -116,7 +116,7 @@ export const ENGLISH_MONTHS_NE = [
'डिसेम्बर',
]

export const ENGLISH_MONTHS_SHORT_NE = [
export const ENGLISH_MONTHS_SHORT_NE: readonly string[] = [
'जन',
'फेब',
'मार',
Expand All @@ -131,11 +131,30 @@ export const ENGLISH_MONTHS_SHORT_NE = [
'डिसे',
]

export const NUM_NE = ['०', '१', '२', '३', '४', '५', '६', '७', '८', '९']
export const NUM_NE: readonly string[] = [
'०',
'१',
'२',
'३',
'४',
'५',
'६',
'७',
'८',
'९',
]

export const WEEKDAYS_SHORT_EN = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
export const WEEKDAYS_SHORT_EN: readonly string[] = [
'Sun',
'Mon',
'Tue',
'Wed',
'Thu',
'Fri',
'Sat',
]

export const WEEKDAYS_LONG_EN = [
export const WEEKDAYS_LONG_EN: readonly string[] = [
'Sunday',
'Monday',
'Tuesday',
Expand All @@ -145,9 +164,17 @@ export const WEEKDAYS_LONG_EN = [
'Saturday',
]

export const WEEKDAYS_SHORT_NE = ['आइत', 'सोम', 'मंगल', 'बुध', 'बिहि', 'शुक्र', 'शनि']
export const WEEKDAYS_SHORT_NE: readonly string[] = [
'आइत',
'सोम',
'मंगल',
'बुध',
'बिहि',
'शुक्र',
'शनि',
]

export const WEEKDAYS_LONG_NE = [
export const WEEKDAYS_LONG_NE: readonly string[] = [
'आइतबार',
'सोमबार',
'मंगलबार',
Expand Down
10 changes: 6 additions & 4 deletions src/dateConverter/constants.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// Reference date for conversion is 2000/01/01 BS and 1943/4/14 AD
export const NP_INITIAL_YEAR = 2000
export const REFERENCE_EN_DATE: [number, number, number] = [1943, 4, 14]
export const REFERENCE_EN_DATE: readonly [number, number, number] = [1943, 4, 14]

// English month constant data (will never change)
export const EN_MONTHS: number[] = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
export const EN_LEAP_YEAR_MONTHS: number[] = [
export const EN_MONTHS: readonly number[] = [
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
]
export const EN_LEAP_YEAR_MONTHS: readonly number[] = [
31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
] // Leap year months (Just 29 on Feb)

// Nepali months data
export const NP_MONTHS_DATA: Array<[number[], number]> = [
export const NP_MONTHS_DATA: ReadonlyArray<readonly [readonly number[], number]> = [
[[30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], 365], // 2000 BS - 1943/1944 AD
[[31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], 365], // 2001 BS
[[31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], 365],
Expand Down
4 changes: 2 additions & 2 deletions src/dateConverter/dateConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const _isLeapYear = (year: number): boolean => {
* @param year - The year for which to retrieve the months.
* @returns An array containing the number of days in each month of the year.
*/
const _getEnMonths = (year: number): number[] => {
const _getEnMonths = (year: number): readonly number[] => {
return _isLeapYear(year) ? EN_LEAP_YEAR_MONTHS : EN_MONTHS
}

Expand Down Expand Up @@ -308,7 +308,7 @@ const nepaliToEnglish = (

// MONTH
// Incrementing month until the difference remains less than next english month (mostly 31)
const month_days: number[] = _getEnMonths(en_year)
const month_days: readonly number[] = _getEnMonths(en_year)
let i = 0
while (difference >= month_days[i]) {
difference -= month_days[i]
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const parseFormatTokens = (format: string): string[] => {
*
* @param toConvert - An array of string containing all the required regex values
*/
export const seqToRE = (toConvert: Array<string>): RegExp => {
export const seqToRE = (toConvert: readonly string[]): RegExp => {
// returns /(?:)/ regex for empty array
if (toConvert.length === 0) {
return new RegExp('')
Expand Down
26 changes: 12 additions & 14 deletions tests/NepaliDate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ describe('NepaliDate with Time feature initialization', () => {

expect(() => {
const _ = new NepaliDate(year, month, day, hour, minute, second, ms)
}).toThrowError(new ValidationError('Hour should be in the range 0-23'))
}).toThrow(new ValidationError('Hour should be in the range 0-23'))
})

it('should throw a ValidationError for invalid negative hour', () => {
Expand All @@ -367,7 +367,7 @@ describe('NepaliDate with Time feature initialization', () => {

expect(() => {
const _ = new NepaliDate(year, month, day, hour, minute, second, ms)
}).toThrowError(new ValidationError('Hour should be in the range 0-23'))
}).toThrow(new ValidationError('Hour should be in the range 0-23'))
})

it('should throw a ValidationError for invalid minute', () => {
Expand All @@ -379,7 +379,7 @@ describe('NepaliDate with Time feature initialization', () => {

expect(() => {
const _ = new NepaliDate(year, month, day, hour, minute, second, ms)
}).toThrowError(new ValidationError('Minute should be in the range 0-59'))
}).toThrow(new ValidationError('Minute should be in the range 0-59'))
})

it('should throw a ValidationError for invalid negative minute', () => {
Expand All @@ -391,7 +391,7 @@ describe('NepaliDate with Time feature initialization', () => {

expect(() => {
const _ = new NepaliDate(year, month, day, hour, minute, second, ms)
}).toThrowError(new ValidationError('Minute should be in the range 0-59'))
}).toThrow(new ValidationError('Minute should be in the range 0-59'))
})

it('should throw a ValidationError for invalid second', () => {
Expand All @@ -403,7 +403,7 @@ describe('NepaliDate with Time feature initialization', () => {

expect(() => {
const _ = new NepaliDate(year, month, day, hour, minute, second, ms)
}).toThrowError(new ValidationError('Second should be in the range 0-59'))
}).toThrow(new ValidationError('Second should be in the range 0-59'))
})

it('should throw a ValidationError for invalid negative second', () => {
Expand All @@ -415,7 +415,7 @@ describe('NepaliDate with Time feature initialization', () => {

expect(() => {
const _ = new NepaliDate(year, month, day, hour, minute, second, ms)
}).toThrowError(new ValidationError('Second should be in the range 0-59'))
}).toThrow(new ValidationError('Second should be in the range 0-59'))
})

it('should throw a ValidationError for invalid millisecond', () => {
Expand All @@ -427,7 +427,7 @@ describe('NepaliDate with Time feature initialization', () => {

expect(() => {
const _ = new NepaliDate(year, month, day, hour, minute, second, ms)
}).toThrowError(new ValidationError('Millisecond should be in the range 0-999'))
}).toThrow(new ValidationError('Millisecond should be in the range 0-999'))
})

it('should throw a ValidationError for invalid negative millisecond', () => {
Expand All @@ -439,7 +439,7 @@ describe('NepaliDate with Time feature initialization', () => {

expect(() => {
const _ = new NepaliDate(year, month, day, hour, minute, second, ms)
}).toThrowError(new ValidationError('Millisecond should be in the range 0-999'))
}).toThrow(new ValidationError('Millisecond should be in the range 0-999'))
})

// timezone support
Expand Down Expand Up @@ -680,7 +680,7 @@ describe('NepaliDate with Time feature: set methods', () => {
const invalidHour = 24
expect(() => {
nepaliDate.setHours(invalidHour)
}).toThrowError(new ValidationError('Hour should be in the range 0-23'))
}).toThrow(new ValidationError('Hour should be in the range 0-23'))
})
})

Expand All @@ -696,7 +696,7 @@ describe('NepaliDate with Time feature: set methods', () => {
const invalidMinute = 60
expect(() => {
nepaliDate.setMinutes(invalidMinute)
}).toThrowError(new ValidationError('Minute should be in the range 0-59'))
}).toThrow(new ValidationError('Minute should be in the range 0-59'))
})
})

Expand All @@ -712,7 +712,7 @@ describe('NepaliDate with Time feature: set methods', () => {
const invalidSecond = 60
expect(() => {
nepaliDate.setSeconds(invalidSecond)
}).toThrowError(new ValidationError('Second should be in the range 0-59'))
}).toThrow(new ValidationError('Second should be in the range 0-59'))
})
})

Expand All @@ -728,9 +728,7 @@ describe('NepaliDate with Time feature: set methods', () => {
const invalidMillisecond = 1000
expect(() => {
nepaliDate.setMilliseconds(invalidMillisecond)
}).toThrowError(
new ValidationError('Millisecond should be in the range 0-999')
)
}).toThrow(new ValidationError('Millisecond should be in the range 0-999'))
})
})

Expand Down
Loading