commit bb3cdb413f0399833d29dfcfd976d96d534f4da9 Author: Scott Wallace Date: Sun Sep 15 11:07:08 2019 +0100 Initial code check-in diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5aa5ccc --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +# See https://help.github.com/ignore-files/ for more about ignoring files. + +# dependencies +/node_modules + +# testing +/coverage + +# production +/dist + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +yarn.lock diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..b14796c --- /dev/null +++ b/.npmignore @@ -0,0 +1,4 @@ +src +node_modules +screenshot.png +yarn.lock diff --git a/package.json b/package.json new file mode 100644 index 0000000..c2d05f0 --- /dev/null +++ b/package.json @@ -0,0 +1,35 @@ +{ + "name": "cerebro-genpw", + "version": "1.0.0", + "description": "Cerebro plugin to search using a Searx instance", + "license": "MIT", + "repository": "scottwallacesh/cerebro-genpw", + "author": { + "name": "Scott Wallace", + "email": "scott@wallace.sh", + "url": "https://scott.wallace.sh" + }, + "engines": { + "node": ">=4" + }, + "dependencies": { + "cerebro-tools": "^0.1.8", + "cerebro-ui": "^0.0.16" + }, + "devDependencies": { + "cerebro-scripts": "0.0.25" + }, + "main": "dist/index.js", + "keywords": [ + "cerebro", + "cerebro-plugin", + "genpw" + ], + "scripts": { + "start": "cerebro-scripts start", + "build": "cerebro-scripts build", + "test": "cerebro-scripts test", + "clear": "cerebro-scripts clear", + "prepublish": "yarn clear && yarn build" + } + } diff --git a/src/icon.png b/src/icon.png new file mode 100644 index 0000000..d0c4b70 Binary files /dev/null and b/src/icon.png differ diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..62f179d --- /dev/null +++ b/src/index.js @@ -0,0 +1,46 @@ +const React = require('react'); + +const icon = require('./icon.png'); + +const KEYWORD = 'genpw'; +const STRLEN = 16; + +const mkstr = length => { + var result = ''; + var characters = + 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@/?#$%&*()[]{},.!~'; + var charactersLength = characters.length; + for (var i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * charactersLength)); + } + 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 (match) { + var length = match[1]; + } else { + var length = STRLEN; + } + + 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 = { + fn: generate +};