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
141 changes: 141 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
## Functions

<dl>
<dt><a href="#getSignByDate">getSignByDate(date, language)</a> ⇒ <code>object</code></dt>
<dd><p>Retrieves the zodiac sign based on a given date and language.</p>
</dd>
<dt><a href="#getSignByName">getSignByName(signName, language)</a> ⇒ <code>number</code></dt>
<dd><p>Retrieves the sign object based on the given sign name and language.</p>
</dd>
<dt><a href="#getSignBySymbol">getSignBySymbol(signSymbol, language)</a> ⇒ <code>number</code></dt>
<dd><p>Retrieves the sign by its symbol.</p>
</dd>
<dt><a href="#getSymbols">getSymbols()</a> ⇒ <code>Array</code></dt>
<dd><p>Retrieves the symbols of the zodiac signs from the zodiac data.</p>
</dd>
<dt><a href="#getNames">getNames(language)</a> ⇒ <code>Array</code></dt>
<dd><p>Retrieves a list of names from the zodiac.json file based on the provided language.</p>
</dd>
<dt><a href="#getElements">getElements(language)</a> ⇒ <code>Array</code></dt>
<dd><p>Retrieves the elements data based on the specified language.</p>
</dd>
<dt><a href="#getSignByIndex">getSignByIndex(index, language)</a> ⇒ <code>string</code></dt>
<dd><p>Retrieves the sign by its index in the zodiac.json file.</p>
</dd>
<dt><a href="#getListValue">getListValue(key, data)</a> ⇒ <code>array</code></dt>
<dd><p>Returns an array of values from the given data object, based on the specified key.</p>
</dd>
<dt><a href="#getElement">getElement(sign, language)</a> ⇒ <code>Object</code></dt>
<dd><p>Retrieves the element data for a given sign and language.</p>
</dd>
</dl>

<a name="getSignByDate"></a>

## getSignByDate(date, language) ⇒ <code>object</code>
Retrieves the zodiac sign based on a given date and language.

**Kind**: global function
**Returns**: <code>object</code> - The zodiac sign corresponding to the given date and language.

| Param | Type | Description |
| --- | --- | --- |
| date | <code>object</code> | An object containing the day and month of the date. |
| language | <code>string</code> | The language of the zodiac sign to be retrieved. |

<a name="getSignByName"></a>

## getSignByName(signName, language) ⇒ <code>number</code>
Retrieves the sign object based on the given sign name and language.

**Kind**: global function
**Returns**: <code>number</code> - The sign object corresponding to the given name and language. Returns -2 if the signName is null or not a string.

| Param | Type | Description |
| --- | --- | --- |
| signName | <code>string</code> | The name of the sign to retrieve. |
| language | <code>string</code> | The language in which to retrieve the sign. |

<a name="getSignBySymbol"></a>

## getSignBySymbol(signSymbol, language) ⇒ <code>number</code>
Retrieves the sign by its symbol.

**Kind**: global function
**Returns**: <code>number</code> - The sign corresponding to the given symbol and language.

| Param | Type | Description |
| --- | --- | --- |
| signSymbol | <code>string</code> | The symbol of the sign to retrieve. |
| language | <code>string</code> | The language to use for retrieving the sign. |

<a name="getSymbols"></a>

## getSymbols() ⇒ <code>Array</code>
Retrieves the symbols of the zodiac signs from the zodiac data.

**Kind**: global function
**Returns**: <code>Array</code> - An array of symbols representing each zodiac sign.
<a name="getNames"></a>

## getNames(language) ⇒ <code>Array</code>
Retrieves a list of names from the zodiac.json file based on the provided language.

**Kind**: global function
**Returns**: <code>Array</code> - An array of names from the zodiac.json file.

| Param | Type | Description |
| --- | --- | --- |
| language | <code>string</code> | The language code specifying the desired language. |

<a name="getElements"></a>

## getElements(language) ⇒ <code>Array</code>
Retrieves the elements data based on the specified language.

**Kind**: global function
**Returns**: <code>Array</code> - An array containing the elements data.

| Param | Type | Description |
| --- | --- | --- |
| language | <code>string</code> | The language code for the desired elements data. |

<a name="getSignByIndex"></a>

## getSignByIndex(index, language) ⇒ <code>string</code>
Retrieves the sign by its index in the zodiac.json file.

**Kind**: global function
**Returns**: <code>string</code> - The sign corresponding to the given index and language.

| Param | Type | Description |
| --- | --- | --- |
| index | <code>number</code> | The index of the sign. |
| language | <code>string</code> | The language to use for localization. |

<a name="getListValue"></a>

## getListValue(key, data) ⇒ <code>array</code>
Returns an array of values from the given data object, based on the specified key.

**Kind**: global function
**Returns**: <code>array</code> - An array of values extracted from the data object.

