Pular para o conteúdo principal

Utils

With this namespace, you can quickly access methods that perform common operations.

The namespace Utils provides to developers, methods to easily implement regularly used operations.

//accessing to utils methods
SW.Utils.{methodName}

convertToString

Description

This method can be used to convert different variable types to string.

Method(s)

1    function convertToString(valueToConvert: any): string
ParameterTypeRequiredDefaultsDescription
valueToConvertanyfalseVariable to convert(boolean, number, function, array, object)

Basic Usage

SW.Utils.convertToString(4);
SW.Utils.convertToString({first: 1, second: 2});
SW.Utils.convertToString(function () {return 2+2});

Response

"4"
"{first: 1,second: 2}"
"function () {return 2+2}"

copyToClipboard

Description

This method can be used to save text in the clipboard.

Method(s)

1    function copyToClipboard(text: string): void
ParameterTypeRequiredDefaultsDescription
textstringfalseText to save in clipboard

Basic Usage

SW.Utils.copyToClipboard('SkillsWorkflow')

Response

The text "SkillsWorkflow" will be saved in the clipboard


getDataArrayFromMultipleSelectionFieldString

Description

This method can be used to convert a string of data into an array of data.

Method(s)

1    function getDataArrayFromMultipleSelectionFieldString(dataString: string): any[]
ParameterTypeRequiredDefaultsDescription
dataStringstringfalseString of data to be converted to array

Basic Usage

SW.Utils.getDataArrayFromMultipleSelectionFieldString("[{\"name\":\"John\"}, {\"name\":\"Arthur\"}]")

Response

[{name: John}, {name: Arthur}]

getEmptyGuidValue

Description

This method can be used to check if parameter key it's a empty guid.

Method(s)

1    function getEmptyGuidValue(key: string, callback: Function): Promise
ParameterTypeRequiredDefaultsDescription
keystringfalseGuid value
callbackFunctionfalseFunction to be executed case is not empty guid

Basic Usage

SW.Utils.getEmptyGuidValue('00000000-0000-0000-0000-000000000000', 
function () {
return "It's empty guid"
}
)
SW.Utils.getEmptyGuidValue('72917063-915e-4e23-a699-2a6e78804ed',
function () {
return "It's not empty guid"
}
)

Response

Promise<{Id: "00000000-0000-0000-0000-000000000000", Name: "N/A"}>
"It's not empty guid"

isValidGuid

Description

This method can be used to check if a given guid is valid.

Method(s)

1    function isValidGuid(id: string): boolean
ParameterTypeRequiredDefaultsDescription
idstringfalseGuid to check

Basic Usage

SW.Utils.isValidGuid('SkillsWorkflow');
SW.Utils.isValidGuid('23814aa4-0b56-4480-8ba8-c02991a5fdca');

Response

false
true

setExternalImage

Description

This method can be used to append an image to an html element.

Method(s)

1    function setExternalImage(element: HTMLElement, size: Size, url: string): HTMLElement
ParameterTypeRequiredDefaultsDescription
elementHTMLElementtrueElement to append image
sizeSizetrueMEDIUMImage size
urlstringtrueImage url

Basic Usage

SW.Utils.setExternalImage(element, 'small', 'https://test.com/images/logo_new_small.png');

Response

The image will be append to the given element.