aboutsummaryrefslogtreecommitdiff
path: root/src/utils.ts
diff options
context:
space:
mode:
authorIndrajith K L2019-12-30 20:01:49 +0530
committerIndrajith K L2019-12-30 20:01:49 +0530
commit6534757b525c98abf03f1e04fff77b1b05e4d66e (patch)
tree158e7532d83457d0ede975edd88e04302302eddd /src/utils.ts
parente655a66b13b961341bd10156108529937ce2bf5a (diff)
downloadKopyPlugin-6534757b525c98abf03f1e04fff77b1b05e4d66e.tar.gz
KopyPlugin-6534757b525c98abf03f1e04fff77b1b05e4d66e.tar.bz2
KopyPlugin-6534757b525c98abf03f1e04fff77b1b05e4d66e.zip
* Enchancements
* Fixes - Your clipboard will not be corrupted * Removed unwanted menus - Now Kopy.io Plugin will show a Notification box with options to Open/Copy your Kopy.io'ed urls * Adds Encryption to your data - Your data is encrypted by default (Unless you share the url with decryption key -- Key is after the '#' part in the url)
Diffstat (limited to 'src/utils.ts')
-rw-r--r--src/utils.ts40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/utils.ts b/src/utils.ts
new file mode 100644
index 0000000..40e985e
--- /dev/null
+++ b/src/utils.ts
@@ -0,0 +1,40 @@
+export class Utils {
+ static createKey(keyLength: number){
+ let keyspace: String = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
+ let text = '';
+ let index;
+ for (let i = 0; i < keyLength; i++)
+ {
+ index = Math.floor(Math.random() * keyspace.length);
+ text += keyspace.charAt(index);
+ }
+ return text;
+ }
+
+ static toUTF8Array(str) {
+ let utf8 = [];
+ for (var i=0; i < str.length; i++) {
+ let charcode = str.charCodeAt(i);
+ if (charcode < 0x80) utf8.push(charcode);
+ else if (charcode < 0x800) {
+ utf8.push(0xc0 | (charcode >> 6),
+ 0x80 | (charcode & 0x3f));
+ }
+ else if (charcode < 0xd800 || charcode >= 0xe000) {
+ utf8.push(0xe0 | (charcode >> 12),
+ 0x80 | ((charcode>>6) & 0x3f),
+ 0x80 | (charcode & 0x3f));
+ }
+ // surrogate pair
+ else {
+ i++;
+ charcode = ((charcode&0x3ff)<<10)|(str.charCodeAt(i)&0x3ff)
+ utf8.push(0xf0 | (charcode >>18),
+ 0x80 | ((charcode>>12) & 0x3f),
+ 0x80 | ((charcode>>6) & 0x3f),
+ 0x80 | (charcode & 0x3f));
+ }
+ }
+ return utf8;
+ }
+} \ No newline at end of file