ecc-utils collection
A set of small utility function that may not fit in any other package.
uuid
Creates a v4 uuid.
Is basically a wrapper around the npm package uuid.
For options see here
import {uuid} from 'ecc-utils';
const id = uuid();
URI
Wrapper around URI.js.
import {URI} from 'ecc-utils'
const newURI = new URI('http://example.org');
newURI.is('resourceURI');
changeFavicon
Change a favicon of a website dynamically.
import {changeFavicon} from 'ecc-utils';
changeFavicon(
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQMAAABJtOi3AAAABlBMVEUAAAD+jwHRIVMHAAAAAXRSTlMAQObYZgAAAHlJREFU" +
"CNctzbEJAzEQRNF/KBAGw6aOtG04EHJbFwisElzSlqISFCo4Tl7sg+EFE8yADC6C/biDzgTvs8A6K9s6JmHcBtFCR1o0BPmgD32SctkppVayzkyW4cTuBH" +
"O25uBJsP9RmEhjILb5aI+dMNX8aDVYC3gdjvdfRm8rdNXB000AAAAASUVORK5CYII="
);
getBrowserLocales
Retrieve preferred locales by the user. Values are read from the window.navigator object
import {getBrowserLocales} from 'ecc-utils';
getBrowserLocales();
getBestLocale
Returns best match between a list of preferred locales and supported locales.
Preferred locales default to getBrowserLocales and order is important (First in array is most important locale).
If no match can be found a default locale will be returned.
import {getBestLocale} from 'ecc-utils';
getBestLocale();
getBestLocale({defaultLocale: 'de'});
getBestLocale({supportedLocales: ['de', 'en']});
getBestLocale({
preferredLocales: ['de-AT', 'en'],
supportedLocales: ['en-AU', 'ru-RU'],
});
getBestLocale({supportedLocales: ['en', 'en-AU', 'de']});
getBestLocale({supportedLocales: ['en-AU', 'en', 'de']});
sanitizeFileName
Transform all not common letters like 'ö,ä,ü,é' to standard latin and replace all special characters like '$,],¶' to a single '_' from a given string.
Has optional parameter ensureType in options
import {sanitizeFileName} from 'ecc-utils';
string = '<oxo|{[¢$frmble?.csv';
sanitizeFileName(string, {ensureType: 'csv'});
convertSpringPropertyObject
Helps to convert Spring Property Objects to proper Javascript Objects
const input = {
'foo.bar.string': '123',
'foo.bar.array': ["a", "b", "c"],
'[http://example.org]foo.bar': {
'a.b': 12
}
};
const output =
{
"foo": {
"bar": {
"array": [
"a",
"b",
"c",
],
"string": "123"
}
},
"http://example.org": {
"foo": {
"bar": {
"a": {
"b": 12
}
}
}
}
}
;
should(convertSpringPropertyObject(input)).deepEqual(output);