@tv2media/command-transpiler
Advanced tools
Comparing version 1.3.1 to 1.4.0
@@ -5,3 +5,8 @@ import { IParser } from '../utilities/parser-combinator'; | ||
export declare function parseNumberLiteral(): IParser<number>; | ||
export declare function parseVarnameLiteral(): IParser<{ | ||
type: 'variable'; | ||
varname: string; | ||
}>; | ||
export declare function parseLiteral(): IParser<any>; | ||
export declare function parseExtendedLiteral(): IParser<any>; | ||
export declare function parseParens<T>(parser: IParser<T>): IParser<T>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseParens = exports.parseLiteral = exports.parseNumberLiteral = exports.parseStringLiteral = exports.parseVarname = void 0; | ||
exports.parseParens = exports.parseExtendedLiteral = exports.parseLiteral = exports.parseVarnameLiteral = exports.parseNumberLiteral = exports.parseStringLiteral = exports.parseVarname = void 0; | ||
const combinators_1 = require("../utilities/parser-combinator/combinators"); | ||
function parseVarname() { | ||
return combinators_1.lpipe(combinators_1.regex(/[a-zæøå_][a-zæøå0-9_]+/i), combinators_1.ws); | ||
return combinators_1.lpipe(combinators_1.regex(/[a-zæøå_][a-zæøå0-9_]*/i), combinators_1.ws); | ||
} | ||
@@ -17,2 +17,6 @@ exports.parseVarname = parseVarname; | ||
exports.parseNumberLiteral = parseNumberLiteral; | ||
function parseVarnameLiteral() { | ||
return combinators_1.map(parseVarname(), (varname) => ({ type: 'variable', varname })); | ||
} | ||
exports.parseVarnameLiteral = parseVarnameLiteral; | ||
function parseLiteral() { | ||
@@ -22,2 +26,6 @@ return combinators_1.any(parseStringLiteral(), parseNumberLiteral()); | ||
exports.parseLiteral = parseLiteral; | ||
function parseExtendedLiteral() { | ||
return combinators_1.any(parseStringLiteral(), parseNumberLiteral(), parseVarnameLiteral()); | ||
} | ||
exports.parseExtendedLiteral = parseExtendedLiteral; | ||
function parseParens(parser) { | ||
@@ -24,0 +32,0 @@ return combinators_1.pipe(combinators_1.string('('), combinators_1.ws, combinators_1.lpipe(parser, combinators_1.ws, combinators_1.string(')'))); |
@@ -5,5 +5,8 @@ import { IModifier, IInterpreterContext, IInterpret } from '../../common/types'; | ||
export declare function interpretEqual({ varname, args }: IInterpreterContext): IInterpret; | ||
export declare function interpretGreater({ varname, args }: IInterpreterContext): IInterpret; | ||
export declare function interpretLess({ varname, args }: IInterpreterContext): IInterpret; | ||
export declare function interpretDefault({ varname, args }: IInterpreterContext): IInterpret; | ||
export declare function interpretNot({ varname }: IInterpreterContext): IInterpret; | ||
export declare function interpretExists({ varname }: IInterpreterContext): IInterpret; | ||
export declare function interpretExist({ varname }: IInterpreterContext): IInterpret; | ||
export declare function interpretIn({ varname, args }: IInterpreterContext): IInterpret; | ||
export default function interpretModifier({ modifier: type, args }: IModifier, varname: string): IInterpret; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.interpretExists = exports.interpretNot = exports.interpretDefault = exports.interpretEqual = exports.interpretToString = exports.interpretLength = void 0; | ||
exports.interpretIn = exports.interpretExist = exports.interpretNot = exports.interpretDefault = exports.interpretLess = exports.interpretGreater = exports.interpretEqual = exports.interpretToString = exports.interpretLength = void 0; | ||
const interpreter_1 = require("../../base/interpreter"); | ||
function interpretLength({ varname }) { | ||
@@ -13,5 +14,13 @@ return (store) => ({ ...store, [varname]: store[varname].length ? store[varname].length : 0 }); | ||
function interpretEqual({ varname, args }) { | ||
return (store) => ({ ...store, [varname]: store[varname] === args.value }); | ||
return (store) => ({ ...store, [varname]: store[varname] === interpreter_1.evalLiteral(args.value, store) }); | ||
} | ||
exports.interpretEqual = interpretEqual; | ||
function interpretGreater({ varname, args }) { | ||
return (store) => ({ ...store, [varname]: store[varname] > interpreter_1.evalLiteral(args.value, store) }); | ||
} | ||
exports.interpretGreater = interpretGreater; | ||
function interpretLess({ varname, args }) { | ||
return (store) => ({ ...store, [varname]: store[varname] < interpreter_1.evalLiteral(args.value, store) }); | ||
} | ||
exports.interpretLess = interpretLess; | ||
function interpretDefault({ varname, args }) { | ||
@@ -25,6 +34,29 @@ return (store) => ({ ...store, [varname]: store[varname] === undefined ? args.value : store[varname] }); | ||
exports.interpretNot = interpretNot; | ||
function interpretExists({ varname }) { | ||
function interpretExist({ varname }) { | ||
return (store) => ({ ...store, [varname]: varname in store && store[varname] !== undefined }); | ||
} | ||
exports.interpretExists = interpretExists; | ||
exports.interpretExist = interpretExist; | ||
// TODO: Redefine | ||
function interpretIn({ varname, args }) { | ||
return (store) => { | ||
let value = args.value; | ||
// Variable name | ||
if (typeof args.value === 'object' && args.value.type === 'variable') { | ||
if (args.value.varname in store) { | ||
const varValue = store[args.value.varname]; | ||
if (typeof varValue === 'string') { | ||
value = varValue.split(','); | ||
} | ||
else { | ||
value = Array.isArray(varValue) ? varValue : [varValue]; | ||
} | ||
} | ||
else { | ||
throw Error(`Variable ${args.value.varname} is undefined.`); | ||
} | ||
} | ||
return { ...store, [varname]: value.includes(store[varname]) }; | ||
}; | ||
} | ||
exports.interpretIn = interpretIn; | ||
// TODO: Check how to best use type here | ||
@@ -38,4 +70,7 @@ function interpretModifier({ modifier: type, args }, varname) { | ||
case 'equal': return interpretEqual(context); | ||
case 'greater': return interpretGreater(context); | ||
case 'less': return interpretLess(context); | ||
case 'not': return interpretNot(context); | ||
case 'exists': return interpretExists(context); | ||
case 'exist': return interpretExist(context); | ||
case 'in': return interpretIn(context); | ||
default: | ||
@@ -42,0 +77,0 @@ throw Error(`Unknown General modifier: ${type}`); |
@@ -7,3 +7,6 @@ import { IParser } from '../../utilities/parser-combinator'; | ||
export declare function parseEqual(): IParser<IModifier>; | ||
export declare function parseGreater(): IParser<IModifier>; | ||
export declare function parseLess(): IParser<IModifier>; | ||
export declare function parseNot(): IParser<IModifier>; | ||
export declare function parseExists(): IParser<IModifier>; | ||
export declare function parseExist(): IParser<IModifier>; | ||
export declare function parseIn(): IParser<IModifier>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseExists = exports.parseNot = exports.parseEqual = exports.parseDefault = exports.parseToString = exports.parseLength = void 0; | ||
exports.parseIn = exports.parseExist = exports.parseNot = exports.parseLess = exports.parseGreater = exports.parseEqual = exports.parseDefault = exports.parseToString = exports.parseLength = void 0; | ||
const combinators_1 = require("../../utilities/parser-combinator/combinators"); | ||
@@ -16,16 +16,36 @@ const parser_1 = require("../../base/parser"); | ||
function parseDefault() { | ||
return combinators_1.map(combinators_1.pipe(combinators_1.string('default'), combinators_1.ws1, parser_1.parseLiteral()), (value) => ({ domain, modifier: 'default', args: { value } })); | ||
return combinators_1.map(combinators_1.pipe(combinators_1.string('default'), combinators_1.ws1, parser_1.parseLiteral()), (value) => ({ | ||
domain, | ||
modifier: 'default', | ||
args: { value }, | ||
})); | ||
} | ||
exports.parseDefault = parseDefault; | ||
function parseEqual() { | ||
return combinators_1.map(combinators_1.pipe(combinators_1.string('equal'), combinators_1.ws1, parser_1.parseLiteral()), (value) => ({ domain, modifier: 'equal', args: { value } })); | ||
return combinators_1.map(combinators_1.pipe(combinators_1.string('equal'), combinators_1.ws1, parser_1.parseExtendedLiteral()), (value) => ({ domain, modifier: 'equal', args: { value } })); | ||
} | ||
exports.parseEqual = parseEqual; | ||
function parseGreater() { | ||
return combinators_1.map(combinators_1.pipe(combinators_1.string('greater'), combinators_1.ws1, combinators_1.any(parser_1.parseNumberLiteral(), parser_1.parseVarnameLiteral())), (value) => ({ domain, modifier: 'greater', args: { value } })); | ||
} | ||
exports.parseGreater = parseGreater; | ||
function parseLess() { | ||
return combinators_1.map(combinators_1.pipe(combinators_1.string('less'), combinators_1.ws1, combinators_1.any(parser_1.parseNumberLiteral(), parser_1.parseVarnameLiteral())), (value) => ({ domain, modifier: 'less', args: { value } })); | ||
} | ||
exports.parseLess = parseLess; | ||
function parseNot() { | ||
return combinators_1.map(combinators_1.string('not'), () => ({ domain, modifier: 'not' })); | ||
return combinators_1.map(combinators_1.string('not'), (modifier) => ({ domain, modifier })); | ||
} | ||
exports.parseNot = parseNot; | ||
function parseExists() { | ||
return combinators_1.map(combinators_1.string('exists'), () => ({ domain, modifier: 'exists' })); | ||
function parseExist() { | ||
return combinators_1.map(combinators_1.string('exist'), (modifier) => ({ domain, modifier })); | ||
} | ||
exports.parseExists = parseExists; | ||
exports.parseExist = parseExist; | ||
function parseIn() { | ||
return combinators_1.map(combinators_1.pipe(combinators_1.string('in'), combinators_1.any(combinators_1.pipe(combinators_1.ws1, parser_1.parseVarnameLiteral()), combinators_1.many1(combinators_1.pipe(combinators_1.ws1, parser_1.parseLiteral())))), (value) => ({ | ||
domain, | ||
modifier: 'in', | ||
args: { value }, | ||
})); | ||
} | ||
exports.parseIn = parseIn; |
@@ -6,2 +6,5 @@ "use strict"; | ||
} | ||
function interpretToInteger({ varname }) { | ||
return (store) => ({ ...store, [varname]: parseInt(store[varname], 10) }); | ||
} | ||
function interpretInc({ varname, args }) { | ||
@@ -33,2 +36,4 @@ return (store) => ({ ...store, [varname]: store[varname] + args.amount }); | ||
return interpretAbs(context); | ||
case 'toInteger': | ||
return interpretToInteger(context); | ||
default: | ||
@@ -35,0 +40,0 @@ throw Error('Unknown Number modifier: ' + type); |
@@ -11,4 +11,6 @@ "use strict"; | ||
function indexOfBasename(path) { | ||
let index = path.search(/((?!(\/|\\(?! ))).)+(\/|\\)?$/); | ||
return index >= 0 ? index : 0; | ||
const pathMount = /^(\\\\+|[A-ZÆØÅ]+:)/.test(path) ? mount(path) : ''; | ||
const pathOffset = pathMount.length; | ||
const index = path.replace(pathMount, '').search(/((?!(\/|\\(?! ))).)+(\/|\\)?$/); | ||
return (index >= 0 ? index : 0) + pathOffset; | ||
} | ||
@@ -15,0 +17,0 @@ function dir(path) { |
{ | ||
"name": "@tv2media/command-transpiler", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "Transpiles commands from one protocol to another.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
68935
90
1652