@gs-libs/utils
v1.2.1
Published
This package contains GS's most commonly used utility functions
Downloads
2
Readme
GS Utilities Package
This package contains GS's most commonly used utility functions
Util Functions
decodeHtml
When we fetch a hub story using JSBridge-API
, the description
and the title
of the story in mobile platforms are returned with encoded char. And we need to decode them before displaying it.
import { decodeHtml } from '@gs-libs/utils'
const encodedNoHTML =
'Welcome to our New Partner© & Strategy™ Portal!';
const decoded = decodeHtml(encodedNoHTML); // => Welcome to our New Partner© & Strategy™ Portal!
encodeHtml
import { encodeHtml } from '@gs-libs/utils'
const decodedHtml =
'Welcome to our New Partner© & Strategy™ Portal!';
const encoded = encodeHtml(decodedHtml); // => Welcome to our New Partner© & Strategy™ Portal!
ensure
To make sure a promise doesn't throw and wrap the result into the Result object.
import { ensure } from '@gs-libs/utils';
import { BridgeServices, Story } from '@gs-libs/bridge';
const bridge = new BridgeServices();
// ------ The below code is possible to throw ------
const data = await bridge.getEntity<Story>({
entityName: 'story', id: 123
});
const storyTitle = data.title;
// ------ The below code won't throw ------
const data = await ensure(() => bridge.getEntity<Story>({
entityName: 'story',
id: 123
}))
if (data.hasError) {
...
} eles {
const storyTitle = data.value.title;
}