@botmock-api/utils
Advanced tools
Comparing version 0.3.0 to 0.4.0
51
index.js
@@ -1,50 +0,1 @@ | ||
// Return a map associating message id and array of intent ids connected to it | ||
exports.createIntentMap = (messages = []) => { | ||
return new Map( | ||
messages.reduce( | ||
(acc, { next_message_ids }) => [ | ||
...acc, | ||
...next_message_ids | ||
.filter(({ intent }) => intent.value) | ||
// Group this message with this intent and others like it (in that they | ||
// also are incident on this message) | ||
.map(message => [ | ||
message.message_id, | ||
[ | ||
message.intent.value, | ||
...messages.reduce( | ||
(acc, { next_message_ids }) => [ | ||
...acc, | ||
// Must have an intent, must not be the one we already have, | ||
// and must be incident on this message | ||
...next_message_ids | ||
.filter( | ||
({ intent, message_id }) => | ||
intent.value && | ||
intent.value !== message.intent.value && | ||
message_id === message.message_id | ||
) | ||
.map(m => m.intent.value) | ||
], | ||
[] | ||
) | ||
] | ||
]) | ||
], | ||
[] | ||
) | ||
); | ||
}; | ||
exports.createNodeCollector = (map, getMessage) => | ||
function f(next, collected = []) { | ||
for (const { message_id } of next) { | ||
// If the provided intent map does not have this message id, recur with | ||
// this id appended to `collected` | ||
if (!map.has(message_id)) { | ||
const { next_message_ids } = getMessage(message_id); | ||
return f(next_message_ids, [...collected, message_id]); | ||
} | ||
} | ||
return collected; | ||
}; | ||
export { createIntentMap, createNodeCollector } from './src'; |
{ | ||
"name": "@botmock-api/utils", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "utilities for handling data from the Botmock API", | ||
"main": "index.js", | ||
"module": "index.js", | ||
"module": "main.js", | ||
"scripts": { | ||
@@ -23,3 +23,5 @@ "test": "jest" | ||
"license": "MIT", | ||
"dependencies": {}, | ||
"dependencies": { | ||
"esm": "3.2.22" | ||
}, | ||
"devDependencies": { | ||
@@ -26,0 +28,0 @@ "jest": "24.7.1" |
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
10606
8
62
1
+ Addedesm@3.2.22
+ Addedesm@3.2.22(transitive)