File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Linting
2+ package-lock.json
23.cache
34
45node_modules
6+
7+ ._ *
8+ .DS_Store
9+
10+ * .tgz
Original file line number Diff line number Diff line change 1+ package-lock = false
Original file line number Diff line number Diff line change 1+ # Utils
2+
3+ A collection of JavaScript utilities and helper functions
4+
5+
6+ ## Labels
7+
8+ ** Returns**
9+
10+ - ` l ` - gets the current document language
11+ - ` labels ` - an object with translations
12+
13+ ** Usage**
14+
15+ ``` javascript
16+
17+ import {l , labels } from ' @packages/utils' ;
18+
19+ // Extend the _labels_
20+ $ .extend (true , labels, {
21+ en: {
22+ ' cookify.message' : ` This site uses cookies.`
23+ },
24+ pt: {
25+ ' cookify.message' : ` Este site usa cookies.`
26+ }
27+ })
28+
29+ const cookieBanner = $ (` <div class="cookiePolicy">${ l (' cookie.message' )} </div>` );
30+
31+ ```
32+
33+ ## Debounce
34+
35+ An example of sticky navigation on scroll with ` debounce ` function
36+
37+ ** Usage**
38+
39+ ``` javascript
40+ import { debounce } from ' @packages/utils' ;
41+
42+ (() => {
43+ const header = $ (' .siteHeader' ),
44+ headerHeight = header .outerHeight (true );
45+
46+ window .addEventListener (' scroll' , debounce (function () {
47+ if ($ (this ).scrollTop () > headerHeight) {
48+ header .addClass (' isFixed' );
49+ } else {
50+ header .removeClass (' isFixed' );
51+ }
52+ }, 200 ));
53+ })();
54+
55+ ```
56+
57+ ## Migrate to version 2
58+
59+ - ` docReady() ` was renamed to ` documentReady() `
60+ - ` url-get-parameters ` function was removed. Use the native ` URLSearchParams() ` - see [ URLSearchParams] ( https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams ) on MDN
61+ - ` guid-generator ` was also removed in favour of native [ Crypto] ( https://developer.mozilla.org/en-US/docs/Web/API/Crypto ) interface eg. ` const randomId = crypto.getRandomValues(new Uint32Array(1))[0] `
Original file line number Diff line number Diff line change 11{
2- "name" : " @packages /utils" ,
2+ "name" : " @liquidlight /utils" ,
33 "version" : " 2.1.0" ,
44 "description" : " Utils - collection of JS functions" ,
55 "main" : " src/js/index.js" ,
66 "repository" : {
77 "type" : " git" ,
8- "url" : " git@gitlab.liquidlight.uk:packages/npm/utils.git"
8+ "url" : " git@github.com:liquidlight/utils.git"
9+ },
10+ "bugs" : {
11+ "url" : " https://github.com/liquidlight/utils/issues"
912 },
1013 "author" : " João Augusto <joao@liquidlight.co.uk>" ,
1114 "contributors" : [
1215 " Mike Street <mike@liquidlight.co.uk>"
1316 ],
1417 "license" : " ISC" ,
15- "publishConfig" : {
16- "@packages:registry" : " https://gitlab.liquidlight.uk/api/v4/projects/339/packages/npm/"
17- },
1818 "scripts" : {
1919 "eslint:dry-run" : " eslint src --color --cache --config node_modules/@lintkit/eslint-config/eslint.config.js --cache-location .cache/ --cache-strategy content" ,
2020 "eslint:fix" : " npm run eslint:dry-run -- --fix" ,
You can’t perform that action at this time.
0 commit comments