quasar-ui-danx 0.2.32 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,17 +1,12 @@
1
1
  /**
2
- *
3
- * @param array
4
- * @param item
5
- * @param newItem
6
- * @returns {*[]}
2
+ * Replace an item in an array with a new item
7
3
  */
8
- export function replace(array, item, newItem = undefined) {
9
- const index =
10
- typeof item === "function" ? array.findIndex(item) : array.indexOf(item);
11
- if (index === false) {
12
- console.error("Item not found in array", item, array);
13
- throw new Error("Item not found in array");
4
+ export function replace(array: any[], item: any, newItem = undefined, appendIfMissing = false) {
5
+ const index: any = typeof item === "function" ? array.findIndex(item) : array.indexOf(item);
6
+ if (index === false || index === -1) {
7
+ return appendIfMissing ? [...array, newItem] : array;
14
8
  }
9
+
15
10
  const newArray = [...array];
16
11
  newItem !== undefined
17
12
  ? newArray.splice(index, 1, newItem)
@@ -19,17 +14,17 @@ export function replace(array, item, newItem = undefined) {
19
14
  return newArray;
20
15
  }
21
16
 
22
- export function remove(array, item) {
17
+ /**
18
+ * Remove an item from an array
19
+ */
20
+ export function remove(array: any[], item: any) {
23
21
  return replace(array, item);
24
22
  }
25
23
 
26
24
  /**
27
25
  * Remove duplicate items from an array using a callback to compare 2 elements
28
- * @param array
29
- * @param cb
30
- * @returns {*}
31
26
  */
32
- export function uniqueBy(array, cb) {
27
+ export function uniqueBy(array: any[], cb: Function) {
33
28
  return array.filter((a, index, self) => {
34
29
  // Check if the current element 'a' is the first occurrence in the array
35
30
  return index === self.findIndex((b) => cb(a, b));
@@ -1,25 +1,18 @@
1
- import { watch } from "vue";
1
+ import { Ref, watch } from "vue";
2
2
 
3
3
  /**
4
- * Sleep function to be used in conjuction with async await:
4
+ * Sleep function to be used in conjunction with async await:
5
5
  *
6
6
  * eg: await sleep(5000);
7
- *
8
- * @param delay
9
- * @returns {Promise<any>}
10
7
  */
11
- export function sleep(delay) {
8
+ export function sleep(delay: number) {
12
9
  return new Promise((resolve) => setTimeout(resolve, delay));
13
10
  }
14
11
 
15
12
  /**
16
13
  * Wait for a ref to have a value and then resolve the promise
17
- *
18
- * @param ref
19
- * @param value
20
- * @returns {Promise<void>}
21
14
  */
22
- export function waitForRef(ref, value) {
15
+ export function waitForRef(ref: Ref, value: any) {
23
16
  return new Promise<void>((resolve) => {
24
17
  watch(ref, (newValue) => {
25
18
  if (newValue === value) {
@@ -31,39 +24,29 @@ export function waitForRef(ref, value) {
31
24
 
32
25
  /**
33
26
  * Returns a number that is constrained to the given range.
34
- * @param min
35
- * @param max
36
- * @param value
37
- * @returns {number}
38
27
  */
39
- export function minmax(min, max, value) {
28
+ export function minmax(min: number, max: number, value: number) {
40
29
  return Math.max(min, Math.min(max, value));
41
30
  }
42
31
 
43
32
  /**
44
33
  * Convert meters to miles
45
- * @param meters
46
- * @returns {number}
47
34
  */
48
- export function metersToMiles(meters) {
35
+ export function metersToMiles(meters: number) {
49
36
  return meters * 0.000621371;
50
37
  }
51
38
 
52
39
  /**
53
40
  * Convert miles to meters
54
- * @param miles
55
- * @returns {number}
56
41
  */
57
- export function milesToMeters(miles) {
42
+ export function milesToMeters(miles: number) {
58
43
  return miles / 0.000621371;
59
44
  }
60
45
 
61
46
  /**
62
47
  * Parses a string for Lat and Long coords
63
- * @param location
64
- * @returns {null|{lng: number, lat: number}}
65
48
  */
66
- export function parseCoords(location) {
49
+ export function parseCoords(location: string) {
67
50
  const latLong = location.split(",");
68
51
 
69
52
  if (latLong.length === 2) {
@@ -80,3 +63,15 @@ export function parseCoords(location) {
80
63
 
81
64
  return null;
82
65
  }
66
+
67
+ /**
68
+ * Increment a name by adding a number to the end of it or incrementing the number if it already exists
69
+ */
70
+ export function incrementName(name: string) {
71
+ name = (name || "New Item").trim();
72
+ const match = name.match(/(\d+)$/);
73
+ if (match) {
74
+ return name.replace(/\d+$/, (match: string) => "" + (parseInt(match) + 1));
75
+ }
76
+ return `${name} 1`;
77
+ }
@@ -1,3 +1,7 @@
1
+ .q-tab {
2
+ text-transform: capitalize
3
+ }
4
+
1
5
  .q-tab-panels {
2
6
  overflow: visible;
3
7