-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from 4urcloud/dev
Dev
- Loading branch information
Showing
30 changed files
with
2,074 additions
and
855 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
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,55 @@ | ||
const levelAlert = ["info", "warning", "error", "fatal"]; | ||
export const Teams = { | ||
//https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using?tabs=cURL | ||
OneTeams: (color:string, subject:string, url:string, description:string) => { | ||
return JSON.stringify({ | ||
"@type": "MessageCard", | ||
"@context": "http://schema.org/extensions", | ||
"themeColor": color, | ||
"summary": subject, | ||
"sections": [ | ||
{ | ||
"activityTitle": subject, | ||
"activitySubtitle": description, | ||
"activityImage": "https://kexa.io/kexa-no-background-color.png", | ||
"markdown": true | ||
} | ||
], | ||
"potentialAction": [ | ||
{ | ||
"@type": "OpenUri", | ||
"name": "Go to ressource", | ||
"targets": [ | ||
{ | ||
"os": "default", | ||
"uri": url | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
}, | ||
GlobalTeams: (color:string, subject:string, text:string, errors:{ [x: string]: number; }) => { | ||
return JSON.stringify({ | ||
"@type": "MessageCard", | ||
"@context": "http://schema.org/extensions", | ||
"themeColor": color, | ||
"summary": subject, | ||
"sections": [ | ||
{ | ||
"activityTitle": subject, | ||
"activitySubtitle": "Kexa by 4urcloud", | ||
"activityImage": "https://kexa.io/kexa-no-background-color.png", | ||
"text": text, | ||
"facts": Object.entries(errors).map(([name, value]) => { | ||
return { | ||
"name": name, | ||
"value": value.toString() | ||
}; | ||
}), | ||
"markdown": true | ||
} | ||
] | ||
}); | ||
}, | ||
}; |
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,34 @@ | ||
const jsdom = require("jsdom") | ||
const { JSDOM } = jsdom | ||
global.DOMParser = new JSDOM().window.DOMParser | ||
|
||
export const extractURL = (text: string): string | null => { | ||
return extractFirstURLFromHTML(text)??extractFirstURL(text); | ||
} | ||
|
||
function extractFirstURLFromHTML(html: string): string | null { | ||
const parser = new DOMParser(); | ||
const doc = parser.parseFromString(html, 'text/html'); | ||
|
||
const urlElements = Array.from(doc.querySelectorAll('a[href], img[src]')); | ||
|
||
for (const element of urlElements) { | ||
const url = (element as HTMLAnchorElement).href || (element as HTMLImageElement).src; | ||
if (url) { | ||
return url; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
function extractFirstURL(input:string): string | null { | ||
const urlRegex = /(https?:\/\/[^\s]+)/g; | ||
const matches = input.match(urlRegex); | ||
|
||
if (matches && matches.length > 0) { | ||
return matches[0]; | ||
} | ||
|
||
return null; | ||
} |
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,21 @@ | ||
export const splitProperty = (prop: string, delimiter:string, ignore:string="/"):string[] => { | ||
const result = []; | ||
let current = ""; | ||
let escape = false; | ||
|
||
for (const char of prop) { | ||
if (char === delimiter && !escape) { | ||
result.push(current); | ||
current = ""; | ||
} else if (char === ignore && !escape) { | ||
escape = true; | ||
} else { | ||
if(escape && char !== delimiter) current += ignore; | ||
current += char; | ||
escape = false; | ||
} | ||
} | ||
|
||
result.push(current); | ||
return result; | ||
} |
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,37 @@ | ||
export function getMinMaxMeanMedian(array: Array<number>): MinMaxMeanMedian { | ||
let min = array[0]; | ||
let max = array[0]; | ||
let sum = 0; | ||
for(const num of array){ | ||
if(num < min) min = num; | ||
if(num > max) max = num; | ||
sum += num; | ||
} | ||
return { | ||
"min": min, | ||
"max": max, | ||
"mean": sum/array.length, | ||
"median": array[Math.floor(array.length/2)], | ||
} | ||
} | ||
|
||
export function convertToPercentage(num: number, total: number): number { | ||
// pourcentage avec 2 chiffres après la virgule | ||
return Math.round((num/total)*10000)/100; | ||
} | ||
|
||
export function convertMinMaxMeanMedianToPercentage(stat:MinMaxMeanMedian, total:number): MinMaxMeanMedian { | ||
return { | ||
"min": convertToPercentage(stat.min, total), | ||
"max": convertToPercentage(stat.max, total), | ||
"mean": convertToPercentage(stat.mean, total), | ||
"median": convertToPercentage(stat.median, total), | ||
} | ||
} | ||
|
||
export interface MinMaxMeanMedian { | ||
min: number, | ||
max: number, | ||
mean: number, | ||
median: number, | ||
} |
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
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
Oops, something went wrong.