DEV Community

Mohamed Safouan Besrour
Mohamed Safouan Besrour

Posted on

Get the Zodiac Sign for a date in JavaScript

Get the Zodiac Sign for a date in JavaScript<br>
I created this little library to provide a zodiac sign & chinese zodiac sign depending on a birthday using The Intl.DateTimeFormat object.

You can install the library via jsDeliver CDN

<script src="https://cdn.jsdelivr.net/gh/besrourms/zodiacsigns@latest/index.min.js"></script>
Enter fullscreen mode Exit fullscreen mode

Getting a zodiac sign from a date

// Return 'Sagittarius: The Archer'
console.log(new ZodiacSign('1991-11-30').sign)
Enter fullscreen mode Exit fullscreen mode

Getting a chinese zodiac sign from a date

// Return 'Fire Rat'
console.log(new ZodiacSign('1 Feb 1997 00:12:00 GMT').chinese)
Enter fullscreen mode Exit fullscreen mode

Getting a sign with translation

// Overload the default language (format xx)
console.log(new ZodiacSign('1 Feb 1997 00:12:00 GMT', 'ar').chinese);
Enter fullscreen mode Exit fullscreen mode

Translation

For the moment, the only available languages are English, French, Spanish and Arabic.
Fell free to participate to the translation in any other language.

Available languages

  • English (en)
  • French (fr)
  • Spanish (es)
  • Arabic (ar)

GitHub logo BesrourMS / ZodiacSigns

Get the Zodiac Sign / Chinese Zodiac Sign for a date in JavaScript

License: MIT

Zodiac Signs / Chinese Zodiac Signs

Provides a zodiac sign & chinese zodiac sign depending a birthday

Installation

<script src="https://cdn.jsdelivr.net/gh/besrourms/zodiacsigns@latest/index.min.js"></script>
Enter fullscreen mode Exit fullscreen mode

Examples

Getting a zodiac sign from a date

// Return 'Sagittarius: The Archer'
console.log(new ZodiacSign('1991-11-30').sign)
Enter fullscreen mode Exit fullscreen mode

Getting a chinese zodiac sign from a date

// Return 'Fire Rat'
console.log(new ZodiacSign('1 Feb 1997 00:12:00 GMT').chinese)
Enter fullscreen mode Exit fullscreen mode

Getting a sign with translation

// Overload the default language (format xx)
console.log(new ZodiacSign('1 Feb 1997 00:12:00 GMT', 'ar').chinese);
Enter fullscreen mode Exit fullscreen mode

Translation

For the moment, the only available languages are English, French, Spanish, Arabic, Ukrainian and Chinese Fell free to participate to the translation in any other language.

Available languages

  • English (en)
  • French (fr)
  • Spanish (es)
  • Arabic (ar)
  • Ukrainian…

Top comments (0)