{"id":21296694,"url":"https://github.com/eccenca/ecc-utils","last_synced_at":"2025-03-15T17:26:16.194Z","repository":{"id":57110519,"uuid":"68418136","full_name":"eccenca/ecc-utils","owner":"eccenca","description":"A set of small utility function that may not fit in any other package","archived":false,"fork":false,"pushed_at":"2018-02-28T14:43:25.000Z","size":189,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-04-14T11:51:09.764Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eccenca.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-16T22:18:17.000Z","updated_at":"2024-04-14T11:51:09.765Z","dependencies_parsed_at":"2022-08-20T22:20:37.147Z","dependency_job_id":null,"html_url":"https://github.com/eccenca/ecc-utils","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eccenca%2Fecc-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eccenca%2Fecc-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eccenca%2Fecc-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eccenca%2Fecc-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eccenca","download_url":"https://codeload.github.com/eccenca/ecc-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243764634,"owners_count":20344456,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-21T14:29:05.395Z","updated_at":"2025-03-15T17:26:16.175Z","avatar_url":"https://github.com/eccenca.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @eccenca/utils collection\n\nA set of small utility function that may not fit in any other package.\n\n## uuid\n\nCreates a `v4` uuid.\nIs basically a wrapper around the npm package `uuid`.\nFor options see [here](https://github.com/kelektiv/node-uuid#uuidv4options--buffer--offset)\n\n```js\nimport {uuid} from '@eccenca/utils';\n\nconst id = uuid();\n\n```\n\n## URI\n\nWrapper around [URI.js](https://github.com/medialize/URI.js).\n\n```js\n\nimport {URI} from '@eccenca/utils'\n\nconst newURI = new URI('http://example.org');\n\n//Our wrapper adds this check:\n//Returns true if URI is urn-like or an absolute URL\nnewURI.is('resourceURI');\n\n```\n\n## changeFavicon\n\nChange a favicon of a website dynamically.\n\n```js\nimport {changeFavicon} from '@eccenca/utils';\n\nchangeFavicon(\n\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQMAAABJtOi3AAAABlBMVEUAAAD+jwHRIVMHAAAAAXRSTlMAQObYZgAAAHlJREFU\" +\n\"CNctzbEJAzEQRNF/KBAGw6aOtG04EHJbFwisElzSlqISFCo4Tl7sg+EFE8yADC6C/biDzgTvs8A6K9s6JmHcBtFCR1o0BPmgD32SctkppVayzkyW4cTuBH\" +\n\"O25uBJsP9RmEhjILb5aI+dMNX8aDVYC3gdjvdfRm8rdNXB000AAAAASUVORK5CYII=\"\n);\n```\n\n## getBrowserLocales\n\nRetrieve preferred locales by the user. Values are read from the `window.navigator` object\n\n```js\nimport {getBrowserLocales} from '@eccenca/utils';\n\n//Returns for example ['de-AT', 'de', 'en']\ngetBrowserLocales();\n```\n\n## getBestLocale\n\nReturns best match between a list of preferred locales and supported locales.\nPreferred locales default to `getBrowserLocales` and order is important (First in array is most important locale).\nIf no match can be found a default locale will be returned.\n\n```js\nimport {getBestLocale} from '@eccenca/utils';\n\n//returns 'en' (default value)\ngetBestLocale();\n\n//returns 'de' (default value)\ngetBestLocale({defaultLocale: 'de'});\n\n//suppose a user has a preference of ['de-AT', 'en'] in their browser\n//returns 'de'\ngetBestLocale({supportedLocales: ['de', 'en']});\n\n//returns 'en-AU'\ngetBestLocale({\n    preferredLocales: ['de-AT', 'en'],\n    supportedLocales: ['en-AU', 'ru-RU'],\n});\n\n//Sometimes order matters in supportedLocales\n//suppose a user has a preference of ['en-US', 'de'] in their browser\n//returns 'en'\ngetBestLocale({supportedLocales: ['en', 'en-AU', 'de']});\n//returns 'en-AU'\ngetBestLocale({supportedLocales: ['en-AU', 'en', 'de']});\n```\n\n## sanitizeFileName\n\nTransform all not common letters like 'ö,ä,ü,é' to standard latin and replace all special characters like '$,],¶' to a single '_' from a given string.\nHas optional parameter `ensureType` in options\n\n```js\nimport {sanitizeFileName} from '@eccenca/utils';\n\nstring = '\u003coxo|{[¢$frmble?.csv';\n//Returns 'oxo_frmble.csv'\nsanitizeFileName(string, {ensureType: 'csv'});\n```\n\n## convertSpringPropertyObject\n\nHelps to convert Spring Property Objects to proper Javascript Objects\n\n```js\n    const input = {\n        'foo.bar.string': '123',\n        'foo.bar.array': [\"a\", \"b\", \"c\"],\n        '[http://example.org]foo.bar': {\n            'a.b': 12\n        }\n    };\n\n    const output =\n        {\n            \"foo\": {\n                \"bar\": {\n                    \"array\": [\n                        \"a\",\n                        \"b\",\n                        \"c\",\n                    ],\n                    \"string\": \"123\"\n                }\n            },\n            \"http://example.org\": {\n                \"foo\": {\n                    \"bar\": {\n                        \"a\": {\n                            \"b\": 12\n                        }\n                    }\n                }\n            }\n        }\n    ;\n\n    should(convertSpringPropertyObject(input)).deepEqual(output);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feccenca%2Fecc-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feccenca%2Fecc-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feccenca%2Fecc-utils/lists"}