Skip to content

Commit

Permalink
improve parseKeywordValue helper & fix descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Nov 9, 2022
1 parent 852d01d commit 1a1b621
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 3 additions & 5 deletions src/helpers/parse-keyword-value.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
/**
* Modify value according to a keyword.
* Pass initial value if a keyword is not found.
* Modifies passed keyword value according to its purpose.
* Returns initial value if it's not a keyword.
* @param {string} rawValue
* @returns {string}
*/
export const parseKeywordValue = (rawValue) => {
const NOW_VALUE_KEYWORD = '$now$';
const CURRENT_DATE_KEYWORD = '$currentDate$';

let parsedValue;
let parsedValue = rawValue;

if (rawValue === NOW_VALUE_KEYWORD) {
// Set to current time in ms, e.g 1667915146503
parsedValue = Date.now().toString();
} else if (rawValue === CURRENT_DATE_KEYWORD) {
// Set to current date e.g 'Tue Nov 08 2022 13:53:19 GMT+0300'
parsedValue = Date();
} else {
parsedValue = rawValue;
}

return parsedValue;
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/storage-utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Set item to a specified storage
* @param {Object} storage Storage instance to set item into
* Sets item to a specified storage, if it's not full.
* @param {Storage} storage storage instance to set item into
* @param {string} key
* @param {string} value
* @param {boolean} shouldLog
* @param {boolean} shouldLog determines if helper should log on a failed set attempt
*/
export const setStorageItem = (storage, key, value, shouldLog) => {
// eslint-disable-next-line no-console
Expand Down

0 comments on commit 1a1b621

Please sign in to comment.