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
Param | Type |
---|---|
source | Object |
addition | Object |
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
Param | Type |
---|---|
value | any |
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.
Param | Type |
---|---|
params | Array.<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
Param | Type | Description |
---|---|---|
text | string | to cut |
leading_characters | string | to 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
Param | Type | Description |
---|---|---|
text | string | to cut |
trailing_characters | string | to cut from text |
Example
.cutLeadingCharacters('/some/path/file.ext','.ext')
// => 'some/path/file'
SipaHelper.constantizeString(constant) → *
Transform the given string into its constant representation.
Param | Type |
---|---|
constant | string |
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
Name | Type | Description |
---|---|---|
param_value | any | |
param_name | string | |
expected_type, | string | e.g. 'Object', 'String, 'Array', ... |