| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- /**
- * Is the provided string a URL?
- *
- * @param urlToCheck the url to inspect
- */
- export function isUrl(urlToCheck: string): boolean {
- if (urlToCheck.indexOf('http') === 0 || urlToCheck.indexOf('/') === 0 || urlToCheck.indexOf('./') === 0 || urlToCheck.indexOf('../') === 0) {
- return true;
- }
- return false;
- }
- /**
- * Convert a string from kebab-case to camelCase
- * @param s string to convert
- */
- export function kebabToCamel(s) {
- return s.replace(/(\-\w)/g, function (m) { return m[1].toUpperCase(); });
- }
- //https://gist.github.com/youssman/745578062609e8acac9f
- /**
- * Convert a string from camelCase to kebab-case
- * @param str string to convert
- */
- export function camelToKebab(str) {
- return !str ? null : str.replace(/([A-Z])/g, function (g) { return '-' + g[0].toLowerCase() });
- }
- /**
- * This will extend an object with configuration values.
- * What it practically does it take the keys from the configuration and set them on the object.
- * I the configuration is a tree, it will traverse into the tree.
- * @param object the object to extend
- * @param config the configuration object that will extend the object
- */
- export function extendClassWithConfig(object: any, config: any) {
- if (!config) return;
- Object.keys(config).forEach(key => {
- if (key in object && typeof object[key] !== 'function') {
- // if (typeof object[key] === 'function') return;
- // if it is an object, iterate internally until reaching basic types
- if (typeof object[key] === 'object') {
- extendClassWithConfig(object[key], config[key]);
- } else {
- if (config[key] !== undefined) {
- object[key] = config[key];
- }
- }
- }
- });
- }
|