Qbs Manual | List of Built-in Services | General Services

Qbs 1.8.1

# General Services

These are operations that do not fit into any of the other categories. They are automatically available in any Qbs project file or JavaScript file.

## Available Operations

### require

      require(identifier: string): any

Loads an extension and returns an object representing the extension. If identifier is a relative or absolute file path, this function will load a JavaScript file and return an object containing the evaluated context of that file. Otherwise, loads a Qbs extension named identifier and returns an object that contains the extension's context. This function is only available in JavaScript files and is designed to behave similarly to the CommonJS/RequireJS/Node.js module resolution systems.

      var MyFunctions = require("./myfunctions.js");
      MyFunctions.doSomething();
      var FileInfo = require("qbs.FileInfo");
      var fileName = FileInfo.fileName(filePath);

## Extensions to JavaScript Built-in Objects

### Array.contains

      Array.contains(e: any): boolean

Returns `true` if the array contains the element `e`. Returns `false` otherwise.

### Array.containsAll

      Array.containsAll(other: any[]): boolean

Returns `true` if the array contains every element in the `other` array. Returns `false` otherwise.

### Array.containsAny

      Array.containsAny(other: any[]): boolean

Returns `true` if the array contains some element(s) in the `other` array. Returns `false` otherwise.

### Array.uniqueConcat

      Array.uniqueConcat(other: any[]): any[]

Returns a copy of this array joined with the array `other`. Duplicates that would originate from the concatenation are removed. The order of elements is preserved.

### String.contains

      String.contains(s: string): boolean

Returns `true` if the string contains the substring `s`. Returns `false` otherwise.

### startsWith

      String.startsWith(s: string): boolean

Returns `true` if the string starts with the substring `s`. Returns `false` otherwise.

### endsWith

      String.endsWith(s: string): boolean

Returns `true` if the string ends with the substring `s`. Returns `false` otherwise.

## Console API

Qbs provides a subset of the non-standard Console API available in most ECMAScript runtimes.

The output of each of these functions will only be displayed if the logging level is at least the level which the function outputs at. Logging levels from lowest to highest are: 'error', 'warning', 'info', 'debug', and 'trace'. The default is 'info'.

Warning: The contents of this section are subject to change in order to align with future standardization processes.

### console.debug

      console.debug(s: string): void

This method is an alias for `console.log()`.

### console.error

      console.error(s: string): void

Logs an `error` level message. Outputs to stderr when the logger output is a terminal. The string will be prefixed with `"ERROR: "` and colored red when the logger output is a color-capable terminal.

### console.info

      console.info(s: string): void

Logs an `info` level message. Outputs to stdout when the logger output is a terminal.

### console.log

      console.log(s: string): void

Logs a `debug` level message. Outputs to stderr when the logger output is a terminal.

### console.warn

      console.warn(s: string): void

Logs a `warning` level message. Outputs to stderr when the logger output is a terminal. The string will be prefixed with `"WARNING: "` and colored yellow when the logger output is a color-capable terminal.