Skip to content

Commit

Permalink
fix: set country, state as object
Browse files Browse the repository at this point in the history
  • Loading branch information
commenthol committed Mar 30, 2019
1 parent 3444a09 commit bcb427e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
18 changes: 9 additions & 9 deletions src/Data.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,17 @@ module.exports = Data
* @return {Object}
*/
Data.splitName = function (country, state, region) {
if (!country) {
return
} else if (typeof country === 'object' && country.country) {
if (typeof country === 'object' && country.country) {
return toUpperCase(country)
} else if (typeof country === 'string') {
const a = country.split(/[.-]/)
const o = {
country: a.shift(),
state: a.shift() || state,
region: a.shift() || region
}
return toUpperCase(o)
}
const o = {}
const a = country.split(/[.-]/)
o.country = a.shift()
o.state = a.shift() || state
o.region = a.shift() || region
return toUpperCase(o)
}

Data.majorLang = function (lang) {
Expand Down
3 changes: 1 addition & 2 deletions src/Holidays.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,8 @@ function getArgs (country, state, region, opts) {
} else if (typeof state === 'object') {
opts = state
state = null
} else if (typeof country === 'object') {
} else if (typeof country === 'object' && !country.country) {
opts = country
country = null
}
opts = opts || {}
return [country, state, region, opts]
Expand Down
9 changes: 9 additions & 0 deletions test/Holidays.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,15 @@ describe('#Holidays', function () {
const res = Array.from(new Set(hd.getHolidays(2018).map(i => i.type)))
assert.deepStrictEqual(res, ['public', 'observance'])
})

it('should set holidays country with object', function () {
const hd = new Holidays(fixtures.holidays,
{ country: 'au', state: 'nsw' }
)
const res = hd.getHolidays(2018)
assert.ok(res.length)
assert.ok(res[1].name === 'Australia Day')
})
})

describe('can check', function () {
Expand Down

0 comments on commit bcb427e

Please sign in to comment.