-
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.
feat(method): new 'specTextValue' method
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
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
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,36 @@ | ||
import specValues from './specValues' | ||
|
||
const specTextValue = (product, gridId, grids, delimiter = ', ') => { | ||
// using text property of each spec object | ||
let values = specValues(product, gridId, grids) | ||
if (values.length) { | ||
let valuesString = values[0].text | ||
for (let i = 1; i < values.length; i++) { | ||
valuesString += delimiter + values[i].text | ||
} | ||
return valuesString | ||
} | ||
// specification not found | ||
return null | ||
} | ||
|
||
/** | ||
* @method | ||
* @memberof ecomUtils | ||
* @name specTextValue | ||
* @description Parse specifications array of nested objects to string. | ||
* @param {object|array} product - Product body or array of variation objects | ||
* @param {string} gridId - Grid ID string such as 'color' | ||
* @param {array} [grids] - List of grid objects | ||
* @param {string} [delimiter=', '] - Delimiter between each specification | ||
* @returns {string|null} | ||
* | ||
* @example | ||
* // TODO | ||
* | ||
* @example | ||
* // Importing this method standalone | ||
* import specTextValue from '@ecomplus/utils/dist/methods/spec-text-value' | ||
*/ | ||
|
||
export default specTextValue |