Repository URL to install this package:
|
Version:
1.1.2 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function processKeys(obj, keys) {
if (!obj || !keys || keys.length == 0)
return null;
if (keys.length == 1)
return obj[keys[0]];
const key = keys.shift();
return processKeys(obj[key], keys);
}
// return a key given a key string aka. product.properties.children
function getValueForKey(obj, keyString, defaultValue) {
return processKeys(obj, keyString.split('.')) || defaultValue;
}
exports.getValueForKey = getValueForKey;
// Format a price to standard fixed
function formatPrice(price) {
try {
let newPrice = Number(price);
return newPrice.toFixed(2);
}
catch (e) {
return 'N/A';
}
}
exports.formatPrice = formatPrice;
// Utility to updates state
function updateState(component, newState) {
component.setState(Object.assign({}, component.state, newState));
}
exports.updateState = updateState;
exports.pricifyFilter = (str) => {
// i.e 500 & Above -> $500 & Above
// '$' + str.replace(/-|&/, ' - ')
if (str.includes('&')) {
return `$${str.split(' & ')[0]} & ${str.split(' & ')[1]}`;
}
// i.e TOP -> Top
if (!str.includes('-')) {
return str;
}
// i.e 0-50 -> $0 - $50
return str
.split('-')
.map(v => `$${v}`)
.join(' - ');
};
//# sourceMappingURL=formatting.js.map