mirror of
https://github.com/jwetzell/osc-js.git
synced 2026-08-30 19:29:03 +00:00
npm run format:write
This commit is contained in:
+23
-23
@@ -37,23 +37,23 @@ export function messageToBuffer(message: OSCMessage): Uint8Array {
|
|||||||
throw new Error('problem encoding address');
|
throw new Error('problem encoding address');
|
||||||
}
|
}
|
||||||
|
|
||||||
let typeString = ','
|
let typeString = ',';
|
||||||
|
|
||||||
const flatOSCArgs: OSCArg[] = []
|
const flatOSCArgs: OSCArg[] = [];
|
||||||
|
|
||||||
message.args.forEach((oscArg)=> {
|
message.args.forEach((oscArg) => {
|
||||||
if(Array.isArray(oscArg)){
|
if (Array.isArray(oscArg)) {
|
||||||
typeString += '['
|
typeString += '[';
|
||||||
oscArg.forEach((oscArg)=>{
|
oscArg.forEach((oscArg) => {
|
||||||
typeString += oscArg.type
|
typeString += oscArg.type;
|
||||||
flatOSCArgs.push(oscArg)
|
flatOSCArgs.push(oscArg);
|
||||||
})
|
});
|
||||||
typeString += ']'
|
typeString += ']';
|
||||||
}else {
|
} else {
|
||||||
typeString += oscArg.type
|
typeString += oscArg.type;
|
||||||
flatOSCArgs.push(oscArg)
|
flatOSCArgs.push(oscArg);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
const typesBuffer = oscTypeConverterMap.s.toBuffer(typeString);
|
const typesBuffer = oscTypeConverterMap.s.toBuffer(typeString);
|
||||||
if (typesBuffer === undefined) {
|
if (typesBuffer === undefined) {
|
||||||
@@ -87,18 +87,18 @@ export function messageFromBuffer(bytes: Uint8Array): [OSCMessage | undefined, U
|
|||||||
for (let index = 1; index < typeString.length; index++) {
|
for (let index = 1; index < typeString.length; index++) {
|
||||||
const argType = typeString.charAt(index) as OSCType;
|
const argType = typeString.charAt(index) as OSCType;
|
||||||
|
|
||||||
if (argType === '['){
|
if (argType === '[') {
|
||||||
if (insideArgArray){
|
if (insideArgArray) {
|
||||||
throw new Error('osc arg array opened without closing previous arg array')
|
throw new Error('osc arg array opened without closing previous arg array');
|
||||||
}
|
}
|
||||||
oscArrayArg = [];
|
oscArrayArg = [];
|
||||||
insideArgArray = true;
|
insideArgArray = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argType === ']'){
|
if (argType === ']') {
|
||||||
if (!insideArgArray){
|
if (!insideArgArray) {
|
||||||
throw new Error('osc arg array closed without opening arg array')
|
throw new Error('osc arg array closed without opening arg array');
|
||||||
}
|
}
|
||||||
oscArgs.push(oscArrayArg);
|
oscArgs.push(oscArrayArg);
|
||||||
oscArrayArg = [];
|
oscArrayArg = [];
|
||||||
@@ -116,9 +116,9 @@ export function messageFromBuffer(bytes: Uint8Array): [OSCMessage | undefined, U
|
|||||||
type: argType,
|
type: argType,
|
||||||
value: value,
|
value: value,
|
||||||
};
|
};
|
||||||
if(insideArgArray){
|
if (insideArgArray) {
|
||||||
oscArrayArg.push(arg)
|
oscArrayArg.push(arg);
|
||||||
}else {
|
} else {
|
||||||
oscArgs.push(arg);
|
oscArgs.push(arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,13 +108,13 @@ const badTests = [
|
|||||||
{
|
{
|
||||||
description: 'bad string arg',
|
description: 'bad string arg',
|
||||||
message: { address: '/address', args: [{ type: 's', value: 123 }] },
|
message: { address: '/address', args: [{ type: 's', value: 123 }] },
|
||||||
throwsMessage: { name: /^TypeError$/, message: /non string/ },
|
throwsMessage: { name: /^TypeError$/, message: /non string/ },
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
description: 'bad integer arg',
|
description: 'bad integer arg',
|
||||||
message: { address: '/address', args: [{ type: 'i', value: 'hi' }] },
|
message: { address: '/address', args: [{ type: 'i', value: 'hi' }] },
|
||||||
throwsMessage: { name: /^TypeError$/, message: /non number/ },
|
throwsMessage: { name: /^TypeError$/, message: /non number/ },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: 'bad float arg',
|
description: 'bad float arg',
|
||||||
@@ -138,7 +138,7 @@ const badTests = [
|
|||||||
name: /^Error$/,
|
name: /^Error$/,
|
||||||
message: 'osc message must start with a /',
|
message: 'osc message must start with a /',
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
describe('OSC Message Encoding', () => {
|
describe('OSC Message Encoding', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user