Socket
Socket
Sign inDemoInstall

@botmock-api/utils

Package Overview
Dependencies
Maintainers
3
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@botmock-api/utils - npm Package Compare versions

Comparing version 2.1.0 to 2.2.1

test/index.test.ts

34

dist/index.js

@@ -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.

2

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc