Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

util.ts 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. export function merge(...sets:Array<string>):string {
  2. if (sets.length > 1) {
  3. sets[0] = sets[0].slice(0, -1);
  4. const xl = sets.length - 1;
  5. for (let x = 1; x < xl; ++x) {
  6. sets[x] = sets[x].slice(1, -1);
  7. }
  8. sets[xl] = sets[xl].slice(1);
  9. return sets.join('');
  10. } else {
  11. return sets[0];
  12. }
  13. }
  14. export function subexp(str:string):string {
  15. return "(?:" + str + ")";
  16. }
  17. export function typeOf(o:any):string {
  18. return o === undefined ? "undefined" : (o === null ? "null" : Object.prototype.toString.call(o).split(" ").pop().split("]").shift().toLowerCase());
  19. }
  20. export function toUpperCase(str:string):string {
  21. return str.toUpperCase();
  22. }
  23. export function toArray(obj:any):Array<any> {
  24. return obj !== undefined && obj !== null ? (obj instanceof Array ? obj : (typeof obj.length !== "number" || obj.split || obj.setInterval || obj.call ? [obj] : Array.prototype.slice.call(obj))) : [];
  25. }
  26. export function assign(target: object, source: any): any {
  27. const obj = target as any;
  28. if (source) {
  29. for (const key in source) {
  30. obj[key] = source[key];
  31. }
  32. }
  33. return obj;
  34. }