-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,318 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,94 @@ | ||
[](https://opensource.org/licenses/MIT) | ||
[](https://www.npmjs.com/package/birthgem) | ||
|
||
# Birthgem | ||
|
||
Determines the birthstones from the given month, day of the week or zodiac sign. | ||
|
||
*This is based on ekimng's [package](https://github.com/ekimng/birthstone).* | ||
|
||
## Installation | ||
|
||
You have to add this module to your NPM folder. | ||
|
||
```bash | ||
$ npm install birthgem | ||
``` | ||
|
||
## Example | ||
|
||
### Importing the module | ||
|
||
```js | ||
const acKeijiban = require('birthgem')('en'); | ||
// Require with a language (format xx-YY) sets 'en'(format xx) | ||
const acKeijiban = require('birthgem')('en-US') | ||
// Require without an argument sets 'en' | ||
const acKeijiban = require('birthgem')(); | ||
``` | ||
|
||
*The stone names and zodiac signs names can be displayed in different languages.* | ||
|
||
### Displaying a month birthstone | ||
|
||
```js | ||
// Returns the birthstone of the present month | ||
console.log(birthgem.month()); | ||
// Returns the birthstone of January (values: [1;12]) | ||
console.log(birthgem.month(1)); | ||
// Overload the default language | ||
console.log(birthgem.month(1, 'fr')); | ||
``` | ||
|
||
### Displaying a day of the week birthstone | ||
|
||
```js | ||
// Returns the birthstone of the present day | ||
console.log(birthgem.day()); | ||
// Returns the birthstone of Monday (values: [1;7]) | ||
console.log(birthgem.day(1)); | ||
// Overloads the default language | ||
console.log(birthgem.day(1, 'fr')); | ||
``` | ||
|
||
### Displaying a zodiac sign birthstone | ||
|
||
```js | ||
// Returns the birthstone of the present day | ||
console.log(birthgem.zodiac()); | ||
// Returns the birthstone of Monday (values: zodiac signs names and symbols) | ||
console.log(birthgem.zodiac('aries')); | ||
console.log(birthgem.zodiac('♈'); | ||
// Overload the default language | ||
console.log(birthgem.zodiac(1, 'fr')); | ||
``` | ||
## Error management | ||
An integer is returned if the given parameter is wrong: | ||
| Type | Values | Error code | | ||
|--------|--------------------------------|------------| | ||
| Day | [1;7] | -1 | | ||
| Month | [1;12] | -2 | | ||
| Zodiac | zodiac signs names and symbols | -3 | | ||
## Translation | ||
For the moment, the only avaible languages are English and French. | ||
Obviously, you are free to participate to the translation in any other language. | ||
### Avaible languages | ||
- English | ||
- French | ||
## Thanks | ||
Thanks to ekimng for the original package: [birthstone](https://github.com/ekimng/birthstone). | ||
## License | ||
- My source code is published under [MIT License](https://github.com/Helmasaur/ac-keijiban/blob/master/LICENSE). | ||
- The original package is published under [MIT License](https://github.com/ekimng/birthstone/blob/master/LICENSE). |
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,114 @@ | ||
|
||
module.exports = defaultLanguage => { // Language format (xx-YY) verification | ||
|
||
return { | ||
month: (month = new Date().getMonth() + 1, language = defaultLanguage) => { | ||
return getGems(parseMonth(month), 'month', parseLanguage(language)); | ||
}, | ||
day: (day = new Date().getDay() + 1, language = defaultLanguage) => { | ||
return getGems(parseDay(day), 'day', parseLanguage(language)); | ||
}, | ||
zodiac: (sign, language = defaultLanguage) => { | ||
language = parseLanguage(language); | ||
return getGems(parseZodiac(sign, language), 'zodiac', language) | ||
} | ||
} | ||
} | ||
|
||
const getGems = (date, namespace, language) => { | ||
let gemsData; | ||
try { | ||
gemsData = require(`./locales/${language}/birthstones_${namespace}.json`); | ||
} | ||
catch { | ||
gemsData = require(`./locales/en/birthstones_${namespace}.json`); | ||
} | ||
|
||
// Error code | ||
if (date < 0) { | ||
return date; | ||
} | ||
|
||
return Object.values(gemsData)[date]; | ||
} | ||
|
||
const parseMonth = month => { | ||
// January: 1; December: 12 | ||
if (!Number.isInteger(month) || month === null || month < 1 || month > 12) { | ||
return -1; | ||
} | ||
return month - 1; | ||
} | ||
|
||
const parseDay = day => { | ||
// Monday: 1; Sunday: 7 | ||
if (!Number.isInteger(day) || day < 1 || day > 7) { | ||
return -2; | ||
} | ||
return day - 1; | ||
} | ||
|
||
const parseZodiac = (sign, language) => { | ||
if (typeof sign !== 'string' || typeof sign === 'undefined' || sign === null) { | ||
return -3; | ||
} | ||
|
||
let astrologyData; | ||
try { | ||
astrologyData = require(`./locales/${language}/astrology.json`); | ||
} | ||
catch { | ||
astrologyData = require('./locales/en/astrology.json'); | ||
} | ||
|
||
switch (sign.toLowerCase()) { | ||
case Object.values(astrologyData)[0]: | ||
case '♈': | ||
return 0; | ||
case Object.values(astrologyData)[1]: | ||
case '♉': | ||
return 1; | ||
case Object.values(astrologyData)[2]: | ||
case '♊': | ||
return 2; | ||
case Object.values(astrologyData)[3]: | ||
case '♋': | ||
return 3; | ||
case Object.values(astrologyData)[4]: | ||
case '♌': | ||
return 4; | ||
case Object.values(astrologyData)[5]: | ||
case '♍': | ||
return 5; | ||
case Object.values(astrologyData)[6]: | ||
case '♎': | ||
return 6; | ||
case Object.values(astrologyData)[7]: | ||
case '♏': | ||
return 7; | ||
case Object.values(astrologyData)[8]: | ||
case '♐': | ||
return 8; | ||
case Object.values(astrologyData)[9]: | ||
case '♑': | ||
return 9; | ||
case Object.values(astrologyData)[10]: | ||
case '♒': | ||
return 10; | ||
case Object.values(astrologyData)[11]: | ||
case '♓': | ||
return 11; | ||
default: | ||
return -3; | ||
} | ||
} | ||
|
||
const parseLanguage = language => { | ||
const regex = new RegExp('^[a-z]{2}(-[A-Z]{2})?$'); // xx-YY | ||
|
||
if (regex.test(language)) { | ||
language = language.substring(0, 2); | ||
} | ||
|
||
return language; | ||
} |
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,14 @@ | ||
{ | ||
"0": "aries", | ||
"1": "taurus", | ||
"2": "gemini", | ||
"3": "cancer", | ||
"4": "leo", | ||
"5": "virgo", | ||
"6": "libra", | ||
"7": "scorpio", | ||
"8": "sagittarus", | ||
"9": "capricorn", | ||
"10": "aquarius", | ||
"11": "pisces" | ||
} |
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,9 @@ | ||
{ | ||
"monday": ["pearl", "crystal"], | ||
"tuesday": ["ruby", "emerald"], | ||
"wednesday": ["amethyst", "lodestone"], | ||
"thursday": ["sapphire", "carnelian"], | ||
"friday": ["emerald", "cat's eye"], | ||
"saturday": ["turquoise", "diamond"], | ||
"sunday": ["topaz", "diamond"] | ||
} |
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,14 @@ | ||
{ | ||
"january": ["garnet"], | ||
"february": ["amethyst"], | ||
"march": ["aquamarine", "bloodstone"], | ||
"april": ["diamond"], | ||
"may": ["emerald"], | ||
"june": ["alexandrite", "moonstone", "pearl"], | ||
"july": ["ruby"], | ||
"august": ["peridot", "sardonyx", "spinel"], | ||
"september": ["sapphire"], | ||
"october": ["opal", "tourmaline"], | ||
"november": ["citrine", "topaz"], | ||
"december": ["tanzanite", "turquoise", "zircon"] | ||
} |
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,14 @@ | ||
{ | ||
"aries": ["bloodstone"], | ||
"taurus": ["sapphire"], | ||
"gemini": ["agate"], | ||
"cancer": ["emerald"], | ||
"leo": ["onyx"], | ||
"virgo": ["carnelian"], | ||
"libra": ["chrysolite"], | ||
"scorpio": ["beryl"], | ||
"sagittarus": ["topaz"], | ||
"capricorn": ["ruby"], | ||
"aquarius": ["garnet"], | ||
"pisces": ["amethyst"] | ||
} |
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,14 @@ | ||
{ | ||
"0": "bélier", | ||
"1": "taureau", | ||
"2": "gémaux", | ||
"3": "cancer", | ||
"4": "lion", | ||
"5": "vierge", | ||
"6": "balance", | ||
"7": "scorpion", | ||
"8": "sagittaire", | ||
"9": "capricorne", | ||
"10": "verseau", | ||
"11": "poissons" | ||
} |
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,9 @@ | ||
{ | ||
"monday": ["perle", "cristal"], | ||
"tuesday": ["rubis", "émeraude"], | ||
"wednesday": ["améthyste", "magnétite"], | ||
"thursday": ["saphir", "cornaline"], | ||
"friday": ["émeraude", "œil-de-chat"], | ||
"saturday": ["turquoise", "diamant"], | ||
"sunday": ["topaze", "diamant"] | ||
} |
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,14 @@ | ||
{ | ||
"january": ["grenat"], | ||
"february": ["améthyste"], | ||
"march": ["aquamarine", "héliotrope"], | ||
"april": ["diamant"], | ||
"may": ["émeraude"], | ||
"june": ["alexandrite", "pierre de lune", "perle"], | ||
"july": ["rubis"], | ||
"august": ["péridot", "sardonyx", "spinel"], | ||
"september": ["saphir"], | ||
"october": ["opale", "tourmaline"], | ||
"november": ["citrine", "topaze"], | ||
"december": ["tanzanite", "turquoise", "zircon"] | ||
} |
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,14 @@ | ||
{ | ||
"aries": ["héliotrope"], | ||
"taurus": ["saphir"], | ||
"gemini": ["agate"], | ||
"cancer": ["émeraude"], | ||
"leo": ["onyx"], | ||
"virgo": ["cornaline"], | ||
"libra": ["chrysolite"], | ||
"scorpio": ["béryl"], | ||
"sagittarus": ["topaze"], | ||
"capricorn": ["rubis"], | ||
"aquarius": ["grenat"], | ||
"pisces": ["améthyste"] | ||
} |
Oops, something went wrong.