@rebasepro/common 0.0.1-canary.2 → 0.0.1-canary.4d4fb3e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +1 -1
  2. package/dist/collections/CollectionRegistry.d.ts +2 -2
  3. package/dist/data/buildRebaseData.d.ts +14 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.es.js +398 -815
  6. package/dist/index.es.js.map +1 -1
  7. package/dist/index.umd.js +418 -835
  8. package/dist/index.umd.js.map +1 -1
  9. package/dist/util/builders.d.ts +6 -13
  10. package/dist/util/collections.d.ts +2 -2
  11. package/dist/util/entities.d.ts +16 -8
  12. package/dist/util/index.d.ts +1 -11
  13. package/dist/util/navigation_from_path.d.ts +10 -5
  14. package/dist/util/navigation_utils.d.ts +1 -12
  15. package/dist/util/permissions.d.ts +4 -4
  16. package/dist/util/references.d.ts +1 -1
  17. package/dist/util/relations.d.ts +4 -4
  18. package/dist/util/resolutions.d.ts +10 -12
  19. package/dist/util/storage.d.ts +4 -4
  20. package/package.json +11 -16
  21. package/src/collections/CollectionRegistry.ts +96 -33
  22. package/src/data/buildRebaseData.ts +221 -0
  23. package/src/index.ts +1 -0
  24. package/src/types/json-logic-js.d.ts +8 -0
  25. package/src/util/builders.ts +8 -18
  26. package/src/util/callbacks.ts +3 -4
  27. package/src/util/collections.ts +4 -4
  28. package/src/util/conditions.ts +4 -4
  29. package/src/util/entities.ts +37 -12
  30. package/src/util/index.ts +1 -11
  31. package/src/util/navigation_from_path.ts +8 -7
  32. package/src/util/navigation_utils.ts +4 -56
  33. package/src/util/parent_references_from_path.ts +1 -1
  34. package/src/util/permissions.test.ts +24 -28
  35. package/src/util/permissions.ts +14 -14
  36. package/src/util/references.ts +16 -2
  37. package/src/util/relations.ts +23 -19
  38. package/src/util/resolutions.ts +31 -62
  39. package/src/util/storage.ts +5 -5
  40. package/dist/util/arrays.d.ts +0 -1
  41. package/dist/util/dates.d.ts +0 -1
  42. package/dist/util/entity_actions.d.ts +0 -2
  43. package/dist/util/fields.d.ts +0 -2
  44. package/dist/util/flatten_object.d.ts +0 -5
  45. package/dist/util/hash.d.ts +0 -1
  46. package/dist/util/names.d.ts +0 -22
  47. package/dist/util/objects.d.ts +0 -26
  48. package/dist/util/os.d.ts +0 -2
  49. package/dist/util/plurals.d.ts +0 -16
  50. package/dist/util/regexp.d.ts +0 -7
  51. package/dist/util/strings.d.ts +0 -7
  52. package/src/util/arrays.ts +0 -3
  53. package/src/util/dates.ts +0 -1
  54. package/src/util/entity_actions.ts +0 -28
  55. package/src/util/fields.ts +0 -28
  56. package/src/util/flatten_object.ts +0 -45
  57. package/src/util/hash.ts +0 -11
  58. package/src/util/names.ts +0 -30
  59. package/src/util/objects.ts +0 -376
  60. package/src/util/os.ts +0 -13
  61. package/src/util/plurals.ts +0 -188
  62. package/src/util/regexp.ts +0 -32
  63. package/src/util/strings.ts +0 -84
