Bug 1890689 accumulate input in LargerReceiverBlockSizeThanDesiredBuffering GTest...
[gecko.git] / devtools / client / shared / classnames.js
blobe10b256b0374d34007606d84a21b5b6ee8c4a54a
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 "use strict";
6 /**
7  * Take any number of parameters and returns a space-concatenated string.
8  * If a parameter is a non-empty string, it's automatically added to the result.
9  * If a parameter is an object, for each entry, if the value is truthy, then the key
10  * is added to the result.
11  *
12  * For example: `classnames("hi", null, undefined, false, { foo: true, bar: false })` will
13  * return `"hi foo"`
14  *
15  *
16  * @param  {...string|object} argss
17  * @returns String
18  */
19 module.exports = function (...args) {
20   let className = "";
22   for (const arg of args) {
23     if (!arg) {
24       continue;
25     }
27     if (typeof arg == "string") {
28       className += " " + arg;
29     } else if (Object(arg) === arg) {
30       // We don't test that we have an Object literal, so we can be as fast as we can
31       for (const key in arg) {
32         if (arg[key]) {
33           className += " " + key;
34         }
35       }
36     }
37   }
39   return className.trim();