| Param | Type | Description |
| --- | --- | --- |
| key | <code>string</code> | The key to extract values from the data object. |
| data | <code>object</code> | The data object to extract values from. |

<a name="getElement"></a>

## getElement(sign, language) ⇒ <code>Object</code>
Retrieves the element data for a given sign and language.

**Kind**: global function
**Returns**: <code>Object</code> - The sign object with the element data.

| Param | Type | Description |
| --- | --- | --- |
| sign | <code>Object</code> | The sign object. |
| language | <code>string</code> | The language code. |

65 changes: 63 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ module.exports = defaultLanguage => {
}
};

/**
* Retrieves the zodiac sign based on a given date and language.
*
* @param {object} date - An object containing the day and month of the date.
* @param {string} language - The language of the zodiac sign to be retrieved.
* @return {object} The zodiac sign corresponding to the given date and language.
*/
const getSignByDate = ({ day, month }, language) => {
const date = new Date(`2000-${month}-${day}`);
if (date.toString() === 'Invalid Date') {
Expand Down Expand Up @@ -50,16 +57,32 @@ const getSignByDate = ({ day, month }, language) => {
return sign;
};

/**
* Retrieves the sign object based on the given sign name and language.
*
* @param {string} signName - The name of the sign to retrieve.
* @param {string} language - The language in which to retrieve the sign.
* @return {number} The sign object corresponding to the given name and language. Returns -2 if the signName is null or not a string.
*/
const getSignByName = (signName, language) => {
if (signName === null || !(typeof signName === 'string')) {
if (signName === null || typeof signName !== 'string') {
return -2;
}

const index = getNames(language).indexOf(signName.charAt(0).toUpperCase() + signName.slice(1));
const index = getNames(language)
.map(name => name.charAt(0).toUpperCase() + name.slice(1))
.indexOf(signName.charAt(0).toUpperCase() + signName.slice(1));

return getSignByIndex(index, language);
};

/**
* Retrieves the sign by its symbol.
*
* @param {string} signSymbol - The symbol of the sign to retrieve.
* @param {string} language - The language to use for retrieving the sign.
* @return {number} The sign corresponding to the given symbol and language.
*/
const getSignBySymbol = (signSymbol, language) => {
if (signSymbol === null || !(typeof signSymbol === 'string')) {
return -2;
Expand All @@ -70,12 +93,23 @@ const getSignBySymbol = (signSymbol, language) => {
return getSignByIndex(index, language);
};

/**
* Retrieves the symbols of the zodiac signs from the zodiac data.
*
* @return {Array} An array of symbols representing each zodiac sign.
*/
const getSymbols = () => {
const signsData = require('./data/zodiac.json');

return getListValue('symbol', signsData);
};

/**
* Retrieves a list of names from the zodiac.json file based on the provided language.
*
* @param {string} language - The language code specifying the desired language.
* @return {Array} An array of names from the zodiac.json file.
*/
const getNames = (language) => {
let signsLocale;
try {
Expand All @@ -87,6 +121,12 @@ const getNames = (language) => {
return getListValue('name', signsLocale);
};

/**
* Retrieves the elements data based on the specified language.
*
* @param {string} language - The language code for the desired elements data.
* @return {Array} An array containing the elements data.
*/
const getElements = (language) => {
let elementsData;
try {
Expand All @@ -98,6 +138,13 @@ const getElements = (language) => {
return elementsData;
};

/**
* Retrieves the sign by its index in the zodiac.json file.
*
* @param {number} index - The index of the sign.
* @param {string} language - The language to use for localization.
* @return {string} The sign corresponding to the given index and language.
*/
const getSignByIndex = (index, language) => {
if (index === -1) {
return -2;
Expand All @@ -117,6 +164,13 @@ const getSignByIndex = (index, language) => {
return sign;
};

/**
* Returns an array of values from the given data object, based on the specified key.
*
* @param {string} key - The key to extract values from the data object.
* @param {object} data - The data object to extract values from.
* @return {array} An array of values extracted from the data object.
*/
const getListValue = (key, data) => {
data = Object.values(data);
const values = [];
Expand All @@ -128,6 +182,13 @@ const getListValue = (key, data) => {
return values;
};

/**
* Retrieves the element data for a given sign and language.
*
* @param {Object} sign - The sign object.
* @param {string} language - The language code.
* @return {Object} The sign object with the element data.
*/
const getElement = (sign, language) => {
let elementsData;
try {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"test": "test"
},
"scripts": {
"docs": "jsdoc2md index.js > docs/API.md",
"test": "mocha"
},
"repository": {
Expand All @@ -29,6 +30,7 @@
},
"homepage": "https://github.com/helmasaur/zodiac-signs#readme",
"devDependencies": {
"jsdoc-to-markdown": "^8.0.0",
"mocha": "^10.2.0"
}
}