index.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import * as deepmerge from 'deepmerge';
  2. let expDm = deepmerge['default'];
  3. export { expDm as deepmerge };
  4. /**
  5. * Is the provided string a URL?
  6. *
  7. * @param urlToCheck the url to inspect
  8. */
  9. export function isUrl(urlToCheck: string): boolean {
  10. if (urlToCheck.indexOf('http') === 0 || urlToCheck.indexOf('/') === 0 || urlToCheck.indexOf('./') === 0 || urlToCheck.indexOf('../') === 0) {
  11. return true;
  12. }
  13. return false;
  14. }
  15. /**
  16. * Convert a string from kebab-case to camelCase
  17. * @param s string to convert
  18. */
  19. export function kebabToCamel(s) {
  20. return s.replace(/(\-\w)/g, function(m) { return m[1].toUpperCase(); });
  21. }
  22. //https://gist.github.com/youssman/745578062609e8acac9f
  23. /**
  24. * Convert a string from camelCase to kebab-case
  25. * @param str string to convert
  26. */
  27. export function camelToKebab(str) {
  28. return !str ? null : str.replace(/([A-Z])/g, function(g) { return '-' + g[0].toLowerCase(); });
  29. }
  30. /**
  31. * This will extend an object with configuration values.
  32. * What it practically does it take the keys from the configuration and set them on the object.
  33. * I the configuration is a tree, it will traverse into the tree.
  34. * @param object the object to extend
  35. * @param config the configuration object that will extend the object
  36. */
  37. export function extendClassWithConfig(object: any, config: any) {
  38. if (!config || typeof config !== 'object') { return; }
  39. Object.keys(config).forEach(function(key) {
  40. if (key in object && typeof object[key] !== 'function') {
  41. // if (typeof object[key] === 'function') return;
  42. // if it is an object, iterate internally until reaching basic types
  43. if (typeof object[key] === 'object') {
  44. extendClassWithConfig(object[key], config[key]);
  45. } else {
  46. if (config[key] !== undefined) {
  47. object[key] = config[key];
  48. }
  49. }
  50. }
  51. });
  52. }