Skip to content

Commit

Permalink
feat: added copyToClipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Uninen committed Mar 9, 2022
1 parent f8d2122 commit 4c0f6ec
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 86 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.0.4 (2022-03-09)

- Feat: added `copyToClipboard`

## 0.0.1 (2022-03-04)

- Initial version
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ General utilities for Web development
## Features
### Browser

- `storageAvailable(type: 'localStorage' | 'sessionStorage'): boolean`
- `copyToClipboard(content: string): boolean`
- `getCookie(name: string): string | null`
- `storageAvailable(type: 'localStorage' | 'sessionStorage'): boolean`

## Installation

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slipmatio/toolbelt",
"version": "0.0.3",
"version": "0.0.4",
"main": "dist/index.es.js",
"module": "dist/index.es.js",
"exports": {
Expand Down Expand Up @@ -52,7 +52,7 @@
"vite": "~2.8",
"vite-plugin-dts": "^0.9.9",
"vite-plugin-istanbul": "^2.5.0",
"vitest": "~0.5",
"vitest": "~0.6",
"vue": "~3.2",
"wait-on": "~6.0"
},
Expand Down
19 changes: 19 additions & 0 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,22 @@ export function getCookie(name: string) {
}
return cookieValue
}

/**
* Simple clipboard copy for modern browsers. Returns true if successful.
*/
export function copyToClipboard(content: string) {
const d = document
try {
const el = document.createElement('input')
el.setAttribute('style', 'opacity:0;')
el.setAttribute('value', content)
d.body.appendChild(el)
el.select()
d.execCommand('copy')
d.body.removeChild(el)
return true
} catch {
return false
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { storageAvailable, getCookie } from './browser'
export { storageAvailable, getCookie, copyToClipboard } from './browser'
159 changes: 77 additions & 82 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1169,11 +1169,6 @@
resolved "https://registry.yarnpkg.com/@sideway/pinpoint/-/pinpoint-2.0.0.tgz#cff8ffadc372ad29fd3f78277aeb29e632cc70df"
integrity sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ==

"@slipmatio/toolbelt@^0.0.1-alpha.4":
version "0.0.1-alpha.4"
resolved "https://registry.yarnpkg.com/@slipmatio/toolbelt/-/toolbelt-0.0.1-alpha.4.tgz#8e33468c5bde398c82b894b5a42d978e38b3c559"
integrity sha512-/FZAE7pjuv9VJyejXyQ4MUNLyKWdOPeKV28VQuAMq+NAdhlo/w3LJHcpoNsw/jfy2MyJUam3uH3INyIXyKsXZA==

"@ts-morph/common@~0.12.3":
version "0.12.3"
resolved "https://registry.yarnpkg.com/@ts-morph/common/-/common-0.12.3.tgz#a96e250217cd30e480ab22ec6a0ebbe65fd784ff"
Expand Down Expand Up @@ -1239,13 +1234,13 @@
"@types/node" "*"

"@typescript-eslint/eslint-plugin@^5.0.0", "@typescript-eslint/eslint-plugin@~5":
version "5.13.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.13.0.tgz#2809052b85911ced9c54a60dac10e515e9114497"
integrity sha512-vLktb2Uec81fxm/cfz2Hd6QaWOs8qdmVAZXLdOBX6JFJDhf6oDZpMzZ4/LZ6SFM/5DgDcxIMIvy3F+O9yZBuiQ==
version "5.14.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.14.0.tgz#5119b67152356231a0e24b998035288a9cd21335"
integrity sha512-ir0wYI4FfFUDfLcuwKzIH7sMVA+db7WYen47iRSaCGl+HMAZI9fpBwfDo45ZALD3A45ZGyHWDNLhbg8tZrMX4w==
dependencies:
"@typescript-eslint/scope-manager" "5.13.0"
"@typescript-eslint/type-utils" "5.13.0"
"@typescript-eslint/utils" "5.13.0"
"@typescript-eslint/scope-manager" "5.14.0"
"@typescript-eslint/type-utils" "5.14.0"
"@typescript-eslint/utils" "5.14.0"
debug "^4.3.2"
functional-red-black-tree "^1.0.1"
ignore "^5.1.8"
Expand All @@ -1254,68 +1249,68 @@
tsutils "^3.21.0"

"@typescript-eslint/parser@^5.0.0", "@typescript-eslint/parser@~5":
version "5.13.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.13.0.tgz#0394ed8f2f849273c0bf4b811994d177112ced5c"
integrity sha512-GdrU4GvBE29tm2RqWOM0P5QfCtgCyN4hXICj/X9ibKED16136l9ZpoJvCL5pSKtmJzA+NRDzQ312wWMejCVVfg==
version "5.14.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.14.0.tgz#7c79f898aa3cff0ceee6f1d34eeed0f034fb9ef3"
integrity sha512-aHJN8/FuIy1Zvqk4U/gcO/fxeMKyoSv/rS46UXMXOJKVsLQ+iYPuXNbpbH7cBLcpSbmyyFbwrniLx5+kutu1pw==
dependencies:
"@typescript-eslint/scope-manager" "5.13.0"
"@typescript-eslint/types" "5.13.0"
"@typescript-eslint/typescript-estree" "5.13.0"
"@typescript-eslint/scope-manager" "5.14.0"
"@typescript-eslint/types" "5.14.0"
"@typescript-eslint/typescript-estree" "5.14.0"
debug "^4.3.2"

"@typescript-eslint/scope-manager@5.13.0":
version "5.13.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.13.0.tgz#cf6aff61ca497cb19f0397eea8444a58f46156b6"
integrity sha512-T4N8UvKYDSfVYdmJq7g2IPJYCRzwtp74KyDZytkR4OL3NRupvswvmJQJ4CX5tDSurW2cvCc1Ia1qM7d0jpa7IA==
"@typescript-eslint/scope-manager@5.14.0":
version "5.14.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.14.0.tgz#ea518962b42db8ed0a55152ea959c218cb53ca7b"
integrity sha512-LazdcMlGnv+xUc5R4qIlqH0OWARyl2kaP8pVCS39qSL3Pd1F7mI10DbdXeARcE62sVQE4fHNvEqMWsypWO+yEw==
dependencies:
"@typescript-eslint/types" "5.13.0"
"@typescript-eslint/visitor-keys" "5.13.0"
"@typescript-eslint/types" "5.14.0"
"@typescript-eslint/visitor-keys" "5.14.0"

"@typescript-eslint/type-utils@5.13.0":
version "5.13.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.13.0.tgz#b0efd45c85b7bab1125c97b752cab3a86c7b615d"
integrity sha512-/nz7qFizaBM1SuqAKb7GLkcNn2buRdDgZraXlkhz+vUGiN1NZ9LzkA595tHHeduAiS2MsHqMNhE2zNzGdw43Yg==
"@typescript-eslint/type-utils@5.14.0":
version "5.14.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.14.0.tgz#711f08105860b12988454e91df433567205a8f0b"
integrity sha512-d4PTJxsqaUpv8iERTDSQBKUCV7Q5yyXjqXUl3XF7Sd9ogNLuKLkxz82qxokqQ4jXdTPZudWpmNtr/JjbbvUixw==
dependencies:
"@typescript-eslint/utils" "5.13.0"
"@typescript-eslint/utils" "5.14.0"
debug "^4.3.2"
tsutils "^3.21.0"

"@typescript-eslint/types@5.13.0":
version "5.13.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.13.0.tgz#da1de4ae905b1b9ff682cab0bed6b2e3be9c04e5"
integrity sha512-LmE/KO6DUy0nFY/OoQU0XelnmDt+V8lPQhh8MOVa7Y5k2gGRd6U9Kp3wAjhB4OHg57tUO0nOnwYQhRRyEAyOyg==
"@typescript-eslint/types@5.14.0":
version "5.14.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.14.0.tgz#96317cf116cea4befabc0defef371a1013f8ab11"
integrity sha512-BR6Y9eE9360LNnW3eEUqAg6HxS9Q35kSIs4rp4vNHRdfg0s+/PgHgskvu5DFTM7G5VKAVjuyaN476LCPrdA7Mw==

"@typescript-eslint/typescript-estree@5.13.0":
version "5.13.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.13.0.tgz#b37c07b748ff030a3e93d87c842714e020b78141"
integrity sha512-Q9cQow0DeLjnp5DuEDjLZ6JIkwGx3oYZe+BfcNuw/POhtpcxMTy18Icl6BJqTSd+3ftsrfuVb7mNHRZf7xiaNA==
"@typescript-eslint/typescript-estree@5.14.0":
version "5.14.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.14.0.tgz#78b7f7385d5b6f2748aacea5c9b7f6ae62058314"
integrity sha512-QGnxvROrCVtLQ1724GLTHBTR0lZVu13izOp9njRvMkCBgWX26PKvmMP8k82nmXBRD3DQcFFq2oj3cKDwr0FaUA==
dependencies:
"@typescript-eslint/types" "5.13.0"
"@typescript-eslint/visitor-keys" "5.13.0"
"@typescript-eslint/types" "5.14.0"
"@typescript-eslint/visitor-keys" "5.14.0"
debug "^4.3.2"
globby "^11.0.4"
is-glob "^4.0.3"
semver "^7.3.5"
tsutils "^3.21.0"

"@typescript-eslint/utils@5.13.0":
version "5.13.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.13.0.tgz#2328feca700eb02837298339a2e49c46b41bd0af"
integrity sha512-+9oHlPWYNl6AwwoEt5TQryEHwiKRVjz7Vk6kaBeD3/kwHE5YqTGHtm/JZY8Bo9ITOeKutFaXnBlMgSATMJALUQ==
"@typescript-eslint/utils@5.14.0":
version "5.14.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.14.0.tgz#6c8bc4f384298cbbb32b3629ba7415f9f80dc8c4"
integrity sha512-EHwlII5mvUA0UsKYnVzySb/5EE/t03duUTweVy8Zqt3UQXBrpEVY144OTceFKaOe4xQXZJrkptCf7PjEBeGK4w==
dependencies:
"@types/json-schema" "^7.0.9"
"@typescript-eslint/scope-manager" "5.13.0"
"@typescript-eslint/types" "5.13.0"
"@typescript-eslint/typescript-estree" "5.13.0"
"@typescript-eslint/scope-manager" "5.14.0"
"@typescript-eslint/types" "5.14.0"
"@typescript-eslint/typescript-estree" "5.14.0"
eslint-scope "^5.1.1"
eslint-utils "^3.0.0"

"@typescript-eslint/visitor-keys@5.13.0":
version "5.13.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.13.0.tgz#f45ff55bcce16403b221ac9240fbeeae4764f0fd"
integrity sha512-HLKEAS/qA1V7d9EzcpLFykTePmOQqOFim8oCvhY3pZgQ8Hi38hYpHd9e5GN6nQBFQNecNhws5wkS9Y5XIO0s/g==
"@typescript-eslint/visitor-keys@5.14.0":
version "5.14.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.14.0.tgz#1927005b3434ccd0d3ae1b2ecf60e65943c36986"
integrity sha512-yL0XxfzR94UEkjBqyymMLgCBdojzEuy/eim7N9/RIcTNxpJudAcqsU8eRyfzBbcEzGoPWfdM3AGak3cN08WOIw==
dependencies:
"@typescript-eslint/types" "5.13.0"
"@typescript-eslint/types" "5.14.0"
eslint-visitor-keys "^3.0.0"

"@vitejs/plugin-vue@~2":
Expand Down Expand Up @@ -1977,12 +1972,12 @@ browserify@^17.0.0:
xtend "^4.0.0"

browserslist@^4.17.5, browserslist@^4.19.1:
version "4.19.3"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.19.3.tgz#29b7caad327ecf2859485f696f9604214bedd383"
integrity sha512-XK3X4xtKJ+Txj8G5c30B4gsm71s69lqXlkYui4s6EkKxuv49qjYlY6oVd+IFJ73d4YymtM3+djvvt/R/iJwwDg==
version "4.20.0"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.20.0.tgz#35951e3541078c125d36df76056e94738a52ebe9"
integrity sha512-bnpOoa+DownbciXj0jVGENf8VYQnE2LNWomhYuCsMmmx9Jd9lwq0WXODuwpSsp8AVdKM2/HorrzxAfbKvWTByQ==
dependencies:
caniuse-lite "^1.0.30001312"
electron-to-chromium "^1.4.71"
caniuse-lite "^1.0.30001313"
electron-to-chromium "^1.4.76"
escalade "^3.1.1"
node-releases "^2.0.2"
picocolors "^1.0.0"
Expand Down Expand Up @@ -2079,10 +2074,10 @@ camelcase@^5.0.0, camelcase@^5.3.1:
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320"
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==

caniuse-lite@^1.0.30001297, caniuse-lite@^1.0.30001312:
version "1.0.30001313"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001313.tgz#a380b079db91621e1b7120895874e2fd62ed2e2f"
integrity sha512-rI1UN0koZUiKINjysQDuRi2VeSCce3bYJNmDcj3PIKREiAmjakugBul1QSkg/fPrlULYl6oWfGg3PbgOSY9X4Q==
caniuse-lite@^1.0.30001297, caniuse-lite@^1.0.30001313:
version "1.0.30001314"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001314.tgz#65c7f9fb7e4594fca0a333bec1d8939662377596"
integrity sha512-0zaSO+TnCHtHJIbpLroX7nsD+vYuOVjl3uzFbJO1wMVbuveJA0RK2WcQA9ZUIOiO0/ArMiMgHJLxfEZhQiC0kw==

caseless@~0.12.0:
version "0.12.0"
Expand Down Expand Up @@ -2628,10 +2623,10 @@ ecc-jsbn@~0.1.1:
jsbn "~0.1.0"
safer-buffer "^2.1.0"

electron-to-chromium@^1.4.71:
version "1.4.75"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.75.tgz#d1ad9bb46f2f1bf432118c2be21d27ffeae82fdd"
integrity sha512-LxgUNeu3BVU7sXaKjUDD9xivocQLxFtq6wgERrutdY/yIOps3ODOZExK1jg8DTEg4U8TUCb5MLGeWFOYuxjF3Q==
electron-to-chromium@^1.4.76:
version "1.4.78"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.78.tgz#7a1cf853efafde2c4cf6e86facf3e5792d3541a5"
integrity sha512-o61+D/Lx7j/E0LIin/efOqeHpXhwi1TaQco9vUcRmr91m25SfZY6L5hWJDv/r+6kNjboFKgBw1LbfM0lbhuK6Q==

elliptic@^6.5.3:
version "6.5.4"
Expand Down Expand Up @@ -3334,9 +3329,9 @@ form-data@~2.3.2:
mime-types "^2.1.12"

fraction.js@^4.1.2:
version "4.1.3"
resolved "https://registry.yarnpkg.com/fraction.js/-/fraction.js-4.1.3.tgz#be65b0f20762ef27e1e793860bc2dfb716e99e65"
integrity sha512-pUHWWt6vHzZZiQJcM6S/0PXfS+g6FM4BF5rj9wZyreivhQPdsh5PpE25VtSNxq80wHS5RfY51Ii+8Z0Zl/pmzg==
version "4.2.0"
resolved "https://registry.yarnpkg.com/fraction.js/-/fraction.js-4.2.0.tgz#448e5109a313a3527f5a3ab2119ec4cf0e0e2950"
integrity sha512-MhLuK+2gUcnZe8ZHlaaINnQLl0xRIGRfcGk2yl8xoQAfHrSsL3rYu6FCmBdkdbhc9EPlwyGHewaRsvwRMJtAlA==

from@~0:
version "0.1.7"
Expand Down Expand Up @@ -4745,9 +4740,9 @@ postcss-value-parser@^4.2.0:
integrity sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==

postcss@^8.1.10, postcss@^8.4.6:
version "8.4.7"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.7.tgz#f99862069ec4541de386bf57f5660a6c7a0875a8"
integrity sha512-L9Ye3r6hkkCeOETQX6iOaWZgjp3LL6Lpqm6EtgbKrgqGGteRMNb9vzBfRL96YOSu8o7x3MfIH9Mo5cPJFGrW6A==
version "8.4.8"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.8.tgz#dad963a76e82c081a0657d3a2f3602ce10c2e032"
integrity sha512-2tXEqGxrjvAO6U+CJzDL2Fk2kPHTv1jQsYkSoMeOis2SsYaXRO2COxTdQp99cYvif9JTXaAk9lYGc3VhJt7JPQ==
dependencies:
nanoid "^3.3.1"
picocolors "^1.0.0"
Expand Down Expand Up @@ -5033,9 +5028,9 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
inherits "^2.0.1"

rollup@^2.59.0:
version "2.69.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.69.0.tgz#82aa86682a45e9760146b736c1643bf435506156"
integrity sha512-kjER91tHyek8gAkuz7+558vSnTQ+pITEok1P0aNOS45ZXyngaqPsXJmSel4QPQnJo7EJMjXUU1/GErWkWiKORg==
version "2.70.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.70.0.tgz#17a92e5938e92a251b962352e904c9f558230ec7"
integrity sha512-iEzYw+syFxQ0X9RefVwhr8BA2TNJsTaX8L8dhyeyMECDbmiba+8UQzcu+xZdji0+JQ+s7kouQnw+9Oz5M19XKA==
optionalDependencies:
fsevents "~2.3.2"

Expand All @@ -5047,9 +5042,9 @@ run-parallel@^1.1.9:
queue-microtask "^1.2.2"

rxjs@^7.1.0, rxjs@^7.5.1, rxjs@^7.5.4:
version "7.5.4"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.5.4.tgz#3d6bd407e6b7ce9a123e76b1e770dc5761aa368d"
integrity sha512-h5M3Hk78r6wAheJF0a5YahB1yRQKCsZ4MsGdZ5O9ETbVtjPcScGfrMmoOq7EBsCRzd4BDkvDJ7ogP8Sz5tTFiQ==
version "7.5.5"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.5.5.tgz#2ebad89af0f560f460ad5cc4213219e1f7dd4e9f"
integrity sha512-sy+H0pQofO95VDmFLzyaw9xNJU4KTRSwQIGM6+iG3SypAtCiLDzpeG8sJrNCWn2Up9km+KhkvTdbkrdy+yzZdw==
dependencies:
tslib "^2.1.0"

Expand Down Expand Up @@ -5741,9 +5736,9 @@ vite-plugin-dts@^0.9.9:
ts-morph "^13.0.0"

vite-plugin-istanbul@^2.5.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/vite-plugin-istanbul/-/vite-plugin-istanbul-2.5.0.tgz#48f0bb922bdae759c7336ed3c38a6c72a084c65c"
integrity sha512-RqDYGbTo0mY7Ak/8K/GMG3reI2lPcNtKAf2Fzqa72EkGZ6nI3xYpXxCnyObCicK0vJOESNvr/CwOmZn3XHifsQ==
version "2.5.1"
resolved "https://registry.yarnpkg.com/vite-plugin-istanbul/-/vite-plugin-istanbul-2.5.1.tgz#03100d70da69374343ab79676e5f8ceb233fb330"
integrity sha512-5ZR2/haQalUXVqHrjatZ0QKxzF3e0hBiJe6VhjGYxE7Yc4WFs7ZE56oazYB4jnPXvlirOvgLxG0LJQoHFdMxMg==
dependencies:
chalk "^4.1.2"
istanbul-lib-instrument "^4.0.3"
Expand All @@ -5761,10 +5756,10 @@ vite@^2.7.10, vite@~2.8:
optionalDependencies:
fsevents "~2.3.2"

vitest@~0.5:
version "0.5.9"
resolved "https://registry.yarnpkg.com/vitest/-/vitest-0.5.9.tgz#175790f7038c65281c5b43f2765e5c5223b53c94"
integrity sha512-R8lRP9Q1yIbwr8pDf2gvw4PFe8H5YMyHhBcdyfnUh6toLfCR10jrdI/WkNxdo5I4H/9XrMX9t+SAavdJExNdKg==
vitest@~0.6:
version "0.6.0"
resolved "https://registry.yarnpkg.com/vitest/-/vitest-0.6.0.tgz#297e4bb1b69e797bce5f7af8a62c92b568dfbfd5"
integrity sha512-FuIkLHCQxz6rO35MQROUtVdwcBaYnt198YpPGIrJXmuNHGolfPbrZIiwpD7bek0OiETxuphK3+KR5oJ5Qi1g5A==
dependencies:
"@types/chai" "^4.3.0"
"@types/chai-subset" "^1.3.3"
Expand Down

0 comments on commit 4c0f6ec

Please sign in to comment.