Skip to main content

SipaHelper

SipaHelper

SipaHelper

Tool helper class with common helper methods

SipaHelper.mergeOptions(source, addition) Object

Merge default options (source) with custom options (addition)

Works only fine with one level depth, don't merge nested (Object) options, as references are copied then!

Returns: Object - merged object

ParamType
sourceObject
additionObject

Example

SipaHelper.mergeOptions({ a: 1, b: "two"},{b: "TWO", c: null });
// => { a: 1, b: "TWO", c: null }

SipaHelper.isArrayContainingEmptyValue(value) boolean

Check if given value is a array (slice) of size 1 and contains type empty

Returns: boolean - true if a array of size 1 and contains empty => [empty], if size is 1 and not of type empty then false
Throws:

  • Error if array is not of size 1
ParamType
valueany

Example

let arr = ["one"];
delete arr[1]:
arr;
// => [empty]
SipaHelper.isArrayContainingEmptyValue(arr);
// => true

SipaHelper.validateParams(params)

Check the given parameter to be of the expected type. If is is not valid, throw an exception. Throws:

  • Error throws an error if given parameter is not valid.
ParamType
paramsArray.<SipaParamValidation>

Example

function Example(param_one, other_param) {
SipaHelper.validateParams([
{param_name: 'param_one', param_value: param_one, expected_type: 'Object'},
{param_name: 'other_param', param_value: other_param, expected_type: 'boolean'},
]);
}
Example("one",true);
// => Invalid parameter 'param_one' given. Expected type 'Object' but got type 'string'!`

SipaHelper.cutLeadingCharacters(text, leading_characters) string

Cut leading characters (string) from given text

ParamTypeDescription
textstringto cut
leading_charactersstringto cut from text

Example

.cutLeadingCharacters('/some/path/is/that','/')
// => 'some/path/is/that'

SipaHelper.cutTrailingCharacters(text, trailing_characters) string

Cut trailing characters (string) from given text

ParamTypeDescription
textstringto cut
trailing_charactersstringto cut from text

Example

.cutLeadingCharacters('/some/path/file.ext','.ext')
// => 'some/path/file'

SipaHelper.constantizeString(constant) *

Transform the given string into its constant representation.

ParamType
constantstring

Example

class Foo {
static function bar() { console.log("foobar"); }
}

SipaHelper.constantizeString("Foo").bar();
// => foobar

SipaParamValidation : Object

Custom type definitions for excellent IDE auto complete support Properties

NameTypeDescription
param_valueany
param_namestring
expected_type,stringe.g. 'Object', 'String, 'Array', ...