@botmock-api/utils
Advanced tools
Comparing version 2.1.0 to 2.2.1
@@ -58,4 +58,2 @@ "use strict"; | ||
* @returns MessageCollector | ||
* | ||
* @beta | ||
*/ | ||
@@ -87,2 +85,34 @@ exports.createMessageCollector = function (map, getMessage) { | ||
/** | ||
* Wraps occurances of variables within utterance text with a given character. | ||
* | ||
* @remarks | ||
* This function is importable as {import { symmetricWrap } from "@botmock-api/utils"}. | ||
* | ||
* @param text - Utterance string. | ||
* @param charMap - Object with l and r properties containing characters to wrap with | ||
* @returns string | ||
* | ||
* @beta | ||
*/ | ||
exports.symmetricWrap = function (text, _a) { | ||
var l = _a.l, r = _a.r; | ||
var text_ = text; | ||
var numVariableCharsEncountered = 0; | ||
var BOTMOCK_VARIABLE_CHAR = "%"; | ||
var characters = text_.split("").map(function (c, i) { return ({ char: c, i: i }); }); | ||
for (var _i = 0, characters_1 = characters; _i < characters_1.length; _i++) { | ||
var _b = characters_1[_i], char = _b.char, i = _b.i; | ||
if (char === BOTMOCK_VARIABLE_CHAR) { | ||
numVariableCharsEncountered += 1; | ||
if (numVariableCharsEncountered % 2 !== 0) { | ||
text_ = text_.substr(0, i) + l + text_.substr(i + 1); | ||
} | ||
else { | ||
text_ = text_.substr(0, i) + r + text_.substr(i + 1); | ||
} | ||
} | ||
} | ||
return text_; | ||
}; | ||
/** | ||
* Creates linear order of messages such that if (m1, m2) is a connection in the | ||
@@ -89,0 +119,0 @@ * board, m1 appears before m2 in the linear order. |
{ | ||
"name": "@botmock-api/utils", | ||
"version": "2.1.0", | ||
"version": "2.2.1", | ||
"description": "utilities for handling data from the Botmock API", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -99,4 +99,2 @@ type Utterance = { | ||
* @returns MessageCollector | ||
* | ||
* @beta | ||
*/ | ||
@@ -129,3 +127,35 @@ export const createMessageCollector = (map: IntentMap, getMessage: any) => { | ||
type CharMap = { [key: string]: string }; | ||
/** | ||
* Wraps occurances of variables within utterance text with a given character. | ||
* | ||
* @remarks | ||
* This function is importable as {import { symmetricWrap } from "@botmock-api/utils"}. | ||
* | ||
* @param text - Utterance string. | ||
* @param charMap - Object with l and r properties containing characters to wrap with | ||
* @returns string | ||
* | ||
* @beta | ||
*/ | ||
export const symmetricWrap = (text: string, { l, r }: CharMap): string => { | ||
let text_ = text; | ||
let numVariableCharsEncountered = 0; | ||
const BOTMOCK_VARIABLE_CHAR = "%"; | ||
const characters = text_.split("").map((c, i) => ({ char: c, i })); | ||
for (const { char, i } of characters) { | ||
if (char === BOTMOCK_VARIABLE_CHAR) { | ||
numVariableCharsEncountered += 1; | ||
if (numVariableCharsEncountered % 2 !== 0) { | ||
text_ = text_.substr(0, i) + l + text_.substr(i + 1); | ||
} else { | ||
text_ = text_.substr(0, i) + r + text_.substr(i + 1); | ||
} | ||
} | ||
} | ||
return text_; | ||
}; | ||
/** | ||
* Creates linear order of messages such that if (m1, m2) is a connection in the | ||
@@ -132,0 +162,0 @@ * board, m1 appears before m2 in the linear order. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
410
17226
9