@voiceflow/common
Version:
Junk drawer of utility functions
25 lines (24 loc) • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createChannel = exports.Channel = exports.typeFactory = exports.createAsyncAction = exports.createAction = void 0;
const typescript_fsa_1 = require("typescript-fsa");
exports.createAction = (0, typescript_fsa_1.actionCreatorFactory)();
const createAsyncAction = (type, commonMeta) => exports.createAction.async(type, commonMeta);
exports.createAsyncAction = createAsyncAction;
const typeFactory = (...parts) => (name) => [...parts, name].join('.');
exports.typeFactory = typeFactory;
class Channel {
constructor(variables, build) {
this.variables = variables;
this.build = build;
}
buildMatcher() {
return this.build(this.variables.reduce((acc, key) => Object.assign(acc, { [key]: `:${key}` }), {}));
}
extend(variables, build) {
return new Channel([...this.variables, ...variables], (params) => `${this.build(params)}/${build(params)}`);
}
}
exports.Channel = Channel;
const createChannel = (variables, build) => new Channel(variables, build);
exports.createChannel = createChannel;