Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev', v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Aug 13, 2020
2 parents 95f15f9 + e0f03e5 commit b4bde4a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -2,13 +2,13 @@

A set of common JavaScript functionalities for [openEO](http://openeo.org).

The [master branch](https://github.com/Open-EO/openeo-api/tree/master) is the 'stable' version of library, which is currently version **1.1.0**.
The [master branch](https://github.com/Open-EO/openeo-api/tree/master) is the 'stable' version of library, which is currently version **1.1.1**.
The [draft branch](https://github.com/Open-EO/openeo-api/tree/draft) is where active development takes place.

[![Build Status](https://travis-ci.org/Open-EO/openeo-js-commons.svg?branch=master)](https://travis-ci.org/Open-EO/openeo-js-commons)
![Dependencies](https://img.shields.io/librariesio/release/npm/@openeo/js-commons)
![Minified Size](https://img.shields.io/bundlephobia/min/@openeo/js-commons/1.1.0)
![Minzipped Size](https://img.shields.io/bundlephobia/minzip/@openeo/js-commons/1.1.0)
![Minified Size](https://img.shields.io/bundlephobia/min/@openeo/js-commons/1.1.1)
![Minzipped Size](https://img.shields.io/bundlephobia/minzip/@openeo/js-commons/1.1.1)
![Supported API Versions](https://img.shields.io/github/package-json/apiVersions/Open-Eo/openeo-js-commons/master)

## Features
Expand Down Expand Up @@ -40,4 +40,4 @@ In a web environment you can include the library as follows:
<script src="https://cdn.jsdelivr.net/npm/@openeo/js-commons@1/dist/main.min.js"></script>
```

More information can be found in the [**JS commons documentation**](https://open-eo.github.io/openeo-js-commons/1.1.0/).
More information can be found in the [**JS commons documentation**](https://open-eo.github.io/openeo-js-commons/1.1.1/).
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@openeo/js-commons",
"version": "1.1.0",
"version": "1.1.1",
"apiVersions": [
"0.4.x",
"1.0.x"
Expand Down
16 changes: 13 additions & 3 deletions src/utils.js
Expand Up @@ -113,11 +113,21 @@ class Utils {
/**
* Creates a duplicate-free version of an array.
*
* @param {array} arr
* If useEquals is set to true, uses the `Utils.equals` function for comparison instead of
* the JS === operator. Thus, if the array contains objects, you likely want to set
* `useEquals` to `true`.
*
* @param {array} array
* @param {boolean} useEquals
* @returns {array}
*/
static unique(arr) {
return [...new Set(arr)];
static unique(array, useEquals = false) {
if (useEquals) {
return array.filter((s1, pos, arr) => arr.findIndex(s2 => Utils.equals(s1, s2)) === pos);
}
else {
return [...new Set(array)];
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/utils.test.js
Expand Up @@ -38,10 +38,14 @@ describe('Utils Tests', () => {
});

test('unique', () => {
let a = "a";
let b = "b";
expect(Utils.unique([])).toEqual([]);
expect(Utils.unique([123, 123])).toEqual([123]);
expect(Utils.unique([123, "123"])).toEqual([123, "123"]);
expect(Utils.unique(["a", "a", "b", "a"])).toEqual(["a", "b"]);
expect(Utils.unique([{a}, {b}, {a}])).toEqual([{a}, {b}, {a}]);
expect(Utils.unique([{a}, {b}, {a}], true)).toEqual([{a}, {b}]);
});

test('equals', () => {
Expand Down

0 comments on commit b4bde4a

Please sign in to comment.