pddl-workspace
Version:
150 lines • 5.18 kB
JavaScript
;
/* --------------------------------------------------------------------------------------------
* Copyright (c) Jan Dolejsi. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.split = exports.addAllToMapOfLists = exports.addToMapOfLists = exports.removeFromMapOfSets = exports.addToMapOfSets = exports.equalsCaseInsensitive = exports.Util = void 0;
const os = __importStar(require("os"));
class Util {
/**
* Wraps path with doublequotes, if it includes a space.
*
* This is necessary on Windows in order to handle spaces in file and directory names.
* @param path file system path
*/
static q(path) {
return this.shouldBeDoubleQuoted(path) ? `"${path}"` : path;
}
static shouldBeDoubleQuoted(path) {
return os.platform() === 'win32' && path.includes(' ') && !path.includes('"')
&& !path.includes(" -jar ")
&& !path.includes(" -javaagent:")
&& !path.startsWith("node ");
}
/**
* Replaces all occurrences
* @param text text to replace in
* @param searchValue value to replace
* @param replaceValue replacement value
*/
static replaceAll(text, searchValue, replaceValue) {
return text.split(searchValue).join(replaceValue);
}
/**
* Groups array by a key
* @param list list to be grouped
* @param keyGetter grouping key selector
*/
static groupBy(list, keyGetter) {
const map = new Map();
list.forEach((item) => {
const key = keyGetter(item);
const collection = map.get(key);
if (!collection) {
map.set(key, [item]);
}
else {
collection.push(item);
}
});
return map;
}
/**
* Equivalent of flatMap from other languages.
* @param arrayOfArrays array of arrays to be flattened to single dimentional array
*/
static flatMap(arrayOfArrays) {
// eslint-disable-next-line prefer-spread
return new Array().concat.apply(new Array(), arrayOfArrays);
}
static distinct(array) {
return [...new Set(array).values()];
}
}
exports.Util = Util;
/** @returns `true` if `text1` and `text2` are equal ignoring case. */
function equalsCaseInsensitive(text1, text2) {
return text1.toLowerCase() === text2.toLowerCase();
}
exports.equalsCaseInsensitive = equalsCaseInsensitive;
function addToMapOfSets(multiMap, key, value) {
const valuesForKey = multiMap.get(key);
if (valuesForKey) {
valuesForKey.add(value);
}
else {
multiMap.set(key, new Set([value]));
}
}
exports.addToMapOfSets = addToMapOfSets;
function removeFromMapOfSets(multiMap, key, value) {
const valuesForKey = multiMap.get(key);
if (!valuesForKey) {
return false;
}
valuesForKey.delete(value);
if (valuesForKey.size == 0) {
multiMap.delete(key);
}
return true;
}
exports.removeFromMapOfSets = removeFromMapOfSets;
function addToMapOfLists(multiMap, key, value) {
const valuesForKey = multiMap.get(key);
if (valuesForKey) {
valuesForKey.push(value);
}
else {
multiMap.set(key, [value]);
}
}
exports.addToMapOfLists = addToMapOfLists;
function addAllToMapOfLists(multiMap, key, values) {
const valuesForKey = multiMap.get(key);
if (valuesForKey) {
valuesForKey.push(...values);
}
else {
multiMap.set(key, values);
}
}
exports.addAllToMapOfLists = addAllToMapOfLists;
function split(collection, predicate) {
const positives = [];
const negatives = [];
collection.forEach(element => {
if (predicate(element)) {
positives.push(element);
}
else {
negatives.push(element);
}
});
return [positives, negatives];
}
exports.split = split;
//# sourceMappingURL=util.js.map