tencent cloud

All product documents
Tencent Cloud Observability Platform
Common Functions
Last updated: 2025-03-10 22:14:18
Common Functions
Last updated: 2025-03-10 22:14:18

Public JavaScript Library

Native JavaScript syntax is fully supported. For details, see JavaScript Standard Built-in Objects. Below are some basic demos.
Create a JavaScript Date Instance
// Create a JavaScript Date Instance
export default function () {
// supported date functions, refer: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date
console.log(new Date('1995-12-17T03:24:00')); // Sun Dec 17 1995 11:24:00 GMT+0800 (CST)
};
JSON Parse and Stringify
// JSON parse and stringify

export default function () {
const jsonStr = `{
"name": "pts",
"language": "javascript"
}`;
// parse json string to json object
const jsonObj = JSON.parse(jsonStr);
console.log(jsonObj.name); // pts
// convert json string to json object
const convertedStr = JSON.stringify(jsonObj);
console.log(convertedStr); // {"name":"pts","language":"javascript"}
};
Use Math Functions
// Use Math functions
export default function () {
// supported math functions, refer: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Math
console.log(Math.pow(2, 10)); // 1024
// Returns a random integer from 0 to 9:
console.log(Math.floor(Math.random() * 10));
};
Use RegExp Object for Matching Text with Pattern
// Use RegExp Object for matching text with pattern
export default function () {
// supported regexp functions, refer: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/RegExp
let re = /(\w+)\s(\w+)/;
let str = "John Smith";
let newStr = str.replace(re, "$2, $1");
console.log(newStr); // Smith, John
};

PTS Expansion Library

Base64 Encode & Decode
// Base64 Encode & Decode
import util from 'pts/util';

export default function () {
const base64Encoded = util.base64Encoding("Hello, world");
console.log(base64Encoded); // SGVsbG8sIHdvcmxk

const base64Decoded = util.base64Decoding(base64Encoded);
console.log(base64Decoded); // Hello, world
}
Generate UUID
// Generate UUID
import util from 'pts/util';

export default function () {
console.log(util.uuid()); // 5fbf1e59-cabf-469b-9d9f-6622e97de1ec
}


Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support