-
Notifications
You must be signed in to change notification settings - Fork 3
Utility Functions
This page contains some utility functions that will help you checking parameter types and working with the local storage.
This is a list of functions that can specify whether a variable has the specified type or not.
- chayns.utils.isHex(parameter, boolean)
//second parameter determines if shorthand hexadecimals are allowed - chayns.utils.isArray(parameter)
- chayns.utils.isBLEAdress(parameter)
- chayns.utils.isPresent(parameter)
- chayns.utils.isBlank(parameter)
- chayns.utils.isDate(parameter)
- chayns.utils.isDefined(parameter)
- chayns.utils.isFormData(parameter)
- chayns.utils.isFunction(parameter)
- chayns.utils.isGUID(parameter)
- chayns.utils.isMacAdress(parameter)
- chayns.utils.isNumber(parameter)
- chayns.utils.isObject(parameter)
- chayns.utils.isPromise(parameter)
- chayns.utils.isString(parameter)
- chayns.utils.isUUID(parameter)
- chayns.utils.isUndefined(parameter)
- chayns.utils.isDeferred(parameter)
- chayns.utils.isJwt(parameter)
- chayns.utils.isUrl(parameter)
The localStorage stores data into the cache of a browser. The data will not be deleted when the browser is closed and will be available on the next use.
Supported Platforms
- Android
- iOS
- ChaynsWeb
Assignes the value to the key and saves it into the local storage.
Parameter
- key : string - The key that should be assigned to the value.
- value : string - The value you want to store.
chayns.utils.ls.set('myKey', 'myValue');
Retrieves the value that is assigned to the key.
Parameter
- key : string - The key of the entry you want to receive.
chayns.dialog.alert('', chayns.utils.ls.get('myKey'));
Removes the value from the local storage.
Parameter
- key : string - The key of the entry you want to remove.
chayns.utils.ls.remove('myKey')
These functions will support you in different situation but don't refer to the other categories. Take a look at the table of contents to get an overview of the additional chayns functions.
Returns the Payload of a tobit accesstoken.
Parameter
- tobitAccessToken : string - The tobitAccessToken from the current user object.
Result
- FacebookUserID : string - The id of the users facebook profile.
- FirstName : string - The firstname of the current user.
- LastName : string - The lastname of the current user.
- PersonID : string - The personId of the current user. For internal usage.
- LocationID : int - The id of the location this accessToken was generated.
- TobitUserID : int - The id of the current tobit user.
- LoginType : int - Specifies whether the user has logged in via facebook or chayns login.
- isAdmin : boolean - If true the user is member of the chayns manager uac group.
console.log(chayns.utils.getJwtPayload(chayns.env.user.tobitAccessToken));
This method mixes the site color with a color code (hex value, optional) and returns the result color with the given saturation.
Parameter
- saturation : int - Saturation of the returned color.
- color : string - Hex value.
Result
- color : string - Hex value.
console.log(
chayns.utils.colors.get(50, '#abceee');
);
This method mixes two color codes (hex values) and returns the result color with the given saturation.
Parameter
- color1 : string - Hex value.
- color2 : string - Hex value.
- saturation : int - Saturation of the returned color.
Result
- color : string - Hex value.
console.log(
chayns.utils.colors.mix('#789eee', '#abceee', 75)
);
This method returns the requested chayns color.
Parameter
- colorId : string - Name of the color (e.g. 100, text, primary, green-2...)
Result
- color : string - Hex value.
console.log(
chayns.utils.colors.getColorFromPalette('305'),
chayns.utils.colors.getColorFromPalette('headline')
);
This method generates optimized image URLs for tsimg.space and tsimg.cloud image URLs.
Parameter
- url : string - Image URL.
- height (optional) : int - Height the image should have. If set to null or 0, the height won't be set.
- width (optional) : int - Width the image should have. If set to null or 0, the width won't be set.
- preventWebP (optional) : bool - Prevent webP usage.
Result
- url : string - Scaled/optimized URL.
console.log(
chayns.utils.getScaledImageUrl("https://tsimg.cloud/59140-09519/487ed957cce6f7c0cc5fa770a4d3c359ec71d0ac.jpg",200, 200)
);
<!-- To get started.. -->
<!-- Load the chayns API styles and JavaScript from our server -->
<!-- css styles -->
<script src="https://api.chayns-static.space/css/v4/compatibility/compatibility.min.js" version="4.2"></script>
<!-- js api -->
<script src="https://api.chayns-static.space/js/v4.0/chayns.min.js"></script>