From f5ed1d396ea011920d9a113e94c5bfe7673fa39c Mon Sep 17 00:00:00 2001 From: Scott Wallace Date: Sun, 15 Sep 2019 11:32:40 +0100 Subject: [PATCH] Only show when the full keyword is used. Display a preview. --- src/index.js | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/index.js b/src/index.js index 62f179d..2dfbb45 100644 --- a/src/index.js +++ b/src/index.js @@ -1,14 +1,14 @@ -const React = require('react'); +const React = require("react"); -const icon = require('./icon.png'); +const icon = require("./icon.png"); -const KEYWORD = 'genpw'; +const KEYWORD = "genpw"; const STRLEN = 16; const mkstr = length => { - var result = ''; + var result = ""; var characters = - 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@/?#$%&*()[]{},.!~'; + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@/?#$%&*()[]{},.!~"; var charactersLength = characters.length; for (var i = 0; i < length; i++) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); @@ -16,29 +16,28 @@ const mkstr = length => { return result; }; -const order = 10; - const generate = ({ term, actions, display }) => { - let regex = new RegExp('^' + KEYWORD + '\\s+([0-9]+)', 'i'); - let match = term.match(regex); + if (term.startsWith(KEYWORD)) { + let match = term.match(/^.+\s+([0-9]+)/i); - if (match) { - var length = match[1]; - } else { - var length = STRLEN; + if (match && match[1]) { + var length = match[1]; + } else { + var length = STRLEN; + } + + var newstr = mkstr(length); + const result = { + icon, + term, + title: "Generate a random string", + subtitle: "Add a " + length + " character random string to the clipboard", + onSelect: () => actions.copyToClipboard(newstr), + getPreview: () => "" + newstr + "" + }; + + display(result); } - - var newstr = mkstr(length); - const result = { - icon, - order, - term, - title: 'Add the following ' + length + ' character random string to the clipboard', - subtitle: newstr, - onSelect: () => actions.copyToClipboard(newstr) - }; - - display(result); }; module.exports = {