{"id":22924,"date":"2019-11-26T07:12:38","date_gmt":"2019-11-26T07:12:38","guid":{"rendered":"https:\/\/developer.kore.ai\/v7-1\/?p=22924"},"modified":"2019-11-26T10:06:38","modified_gmt":"2019-11-26T10:06:38","slug":"koreutil-libraries","status":"publish","type":"post","link":"https:\/\/developer.kore.ai\/v7-1\/docs\/bots\/advanced-topics\/koreutil-libraries\/","title":{"rendered":"koreUtil Libraries"},"content":{"rendered":"<section class=\"l-section wpb_row height_auto\"><div class=\"l-section-h i-cf\"><div class=\"g-cols vc_row type_default valign_top\"><div class=\"vc_col-sm-12 wpb_column vc_column_container\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<p><strong>koreUtil libraries<\/strong> provide pre-written JavaScript functions which makes common or complex tasks easy to implement. These libraries often target specific tasks such as setting up recurring rules for calendar, parsing and manipulation of dates, conversion of dates between timezone, tools to simplify programming with strings, numbers, arrays, functions and objects etc.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"How_to_Use\">How to Use<\/span><\/h2>\n<p>koreUtil libraries can be used anywhere in the bot where there is a flexibility to write JavaScript code such as script node, message node, confirmation node, entity node, standard responses, answers to FAQs, small talk, event handlers etc.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"List_of_koreUtil_libraries\">List of koreUtil libraries<\/span><\/h2>\n<p>Below is the list of koreUtil libraries provided by the platform:<\/p>\n<ul>\n<li><a href=\"#koreUtilrrule\">koreUtil.rrule<\/a><\/li>\n<li><a href=\"#koreUtilmoment\">koreUtil.moment<\/a><\/li>\n<li><a href=\"#koreUtilintl\">koreUtil.intl<\/a><\/li>\n<li><a href=\"#koreUtilmomenttz\">koreUtil.momenttz<\/a><\/li>\n<li><a href=\"#koreUtilxml2js\">koreUtil.xml2js<\/a><\/li>\n<li><a href=\"#koreUtilhash\">koreUtil.hash<\/a><\/li>\n<li><a href=\"#koreUtil\">koreUtil._<\/a><\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"koreUtilrrule\">koreUtil.rrule<\/span><\/h3>\n<p>koreUtil.rrule is platform offered JS library for creating new recurrence rules, interpreting and reading them in human readable format. This library is backed by rrule npm module version 2.2.0 installed on Kore.ai server. For more details on using rrule <a href=\"https:\/\/www.npmjs.com\/package\/rrule\/v\/2.2.0\" target=\"_blank\" rel=\"noopener noreferrer\">refer here<\/a>.<\/p>\n<p><b>Usage Example:<\/b><br \/>\n<code>context.rule = new koreUtil.rrule({<br \/>\nfreq: koreUtil.rrule.WEEKLY,<br \/>\ninterval: 5,<br \/>\nbyweekday: [koreUtil.rrule.MO, koreUtil.rrule.FR],<br \/>\ndtstart: new Date(2012, 1, 1, 10, 30),<br \/>\nuntil: new Date(2012, 12, 31)<br \/>\n});<\/code><br \/>\n<code>context.between=context.rule.between(new Date(2012, 7, 1), new Date(2012, 8, 1));<\/code><br \/>\n<code>context.readableFormat=context.rule.toText();<\/code><\/p>\n<p><b>Output:<\/b><\/p>\n<ul>\n<li>For context.between<br \/>\n<code>[<br \/>\n\"2012-08-27T10:30:00.000Z\",<br \/>\n\"2012-08-31T10:30:00.000Z\"<br \/>\n]<\/code><\/li>\n<li>For context.readableFormat<br \/>\n<code>every 5 weeks on Monday, Friday until January 31, 2013<\/code><\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"koreUtilmoment\">koreUtil.moment<\/span><\/h3>\n<p>koreUtil.moment is platform offered JS library for validating, manipulating, and formatting dates. This library is backed by moment npm module version 2.19.2 installed on Kore.ai server. For more details on using moment <a href=\"https:\/\/www.npmjs.com\/package\/moment\/v\/2.19.2\" target=\"_blank\" rel=\"noopener noreferrer\">refer here<\/a>.<\/p>\n<p><b>Usage Example:<\/b><br \/>\n<code>context.german=koreUtil.moment().locale('de').format('LLLL');<\/code><\/p>\n<p><b>Output:<\/b><br \/>\nFor context.german:<br \/>\n<code>Montag, 18. November 2019 01:43<\/code><\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"koreUtilintl\">koreUtil.intl<\/span><\/h3>\n<p>koreUtil.intl is platform offered JS library for language specific string comparison, number formatting, and date and time formatting. This library is backed by intl npm module version 1.2.5 installed on Kore.ai server. For more details on using intl <a href=\"https:\/\/www.npmjs.com\/package\/intl\/v\/1.2.5\" target=\"_blank\" rel=\"noopener noreferrer\">refer here<\/a>.<\/p>\n<p><b>Usage Example:<\/b><br \/>\n<code>context.formattedNumberUK = koreUtil.intl.NumberFormat('en-GB').format(123456.789);<br \/>\nvar date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));<br \/>\ncontext.USdate=koreUtil.intl.DateTimeFormat('en-US').format(date);<\/code><\/p>\n<p><b>Output:<\/b><\/p>\n<ul>\n<li>For context.formattedNumberUK:<br \/>\n<code>123,456.789<\/code><\/li>\n<li>For context.USdate<br \/>\n<code>12\/20\/2012<\/code><\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"koreUtilmomenttz\">koreUtil.momenttz<\/span><\/h3>\n<p>koreUtil.momenttz is platform offered JS library for formatting of dates in any timezone and convert dates between timezones. This library is backed by moment-timezone npm module version 0.4.1 installed on Kore.ai server is 0.4.1. For more details on using momenttz <a href=\"https:\/\/www.npmjs.com\/package\/moment-timezone\/v\/0.4.1\" target=\"_blank\" rel=\"noopener noreferrer\">refer here<\/a>.<\/p>\n<p><b>Usage Example:<\/b><br \/>\n<code>var jun = koreUtil.moment(\"2014-06-01T12:00:00Z\");<br \/>\ncontext.newyork= koreUtil.momenttz(jun,'America\/New_York').format('ha z');<br \/>\ncontext.tokyo = koreUtil.moment().tz('Asia\/Tokyo').format('ha z');<br \/>\ncontext.sydney = koreUtil.moment().tz('Australia\/Sydney').format('ha z');<\/code><\/p>\n<p><b>Output:<\/b><\/p>\n<ul>\n<li>For context.newyork:<br \/>\n<code>5am PDT<\/code><\/li>\n<li>For context.tokyo:<br \/>\n<code>7pm JST<\/code><\/li>\n<li>For context.sydney:<br \/>\n<code>9pm AEDT<\/code><\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"koreUtilxml2js\">koreUtil.xml2js<\/span><\/h3>\n<p>koreUtil.xml2js is platform offered JS library for parsing xml to json and vice versa. This library is backed by xml2js npm version 0.4.19 installed on Kore.ai server. More details on using xml2js <a href=\"https:\/\/www.npmjs.com\/package\/xml2js\/v\/0.4.19\" target=\"_blank\" rel=\"noopener noreferrer\">refer here<\/a>.<\/p>\n<p><b>Usage Example:<\/b><br \/>\n<code>var obj = {name: \"John\", Surname: \"Doe\", age: 23};<br \/>\nvar builder = new koreUtil.xml2js.Builder();<br \/>\ncontext.xml = builder.buildObject(obj);<\/code><\/p>\n<p><b>Output:<\/b><\/p>\n<ul>\n<li>For context.xml:<br \/>\n<code><!--?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?-->  John Doe 23 <\/code><\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"koreUtilhash\">koreUtil.hash<\/span><\/h3>\n<p>koreUtil.hash is platform offered JS library that supports SHA on JavaScript. The library is backed by sha.js npm module version 2.4.9 installed on Kore.ai server. For more details <a href=\"https:\/\/www.npmjs.com\/package\/sha.js\/v\/2.4.9\" target=\"_blank\" rel=\"noopener noreferrer\">refer here<\/a>.<\/p>\n<p><b>Usage Example:<\/b><br \/>\n<code>context.hashString= koreUtil.hash('sha256').update('42').digest('hex');<\/code><\/p>\n<p><b>Output:<\/b><\/p>\n<ul>\n<li>For context.hashString:<br \/>\n<code>73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049<\/code><\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"koreUtil\">koreUtil._<\/span><\/h3>\n<p>koreUtil._ is a platform offered JS library which provides utility functions for common programming tasks. This library is backed by lodash.js npm module version 3.10.1 installed on Kore.ai server. For more details <a href=\"https:\/\/www.npmjs.com\/package\/lodash\/v\/3.10.1\" target=\"_blank\" rel=\"noopener noreferrer\">refer here<\/a>.<\/p>\n<p><b>Usage Example:<\/b><br \/>\n<code>context.chunkArray = koreUtil._.chunk(['a', 'b', 'c', 'd'], 2);<br \/>\nvar users = [<br \/>\n{ 'user': 'barney', 'age': 36, 'active': true },<br \/>\n{ 'user': 'fred',   'age': 40, 'active': false }<br \/>\n];<br \/>\ncontext.filterActive =koreUtil._.pluck(koreUtil._.filter(users, { 'age': 36, 'active': true }), 'user');<\/code><\/p>\n<p><b>Output:<\/b><\/p>\n<ul>\n<li>For context.chunkArray:<br \/>\n<code>[[\"a\",\"b\"],[\"c\",\"d\"]]<\/code><\/li>\n<li>For context.filterActive:<br \/>\n<code>[<br \/>\n\"barney\"<br \/>\n]<\/code><\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/section>\n","protected":false},"excerpt":{"rendered":"koreUtil libraries provide pre-written JavaScript functions which makes common or complex tasks easy to implement. These libraries often target specific tasks such as setting up recurring rules for calendar, parsing and manipulation of dates, conversion of dates between timezone, tools to simplify programming with strings, numbers, arrays, functions and objects etc. How to Use koreUtil...","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-22924","post","type-post","status-publish","format-standard","hentry","category-advanced-topics"],"_links":{"self":[{"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/posts\/22924","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/comments?post=22924"}],"version-history":[{"count":5,"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/posts\/22924\/revisions"}],"predecessor-version":[{"id":22934,"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/posts\/22924\/revisions\/22934"}],"wp:attachment":[{"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/media?parent=22924"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/categories?post=22924"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/tags?post=22924"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}