-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.js
More file actions
27 lines (24 loc) · 755 Bytes
/
utils.js
File metadata and controls
27 lines (24 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import urlJoin from 'proper-url-join';
export const copyToClipboard = (str) => {
// ref: https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
};
export const internalUrlJoin = (url) =>
urlJoin(...url, { leadingSlash: true, trailingSlash: false });
export const makeURLSafeString = (str) =>
str
.replace(/((?!([a-z0-9\- ])).)/gi, '')
.trim()
.split(' ')
.filter(Boolean)
.join('-')
.substring(0, 25)
.toLowerCase();