Only show when the full keyword is used.

Display a preview.
This commit is contained in:
Scott Wallace 2019-09-15 11:32:40 +01:00
parent bb3cdb413f
commit f5ed1d396e

View file

@ -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,13 +16,11 @@ 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) {
if (match && match[1]) {
var length = match[1];
} else {
var length = STRLEN;
@ -31,14 +29,15 @@ const generate = ({ term, actions, display }) => {
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)
title: "Generate a random string",
subtitle: "Add a " + length + " character random string to the clipboard",
onSelect: () => actions.copyToClipboard(newstr),
getPreview: () => "<Preview>" + newstr + "</Preview>"
};
display(result);
}
};
module.exports = {