diff --git a/README.md b/README.md index 46fcf2e14..ba9eb3cfd 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ * [Current URL](#current-url) * [Element is visible in viewport](#element-is-visible-in-viewport) * [Get scroll position](#get-scroll-position) -* [Redirect to URL](#redirect-to-url) +* [Redirect to url](#redirect-to-url) * [Scroll to top](#scroll-to-top) ### Function @@ -528,7 +528,17 @@ const getScrollPos = (el = window) => [⬆ back to top](#table-of-contents) -undefined +### Redirect to URL + +Use `window.location.href` or `window.location.replace()` to redirect to `url`. +Pass a second argument to simulate a link click (`true` - default) or an HTTP redirect (`false`). + +```js +const redirect = (url, asLink = true) => + asLink ? window.location.href = url : window.location.replace(url); +// redirect('https://google.com') +``` + [⬆ back to top](#table-of-contents) ### Scroll to top diff --git a/scripts/builder.js b/scripts/builder.js index 6a15e53a7..ba345e67f 100644 --- a/scripts/builder.js +++ b/scripts/builder.js @@ -52,13 +52,13 @@ catch (err){ try { output += `${startPart+'\n'}`; - for(var tag of [...new Set(Object.entries(tagDbData).map(t => t[1]))].sort((a,b) => a.localeCompare(b))){ + for(var tag of [...new Set(Object.entries(tagDbData).map(t => t[1]))].filter(v => v).sort((a,b) => a.localeCompare(b))){ output +=`### ${capitalize(tag, true)}\n`; for(var taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag)) output += `* [${taggedSnippet[0][0].toUpperCase() + taggedSnippet[0].replace(/-/g,' ').slice(1)}](#${taggedSnippet[0].replace(/\(/g,'').replace(/\)/g,'').toLowerCase()})\n` output += '\n'; } - for(var tag of [...new Set(Object.entries(tagDbData).map(t => t[1]))].sort((a,b) => a.localeCompare(b))){ + for(var tag of [...new Set(Object.entries(tagDbData).map(t => t[1]))].filter(v => v).sort((a,b) => a.localeCompare(b))){ output +=`## ${capitalize(tag, true)}\n`; for(var taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag)) output += `\n${snippets[taggedSnippet[0]+'.md']+'\n[⬆ back to top](#table-of-contents)\n'}`; diff --git a/tag_database b/tag_database index 5619a0369..ef62da213 100644 --- a/tag_database +++ b/tag_database @@ -58,7 +58,7 @@ powerset:math promisify:function random-integer-in-range:utility random-number-in-range:utility -redirect-to-URL:browser +redirect-to-url:browser reverse-a-string:string RGB-to-hexadecimal:utility run-promises-in-series:function