forked from eclipse-basyx/basyx-aas-web-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements further utils and composables
- Loading branch information
Showing
5 changed files
with
279 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// convert js date object to string (format: yyyy-MM-dd HH:mm:ss) | ||
export function formatDate(date: Date) { | ||
return ( | ||
[date.getFullYear(), padTo2Digits(date.getMonth() + 1), padTo2Digits(date.getDate())].join('-') + | ||
' ' + | ||
[padTo2Digits(date.getHours()), padTo2Digits(date.getMinutes()), padTo2Digits(date.getSeconds())].join(':') | ||
); | ||
} | ||
|
||
// convert date element to digits | ||
function padTo2Digits(num: number) { | ||
return num.toString().padStart(2, '0'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,50 @@ | ||
import md5 from 'md5'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
export function UUID(): string { | ||
return uuidv4(); | ||
} | ||
|
||
export function generateUUIDFromString(str: any): string { | ||
// create md5 hash from string | ||
const hash = md5(str); | ||
// create UUID from hash | ||
const guid = | ||
hash.substring(0, 8) + | ||
'-' + | ||
hash.substring(8, 12) + | ||
'-' + | ||
hash.substring(12, 16) + | ||
'-' + | ||
hash.substring(16, 20) + | ||
'-' + | ||
hash.substring(20, 32); | ||
return guid; | ||
} | ||
|
||
// Function to check if the idShort of a SubmodelElement matches the given idShort | ||
export function checkIdShort( | ||
referable: any, | ||
idShort: string, | ||
startsWith: boolean = false, | ||
strict: boolean = false | ||
): boolean { | ||
if (idShort.trim() === '') return false; | ||
|
||
if (!referable || !referable.idShort || referable.idShort.length === 0) return false; | ||
|
||
if (startsWith) { | ||
// For matching e.g. ProductImage{00} with idShort ProductImage | ||
if (strict) { | ||
return referable.idShort.startsWith(idShort); | ||
} else { | ||
return referable.idShort.toLowerCase().startsWith(idShort.toLowerCase()); | ||
} | ||
} else { | ||
if (strict) { | ||
return referable.idShort === idShort; | ||
} else { | ||
return referable.idShort.toLowerCase() === idShort.toLowerCase(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Function to capitalize the first letter of a string | ||
export function capitalizeFirstLetter(string: string) { | ||
return string.charAt(0).toUpperCase() + string.slice(1); | ||
} | ||
|
||
// Function to check if the valueType is a number | ||
export function isNumber(valueType: string) { | ||
if (!valueType) return false; | ||
// List of all number types | ||
const numberTypes = [ | ||
'double', | ||
'float', | ||
'integer', | ||
'int', | ||
'nonNegativeInteger', | ||
'positiveInteger', | ||
'unsignedLong', | ||
'unsignedInt', | ||
'unsignedShort', | ||
'unsignedByte', | ||
'nonPositiveInteger', | ||
'negativeInteger', | ||
'long', | ||
'short', | ||
'decimal', | ||
'byte', | ||
]; | ||
// strip xs: from the property if it exists | ||
if (valueType.includes('xs:')) { | ||
valueType = valueType.replace('xs:', ''); | ||
} | ||
// check if the property is a number | ||
if (numberTypes.includes(valueType)) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
// Function to download a JSON File | ||
export function downloadJson(obj: any, fileName: string) { | ||
const jsonStr = JSON.stringify(obj, null, 4); | ||
const blob = new Blob([jsonStr], { type: 'application/json' }); | ||
const url = URL.createObjectURL(blob); | ||
const a = document.createElement('a'); | ||
a.href = url; | ||
a.download = fileName; | ||
document.body.appendChild(a); | ||
a.click(); | ||
document.body.removeChild(a); | ||
URL.revokeObjectURL(url); | ||
} | ||
|
||
// Function to download a binary File | ||
export function downloadFile(filename: string, fileContent: Blob) { | ||
const link = document.createElement('a'); | ||
link.href = window.URL.createObjectURL(fileContent); | ||
link.download = filename; | ||
document.body.appendChild(link); | ||
link.click(); | ||
document.body.removeChild(link); | ||
} |