source: trip-planner-front/node_modules/adjust-sourcemap-loader/lib/process/test-codec.js@ 6a80231

Last change on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[6a3a178]1'use strict';
2
3var assert = require('assert');
4
5/**
6 * Reducer function that converts a codec list to a hash.
7 * @throws Error on bad codec
8 * @param {{name:string, decode:function, encode:function, root:function}} candidate A possible codec
9 * @returns True where an error is not thrown
10 */
11function testCodec(candidate) {
12 assert(
13 !!candidate && (typeof candidate === 'object'),
14 'Codec must be an object'
15 );
16 assert(
17 (typeof candidate.name === 'string') && /^[\w-]+$/.test(candidate.name),
18 'Codec.name must be a kebab-case string'
19 );
20 assert(
21 (typeof candidate.decode === 'function') && (candidate.decode.length === 1),
22 'Codec.decode must be a function that accepts a single source string'
23 );
24 assert(
25 (typeof candidate.encode === 'undefined') ||
26 ((typeof candidate.encode === 'function') && (candidate.encode.length === 1)),
27 'Codec.encode must be a function that accepts a single absolute path string, or else be omitted'
28 );
29 assert(
30 (typeof candidate.root === 'undefined') ||
31 (typeof candidate.root === 'function') && (candidate.root.length === 0),
32 'Codec.root must be a function that accepts no arguments, or else be omitted'
33 );
34 return true;
35}
36
37module.exports = testCodec;
Note: See TracBrowser for help on using the repository browser.