~didrocks/+junk/face-detection-15.04

« back to all changes in this revision

Viewing changes to facedetection/www/bower_components/prism/tests/helper/token-stream-transformer.js

  • Committer: Didier Roche
  • Date: 2016-05-10 23:09:11 UTC
  • Revision ID: didier.roche@canonical.com-20160510230911-c7xr490zrj3yrzxd
New version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"use strict";
 
2
 
 
3
 
 
4
module.exports = {
 
5
        /**
 
6
         * Simplifies the token stream to ease the matching with the expected token stream.
 
7
         *
 
8
         * * Strings are kept as-is
 
9
         * * In arrays each value is transformed individually
 
10
         * * Values that are empty (empty arrays or strings only containing whitespace)
 
11
         *
 
12
         *
 
13
         * @param {Array} tokenStream
 
14
         * @returns {Array.<string[]|Array>}
 
15
         */
 
16
        simplify: function (tokenStream) {
 
17
                if (Array.isArray(tokenStream)) {
 
18
                        return tokenStream
 
19
                                .map(this.simplify.bind(this))
 
20
                                .filter(function (value) {
 
21
                                        return !(Array.isArray(value) && !value.length) && !(typeof value === "string" && !value.trim().length);
 
22
                                }
 
23
                        );
 
24
                }
 
25
                else if (typeof tokenStream === "object") {
 
26
                        return [tokenStream.type, this.simplify(tokenStream.content)];
 
27
                }
 
28
                else {
 
29
                        return tokenStream;
 
30
                }
 
31
        }
 
32
};