@@ -1,7 +0,0 @@
1
- export declare const toKebabCase: (str: string) => string;
2
- export declare const toSnakeCase: (str: string) => string;
3
- export declare function randomString(strLength?: number): string;
4
- export declare function randomColor(): string;
5
- export declare function slugify(text?: string, separator?: string, lowercase?: boolean): string;
6
- export declare function unslugify(slug?: string): string;
7
- export declare function prettifyIdentifier(input: string): string;
@@ -1,3 +0,0 @@
1
- export function toArray<T>(input?: T | T[]): T[] {
2
- return Array.isArray(input) ? input : (input ? [input] : []);
3
- }
package/src/util/dates.ts DELETED
@@ -1 +0,0 @@
1
- export const defaultDateFormat = "MMMM dd, yyyy, HH:mm:ss";
@@ -1,28 +0,0 @@
1
- import { EntityAction } from "@rebasepro/types";
2
-
3
- const reservedKeys = ["edit", "copy", "delete"];
4
-
5
- export function mergeEntityActions(currentActions: EntityAction[], newActions: EntityAction[]): EntityAction[] {
6
- // given the current actions, replace the ones with the same key
7
- // and append the new ones
8
- const updatedActions: EntityAction[] = [];
9
- currentActions.forEach(action => {
10
- const newAction = newActions.find(a => a.key === action.key);
11
- if (newAction) {
12
- const mergedAction = {
13
- ...action,
14
- ...newAction
15
- }
16
- updatedActions.push(mergedAction);
17
- } else {
18
- updatedActions.push(action);
19
- }
20
- });
21
- newActions.forEach(action => {
22
- if (!currentActions.find(a => a.key === action.key) && (!action.key || !reservedKeys.includes(action.key))) {
23
- updatedActions.push(action);
24
- }
25
- });
26
- return updatedActions;
27
-
28
- }
@@ -1,28 +0,0 @@
1
- import { DefaultFieldConfig } from "@rebasepro/types";
2
-
3
- export function isDefaultFieldConfigId(id: string): id is DefaultFieldConfig {
4
- return ["text_field",
5
- "multiline",
6
- "markdown",
7
- "url",
8
- "email",
9
- "switch",
10
- "select",
11
- "multi_select",
12
- "number_input",
13
- "number_select",
14
- "multi_number_select",
15
- "file_upload",
16
- "multi_file_upload",
17
- "reference_as_string",
18
- "reference",
19
- "multi_references",
20
- "relation",
21
- "date_time",
22
- "group",
23
- "key_value",
24
- "repeat",
25
- "custom_array",
26
- "block"
27
- ].includes(id);
28
- }
@@ -1,45 +0,0 @@
1
- export function flattenObject(obj: Record<string, unknown>, parentKey = "") {
2
- if (!obj) return obj;
3
- return Object.keys(obj).reduce((flatObj, key) => {
4
- const newKey = parentKey ? `${parentKey}.${key}` : key;
5
-
6
- if (typeof obj[key] === "object" && obj[key] !== null) {
7
- if (Array.isArray(obj[key])) {
8
- obj[key].forEach((item: unknown, index: number) => {
9
- Object.assign(flatObj, flattenObject(item as Record<string, unknown>, `${newKey}[${index}]`));
10
- });
11
- } else {
12
- Object.assign(flatObj, flattenObject(obj[key] as Record<string, unknown>, newKey));
13
- }
14
- } else {
15
- flatObj[newKey] = obj[key];
16
- }
17
-
18
- return flatObj;
19
- }, {} as { [key: string]: unknown });
20
- }
21
-
22
-
23
- // map from nested property key like "a.b.c" to the maximum array count found in a list of objects for that array
24
- export type ArrayValuesCount = Record<string, number>;
25
-
26
- export function getArrayValuesCount(array: Record<string, unknown>[]): ArrayValuesCount {
27
- return array.reduce((acc: ArrayValuesCount, obj: Record<string, unknown>) => {
28
- Object.entries(obj).forEach(([key, value]) => {
29
- // proceed only if value is an array
30
- if (Array.isArray(value)) {
31
- acc[key] = Math.max(acc[key] || 0, value.length);
32
- }
33
-
34
- // handle nested object
35
- if (typeof value === "object" && value !== null) {
36
- const nested = getArrayValuesCount([value as Record<string, unknown>]);
37
- Object.entries(nested).forEach(([nestedKey, nestedCount]) => {
38
- const compoundKey = `${key}.${nestedKey}`;
39
- acc[compoundKey] = Math.max(acc[compoundKey] || 0, nestedCount);
40
- });
41
- }
42
- });
43
- return acc;
44
- }, {});
45
- }
package/src/util/hash.ts DELETED
@@ -1,11 +0,0 @@
1
- export function hashString(str: string): number {
2
- let hash = 0;
3
- let i;
4
- let chr;
5
- for (i = 0; i < str.length; i++) {
6
- chr = str.charCodeAt(i);
7
- hash = ((hash << 5) - hash) + chr;
8
- hash |= 0; // Convert to 32bit integer
9
- }
10
- return Math.abs(hash);
11
- }
package/src/util/names.ts DELETED
@@ -1,30 +0,0 @@
1
- import { toSnakeCase } from "./strings";
2
-
3
- /**
4
- * Generates a foreign key column name from a given string, typically a collection slug or name.
5
- * It converts the name to snake_case, attempts to singularize it by removing a trailing 's'
6
- * (a common convention for collection names), and appends '_id'.
7
- *
8
- * @param name The base name to convert to a foreign key.
9
- * @returns A foreign key name in the format 'singular_name_id'.
10
- *
11
- * @example
12
- * // returns "user_id"
13
- * generateForeignKeyName("users")
14
- *
15
- * @example
16
- * // returns "post_id"
17
- * generateForeignKeyName("posts")
18
- *
19
- * @example
20
- * // returns "product_id"
21
- * generateForeignKeyName("Product")
22
- *
23
- */
24
- export function generateForeignKeyName(name: string): string {
25
- const snakeCaseName = toSnakeCase(name);
26
- // A simple heuristic to singularize a plural name, which is a common convention.
27
- const singularName = snakeCaseName.endsWith("s") ? snakeCaseName.slice(0, -1) : snakeCaseName;
28
- return `${singularName}_id`;
29
- }
30
-
@@ -1,376 +0,0 @@
1
- import hash from "object-hash";
2
- import { GeoPoint } from "@rebasepro/types";
3
-
4
- /** @private is the value an empty array? */
5
- export const isEmptyArray = (value?: unknown) =>
6
- Array.isArray(value) && value.length === 0;
7
-
8
- /** @private is the given object a Function? */
9
- export const isFunction = (obj: unknown): obj is Function =>
10
- typeof obj === "function";
11
-
12
- /** @private is the given object an integer? */
13
- export const isInteger = (obj: unknown): boolean =>
14
- String(Math.floor(Number(obj))) === String(obj);
15
-
16
- /** @private is the given object a NaN? */
17
- // eslint-disable-next-line no-self-compare
18
- export const isNaN = (obj: unknown): boolean => obj !== obj;
19
-
20
- /**
21
- * Deeply get a value from an object via its path.
22
- */
23
- export function getIn(
24
- obj: Record<string, unknown> | unknown[] | unknown,
25
- key: string | string[],
26
- def?: unknown,
27
- p = 0
28
- ) {
29
- const path = toPath(key);
30
- while (obj && p < path.length) {
31
- obj = (obj as Record<string, unknown>)[path[p++]];
32
- }
33
-
34
- // check if path is not in the end
35
- if (p !== path.length && !obj) {
36
- return def;
37
- }
38
-
39
- return obj === undefined ? def : obj;
40
- }
41
-
42
- export function setIn<T>(obj: T, path: string, value: unknown): T {
43
- const res = clone(obj) as Record<string, unknown>;
44
- let resVal: Record<string, unknown> = res;
45
- let i = 0;
46
- const pathArray = toPath(path);
47
-
48
- for (; i < pathArray.length - 1; i++) {
49
- const currentPath: string = pathArray[i];
50
- const currentObj = getIn(obj as Record<string, unknown>, pathArray.slice(0, i + 1));
51
-
52
- if (currentObj && (isObject(currentObj) || Array.isArray(currentObj))) {
53
- resVal = resVal[currentPath] = clone(currentObj) as Record<string, unknown>;
54
- } else {
55
- const nextPath: string = pathArray[i + 1];
56
- resVal = resVal[currentPath] =
57
- (isInteger(nextPath) && Number(nextPath) >= 0 ? [] : {}) as Record<string, unknown>;
58
- }
59
- }
60
-
61
- // Return original object if new value is the same as current
62
- if ((i === 0 ? obj as Record<string, unknown> : resVal)[pathArray[i]] === value) {
63
- return obj;
64
- }
65
-
66
- if (value === undefined) {
67
- delete resVal[pathArray[i]];
68
- } else {
69
- resVal[pathArray[i]] = value;
70
- }
71
-
72
- // If the path array has a single element, the loop did not run.
73
- // Deleting on `resVal` had no effect in this scenario, so we delete on the result instead.
74
- if (i === 0 && value === undefined) {
75
- delete res[pathArray[i]];
76
- }
77
-
78
- return res as T;
79
- }
80
-
81
- export function clone<T>(value: T): T {
82
- if (Array.isArray(value)) {
83
- return [...value] as unknown as T;
84
- } else if (typeof value === "object" && value !== null) {
85
- return { ...value } as T;
86
- } else {
87
- return value; // This is for primitive types which do not need cloning.
88
- }
89
- }
90
-
91
- function toPath(value: string | string[]) {
92
- if (Array.isArray(value)) return value; // Already in path array form.
93
- // Replace brackets with dots, remove leading/trailing dots, then split by dot.
94
- return value.replace(/\[(\d+)]/g, ".$1").replace(/^\./, "").replace(/\.$/, "").split(".");
95
- }
96
-
97
-
98
- export const pick: <T extends Record<string, unknown>>(obj: T, ...args: (keyof T)[]) => Partial<T> = <T extends Record<string, unknown>>(obj: T, ...args: (keyof T)[]) => ({
99
- ...args.reduce<Record<string, unknown>>((res, key) => ({
100
- ...res,
101
- [key as string]: obj[key as string]
102
- }), {})
103
- }) as Partial<T>;
104
-
105
- export function isObject(item: unknown): item is Record<string, unknown> {
106
- return !!item && typeof item === "object" && !Array.isArray(item);
107
- }
108
-
109
- export function isPlainObject(obj: unknown): obj is Record<string, unknown> {
110
- // 1. Rule out non-objects, null, and arrays
111
- if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
112
- return false;
113
- }
114
-
115
- // 2. Get the object's direct prototype
116
- const proto = Object.getPrototypeOf(obj);
117
-
118
- // 3. A plain object's direct prototype is Object.prototype
119
- return proto === Object.prototype;
120
- }
121
-
122
- export function mergeDeep<T extends Record<string, any>, U extends Record<string, any>>(
123
- target: T,
124
- source: U,
125
- ignoreUndefined: boolean = false
126
- ): T & U {
127
- // If target is not a true object (e.g., null, array, primitive), return target itself.
128
- if (!isObject(target)) {
129
- return target as T & U;
130
- }
131
-
132
- // Create a shallow copy of the target to avoid modifying the original object.
133
- const output = { ...target };
134
-
135
- // If source is not a true object, there's nothing to merge from it.
136
- // Return the shallow copy of target.
137
- if (!isObject(source)) {
138
- return output as T & U;
139
- }
140
-
141
- // Iterate over keys in the source object.
142
- for (const key in source) {
143
- if (Object.prototype.hasOwnProperty.call(source, key)) {
144
- const sourceValue = source[key];
145
- const outputValue = (output as any)[key]; // Current value in our merged object (originating from target)
146
-
147
- // Skip if source value is undefined and ignoreUndefined is true.
148
- // This handles both not adding new undefined properties and not overwriting existing properties with undefined.
149
- if (ignoreUndefined && sourceValue === undefined) {
150
- continue;
151
- }
152
-
153
- if ((sourceValue as unknown) instanceof Date) {
154
- // If source value is a Date, create a new Date instance.
155
- (output as Record<string, unknown>)[key] = new Date((sourceValue as unknown as Date).getTime());
156
- } else if (Array.isArray(sourceValue)) {
157
- if (Array.isArray(outputValue)) {
158
- const newArray = [];
159
- const maxLength = Math.max(outputValue.length, sourceValue.length);
160
- for (let i = 0; i < maxLength; i++) {
161
- const sourceItem = sourceValue[i];
162
- const targetItem = outputValue[i];
163
-
164
- if (i >= sourceValue.length) { // source is shorter
165
- newArray[i] = targetItem;
166
- } else if (i >= outputValue.length) { // target is shorter
167
- newArray[i] = sourceItem;
168
- } else if (sourceItem === null) {
169
- newArray[i] = targetItem;
170
- } else if (isPlainObject(sourceItem) && isPlainObject(targetItem)) {
171
- // Only recursively merge plain objects, preserve class instances
172
- newArray[i] = mergeDeep(targetItem, sourceItem, ignoreUndefined);
173
- } else {
174
- // For class instances and primitives, use source directly
175
- newArray[i] = sourceItem;
176
- }
177
- }
178
- (output as Record<string, unknown>)[key] = newArray;
179
- } else {
180
- // If output's value (from target) is not an array,
181
- // overwrite with a shallow copy of the source array.
182
- (output as Record<string, unknown>)[key] = [...sourceValue];
183
- }
184
- } else if (isPlainObject(sourceValue)) {
185
- // If source value is a plain object (not a class instance like EntityReference, GeoPoint, etc.):
186
- if (isPlainObject(outputValue)) {
187
- // If the corresponding value in output (from target) is also a plain object, recurse.
188
- // Ensure the ignoreUndefined flag is passed down.
189
- (output as Record<string, unknown>)[key] = mergeDeep(outputValue as Record<string, unknown>, sourceValue, ignoreUndefined);
190
- } else {
191
- // If output's value (from target) is not a plain object (e.g., null, primitive, class instance, or key didn't exist in original target),
192
- // overwrite with the source object.
193
- (output as Record<string, unknown>)[key] = sourceValue;
194
- }
195
- } else if (isObject(sourceValue)) {
196
- // If source value is a class instance (not a plain object), use it directly to preserve prototype
197
- (output as Record<string, unknown>)[key] = sourceValue;
198
- } else {
199
- // If source value is a primitive, null, or undefined (and not ignored).
200
- (output as Record<string, unknown>)[key] = sourceValue;
201
- }
202
- }
203
- }
204
-
205
- return output as T & U;
206
- }
207
-
208
- export function getValueInPath(o: object | undefined, path: string): unknown {
209
- if (!o) return undefined;
210
- if (typeof o === "object") {
211
- if (path in o) {
212
- return (o as Record<string, unknown>)[path];
213
- }
214
- if (path.includes(".") || path.includes("[")) {
215
- let pathSegments = path.split(/[.[]/);
216
- if (path.includes("[")) {
217
- pathSegments = pathSegments.map(segment => segment.replace("]", ""));
218
- }
219
- const firstSegment = pathSegments[0];
220
- const isArrayAndIndexExists = Array.isArray((o as Record<string, unknown>)[firstSegment]) && !isNaN(parseInt(pathSegments[1]));
221
- const nextObject = isArrayAndIndexExists
222
- ? ((o as Record<string, unknown>)[firstSegment] as unknown[])[parseInt(pathSegments[1])]
223
- : (o as Record<string, unknown>)[firstSegment];
224
-
225
- const nextPath = pathSegments.slice(isArrayAndIndexExists ? 2 : 1).join(".");
226
- if (nextPath === "")
227
- return nextObject;
228
- return getValueInPath(nextObject as object | undefined, nextPath);
229
- }
230
- }
231
- return undefined;
232
- }
233
-
234
- export function removeInPath(o: object, path: string): object | undefined {
235
- let currentObject = { ...o };
236
- const parts = path.split(".");
237
- const last = parts.pop();
238
- for (const part of parts) {
239
- currentObject = (currentObject as Record<string, unknown>)[part] as Record<string, unknown>;
240
- }
241
- if (last)
242
- delete (currentObject as Record<string, unknown>)[last];
243
- return currentObject;
244
- }
245
-
246
- export function removeFunctions(o: unknown): unknown {
247
- if (o === undefined) return undefined;
248
- if (o === null) return null;
249
- if (typeof o === "object") {
250
- // Handle arrays first - map over them recursively
251
- if (Array.isArray(o)) {
252
- return o.map(v => removeFunctions(v));
253
- }
254
- // Preserve class instances (EntityReference, GeoPoint, etc.) - don't recurse into them
255
- if (!isPlainObject(o)) {
256
- return o;
257
- }
258
- return Object.entries(o)
259
- .filter(([_, value]) => typeof value !== "function")
260
- .map(([key, value]) => {
261
- if (Array.isArray(value)) {
262
- return { [key]: value.map(v => removeFunctions(v)) };
263
- } else if (typeof value === "object") {
264
- return { [key]: removeFunctions(value) };
265
- } else return { [key]: value };
266
- })
267
- .reduce((a, b) => ({ ...a, ...b }), {});
268
- }
269
- return o;
270
- }
271
-
272
- export function getHashValue<T>(v: T): string | null {
273
- if (!v) return null;
274
- if (typeof v === "object" && v !== null) {
275
- if ("id" in v)
276
- return String((v as Record<string, unknown>).id);
277
- else if (v instanceof Date)
278
- return v.toLocaleString();
279
- else if (v instanceof GeoPoint)
280
- return hash(v as unknown as Record<string, unknown>);
281
- }
282
- return hash(v as object, { ignoreUnknown: true });
283
- }
284
-
285
- export function removeUndefined(value: unknown, removeEmptyStrings?: boolean): unknown {
286
- if (typeof value === "function") {
287
- return value;
288
- }
289
- if (Array.isArray(value)) {
290
- return value.map((v: unknown) => removeUndefined(v, removeEmptyStrings));
291
- }
292
- if (typeof value === "object") {
293
- if (value === null)
294
- return value;
295
- // Preserve class instances (EntityReference, GeoPoint, etc.) - don't recurse into them
296
- if (!isPlainObject(value)) {
297
- return value;
298
- }
299
- const res: Record<string, unknown> = {};
300
- Object.keys(value).forEach((key) => {
301
- if (!isEmptyObject(value as object)) {
302
- const childRes = removeUndefined((value as Record<string, unknown>)[key], removeEmptyStrings);
303
- const isString = typeof childRes === "string";
304
- const shouldKeepIfString = !removeEmptyStrings || (removeEmptyStrings && !isString) || (removeEmptyStrings && isString && childRes !== "");
305
- if (childRes !== undefined && !isEmptyObject(childRes as object) && shouldKeepIfString)
306
- res[key] = childRes;
307
- }
308
- });
309
- return res;
310
- }
311
- return value;
312
- }
313
-
314
- export function removeNulls(value: unknown): unknown {
315
- if (typeof value === "function") {
316
- return value;
317
- }
318
- if (Array.isArray(value)) {
319
- return value.map((v: unknown) => removeNulls(v));
320
- }
321
- if (typeof value === "object") {
322
- if (value === null)
323
- return value;
324
- // Preserve class instances (EntityReference, GeoPoint, etc.) - don't recurse into them
325
- if (!isPlainObject(value)) {
326
- return value;
327
- }
328
- const res: Record<string, unknown> = {};
329
- const obj = value as Record<string, unknown>;
330
- Object.keys(obj).forEach((key) => {
331
- if (obj[key] !== null)
332
- res[key] = removeNulls(obj[key]);
333
- });
334
- return res;
335
- }
336
- return value;
337
- }
338
-
339
- export function isEmptyObject(obj: object) {
340
- return obj &&
341
- Object.getPrototypeOf(obj) === Object.prototype &&
342
- Object.keys(obj).length === 0
343
- }
344
-
345
- export function removePropsIfExisting(source: Record<string, unknown> | unknown[], comparison: Record<string, unknown> | unknown[]) {
346
- const isObject = (val: unknown): val is Record<string, unknown> => typeof val === "object" && val !== null;
347
- const isArray = (val: unknown): val is unknown[] => Array.isArray(val);
348
-
349
- if (!isObject(source) || !isObject(comparison)) {
350
- return source;
351
- }
352
-
353
- const res = isArray(source) ? [...source] : { ...source };
354
-
355
- if (isArray(res)) {
356
- for (let i = res.length - 1; i >= 0; i--) {
357
- if (res[i] === comparison[i]) {
358
- res.splice(i, 1);
359
- } else if (isObject(res[i]) && isObject(comparison[i])) {
360
- res[i] = removePropsIfExisting(res[i] as Record<string, unknown>, (comparison as unknown as unknown[])[i] as Record<string, unknown>);
361
- }
362
- }
363
- } else {
364
- Object.keys(comparison).forEach(key => {
365
- if (key in res) {
366
- if (isObject(res[key]) && isObject(comparison[key])) {
367
- res[key] = removePropsIfExisting(res[key], comparison[key]);
368
- } else if (res[key] === comparison[key]) {
369
- delete res[key];
370
- }
371
- }
372
- });
373
- }
374
-
375
- return res;
376
- }
package/src/util/os.ts DELETED
@@ -1,13 +0,0 @@
1
- export function getOS() {
2
- let OS = "Unknown";
3
- if (navigator.userAgent.indexOf("Win") !== -1) OS = "Windows";
4
- if (navigator.userAgent.indexOf("Mac") !== -1) OS = "MacOS";
5
- if (navigator.userAgent.indexOf("X11") !== -1) OS = "UNIX";
6
- if (navigator.userAgent.indexOf("Linux") !== -1) OS = "Linux";
7
- return OS;
8
- }
9
-
10
- export function getAltSymbol() {
11
- if (getOS() === "MacOS") return "⌥";
12
- return "Alt";
13
- }