mirror of
https://github.com/jwetzell/osc-js.git
synced 2026-08-15 04:03:41 +00:00
switch sendosc to osc library
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
const oscTypeConverterMap = {
|
||||
s: {
|
||||
fromString: (string) => string,
|
||||
},
|
||||
f: {
|
||||
fromString: (string) => Number.parseFloat(string),
|
||||
},
|
||||
i: {
|
||||
fromString: (string) => Number.parseInt(string, 10),
|
||||
},
|
||||
b: {
|
||||
fromString: (string) => Buffer.from(string, 'hex'),
|
||||
},
|
||||
};
|
||||
|
||||
function argToTypedArg(rawArg, type = 's') {
|
||||
const typeConverter = oscTypeConverterMap[type];
|
||||
if (typeConverter === undefined) {
|
||||
throw new Error('osc type error: unknown type '.concat(type));
|
||||
}
|
||||
|
||||
if (typeConverter.fromString === undefined) {
|
||||
throw new Error('osc type error: no string converter for type '.concat(type));
|
||||
}
|
||||
|
||||
return typeConverter.fromString(rawArg);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
argToTypedArg,
|
||||
};
|
||||
Reference in New Issue
Block a user