@highlight-ui/utils-commons
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -1,3 +0,52 @@ | ||
export { default as forkHandlers } from './src/forkHandlers.js'; | ||
export { parseMetadata, suffixMetadata } from './src/parseMetadata.js'; | ||
import kebabCase from 'lodash/fp/kebabCase'; | ||
import mapValues from 'lodash/fp/mapValues'; | ||
import curry from 'lodash/fp/curry'; | ||
var forkHandlers = function (handlers) { | ||
return function (e) { | ||
handlers.forEach(function (handler) { | ||
if (handler) handler(e); | ||
}); | ||
}; | ||
}; | ||
function parseMetadata(metadata) { | ||
return metadata ? Object.keys(metadata).reduce(function (acc, key) { | ||
acc["data-" + kebabCase(key)] = metadata[key] || ''; | ||
return acc; | ||
}, {}) : {}; | ||
} | ||
/** | ||
* This function allows to generate a new object that | ||
* contains metadata with values suffixed with provided suffix | ||
* | ||
* @example | ||
* ```ts | ||
* suffixMetadata(metadata, 'inner') | ||
* ``` | ||
* | ||
* This function is curried: | ||
* | ||
* @example | ||
* ```ts | ||
* const { metadata } = props; | ||
* const suffixedMeta = suffixMetadata(metadata); | ||
* ... | ||
* <div {...parseMetadata(suffixedMeta('innerPart1'))}> | ||
* <div {...parseMetadata(suffixedMeta('innerPart2'))} /> | ||
* </div> | ||
* ``` | ||
* | ||
* @param {ComponentMetadata} metadata The original metadata object | ||
* @param {string} suffix A string to be added to the values of the original metadata object | ||
* @returns {ComponentMetadata} The metadata object with values containing suffixes | ||
*/ | ||
var suffixMetadata = curry(function (metadata, suffix) { | ||
return mapValues(function (val) { | ||
return val + "-" + suffix; | ||
}, metadata); | ||
}); | ||
export { forkHandlers, parseMetadata, suffixMetadata }; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@highlight-ui/utils-commons", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"author": "PPU", | ||
@@ -26,3 +26,3 @@ "main": "dist/cjs/index.js", | ||
"@highlight-ui/configs-base-tsconfig": "^3.0.0", | ||
"@highlight-ui/configs-scripts": "^3.0.1", | ||
"@highlight-ui/configs-scripts": "^3.0.2", | ||
"jest": "^27.2.3", | ||
@@ -40,3 +40,3 @@ "lodash": "^4.17.21", | ||
}, | ||
"gitHead": "74898119989d62b9808c3aa67448f8ec487c6d25" | ||
"gitHead": "06cfa844ed2c2451503171e1117652cec7fc243a" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18618
15
234