├── .gitignore ├── .github └── FUNDING.yml ├── example └── index.js ├── bin ├── docs │ └── help.js └── idea ├── LICENSE ├── CONTRIBUTING.md ├── DOCUMENTATION.md ├── package.json ├── lib └── index.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.swo 3 | *~ 4 | *.log 5 | node_modules 6 | *.env 7 | .DS_Store 8 | package-lock.json 9 | .bloggify/* 10 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: ionicabizau 2 | patreon: ionicabizau 3 | open_collective: ionicabizau 4 | custom: https://www.buymeacoffee.com/h96wwchmy -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | // Dependencies 2 | var Idea = require("../lib"); 3 | 4 | // Initialize the idea object 5 | var idea = new Idea("./ideas.json", err => { 6 | if (err) throw err; 7 | idea.create("Implement something cool.", err => { 8 | if (err) throw err; 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /bin/docs/help.js: -------------------------------------------------------------------------------- 1 | module.exports = "idea help" 2 | + "\n" + "usage: idea [command] " 3 | + "\n" + "" 4 | + "\n" + "A lightweight CLI tool and module for keeping your ideas in a safe place quick and easy." 5 | + "\n" + "" 6 | + "\n" + "[command]" 7 | + "\n" + " create Creates and saves a new idea. Example: `idea create \"Implement something very cool\"`" 8 | + "\n" + " list Lists all ideas. Example: `idea list`" 9 | + "\n" + " filter Lists filtered ideas. Example: `idea filter '{\"state\": \"SOLVED\"}'`" 10 | + "\n" + " solve Solves an idea. Example `idea solve 1`" 11 | + "\n" + " remove Removes an idea. Example `idea remove 1`" 12 | + "\n" + " help Prints this help." 13 | + "\n" + "" 14 | + "\n" + "Documentation can be found at https://github.com/IonicaBizau/idea" 15 | ; 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-25 Ionică Bizău (https://ionicabizau.net) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # 🌟 Contributing 2 | 3 | Want to contribute to this project? Great! Please read these quick steps to streamline the process and avoid unnecessary tasks. ✨ 4 | 5 | ## 💬 Discuss Changes 6 | Start by opening an issue in the repository using the [bug tracker][1]. Describe your proposed contribution or the bug you've found. If relevant, include platform info and screenshots. 🖼️ 7 | 8 | Wait for feedback before proceeding unless the fix is straightforward, like a typo. 📝 9 | 10 | ## 🔧 Fixing Issues 11 | 12 | Fork the project and create a branch for your fix, naming it `some-great-feature` or `some-issue-fix`. Commit changes while following the [code style][2]. If the project has tests, add one. ✅ 13 | 14 | If a `package.json` or `bower.json` exists, add yourself to the `contributors` array; create it if it doesn't. 🙌 15 | 16 | ```json 17 | { 18 | "contributors": [ 19 | "Your Name (http://your.website)" 20 | ] 21 | } 22 | ``` 23 | 24 | ## 📬 Creating a Pull Request 25 | Open a pull request and reference the initial issue (e.g., *fixes #*). Provide a clear title and consider adding visual aids for clarity. 📊 26 | 27 | ## ⏳ Wait for Feedback 28 | Your contributions will be reviewed. If feedback is given, update your branch as needed, and the pull request will auto-update. 🔄 29 | 30 | ## 🎉 Everyone Is Happy! 31 | Your contributions will be merged, and everyone will appreciate your effort! 😄❤️ 32 | 33 | Thanks! 🤩 34 | 35 | [1]: /issues 36 | [2]: https://github.com/IonicaBizau/code-style -------------------------------------------------------------------------------- /DOCUMENTATION.md: -------------------------------------------------------------------------------- 1 | ## Documentation 2 | 3 | You can see below the API reference of this module. 4 | 5 | ### `Idea(path, callback)` 6 | 7 | #### Params 8 | 9 | - **String** `path`: The path to the JSON file where your ideas will be stored (default: `~/.ideas.json`). 10 | - **Function** `callback`: The callback function. 11 | 12 | #### Return 13 | - **Idea** The `Idea` instance. 14 | 15 | ### `list(callback)` 16 | Lists all ideas. 17 | 18 | #### Params 19 | 20 | - **Function** `callback`: The callback function. 21 | 22 | #### Return 23 | - **Idea** The `Idea` instance. 24 | 25 | ### `filter(filters, callback)` 26 | Filters ideas. 27 | 28 | #### Params 29 | 30 | - **Object** `filters`: An MongoDB like query object. 31 | - **Function** `callback`: The callback function. 32 | 33 | #### Return 34 | - **Idea** The `Idea` instance. 35 | 36 | ### `create(idea, callback)` 37 | 38 | #### Params 39 | 40 | - **String** `idea`: The idea you have. 41 | - **Function** `callback`: The callback function. 42 | 43 | #### Return 44 | - **Idea** The `Idea` instance. 45 | 46 | ### `solve(id, callback)` 47 | Solves an idea. 48 | 49 | #### Params 50 | 51 | - **String** `id`: The idea id. 52 | - **Function** `callback`: The callback function. 53 | 54 | #### Return 55 | - **Idea** The `Idea` instance. 56 | 57 | ### `remove(id, callback)` 58 | 59 | #### Params 60 | 61 | - **String** `id`: The idea id. 62 | - **Function** `callback`: The callback function. 63 | 64 | #### Return 65 | - **Idea** The `Idea` instance. 66 | 67 | ### `save(callback)` 68 | Saves the ideas in the file. 69 | 70 | #### Params 71 | 72 | - **Function** `callback`: The callback function. 73 | 74 | #### Return 75 | - **Idea** The `Idea` instance. 76 | 77 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "idea", 3 | "version": "2.1.1", 4 | "description": "A lightweight CLI tool and module for keeping ideas in a safe place quick and easy.", 5 | "main": "lib/index.js", 6 | "bin": { 7 | "idea": "./bin/idea" 8 | }, 9 | "dependencies": { 10 | "abs": "^1.2.0", 11 | "ansi-parser": "^3.0.0", 12 | "bug-killer": "^4.2.0", 13 | "couleurs": "^5.2.0", 14 | "daty": "^1.0.0", 15 | "is-there": "^4.3.0", 16 | "le-table": "^4.2.0", 17 | "r-json": "^1.2.0", 18 | "sift": "^3.0.0", 19 | "ul": "^5.2.0", 20 | "w-json": "^1.3.0" 21 | }, 22 | "devDependencies": {}, 23 | "scripts": { 24 | "test": "echo \"Error: no test specified\" && exit 1" 25 | }, 26 | "repository": { 27 | "type": "git", 28 | "url": "git@github.com:IonicaBizau/idea.git" 29 | }, 30 | "keywords": [ 31 | "idea", 32 | "keep" 33 | ], 34 | "author": "Ionică Bizău (https://ionicabizau.net)", 35 | "contributors": [ 36 | { 37 | "name": "Daniel Dias", 38 | "url": "https://github.com/LeinadAsid", 39 | "email": "danynovaisdias@outlook.com" 40 | } 41 | ], 42 | "license": "MIT", 43 | "bugs": { 44 | "url": "https://github.com/IonicaBizau/idea/issues" 45 | }, 46 | "homepage": "https://github.com/IonicaBizau/idea", 47 | "blah": { 48 | "h_img": "http://i.imgur.com/BGMt0Ne.png" 49 | }, 50 | "files": [ 51 | "bin/", 52 | "app/", 53 | "lib/", 54 | "dist/", 55 | "src/", 56 | "scripts/", 57 | "resources/", 58 | "menu/", 59 | "cli.js", 60 | "index.js", 61 | "index.d.ts", 62 | "package-lock.json", 63 | "bloggify.js", 64 | "bloggify.json", 65 | "bloggify/" 66 | ] 67 | } -------------------------------------------------------------------------------- /bin/idea: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const Idea = require("../lib") 4 | , logger = require("bug-killer") 5 | , Table = require("le-table") 6 | , couleurs = require("couleurs") 7 | , ansiParser = require("ansi-parser") 8 | , Daty = require("daty") 9 | ; 10 | 11 | // Defaults 12 | Table.defaults.marks = { 13 | nw: "┌" 14 | , n: "─" 15 | , ne: "┐" 16 | , e: "│" 17 | , se: "┘" 18 | , s: "─" 19 | , sw: "└" 20 | , w: "│" 21 | , b: " " 22 | , mt: "┬" 23 | , ml: "├" 24 | , mr: "┤" 25 | , mb: "┴" 26 | , mm: "┼" 27 | }; 28 | 29 | function display(arr) { 30 | if (!arr.length) { 31 | return logger.log("No ideas fetched.", "info"); 32 | } 33 | var tbl = new Table() 34 | , i = 0 35 | , c = 0 36 | ; 37 | 38 | tbl.addRow([ 39 | couleurs("Id").bold() 40 | , couleurs("Date").bold() 41 | , couleurs("State").bold() 42 | , couleurs("Idea").bold() 43 | ]); 44 | 45 | for (; i < arr.length; ++i) { 46 | c = arr[i]; 47 | c.date = new Daty(c.date).format("dddd, MM/DD/YYYY"); 48 | tbl.addRow([c.id + 1, c.date, c.state, c.idea]); 49 | } 50 | 51 | console.log(ansiParser.removeAnsi(tbl.toString())); 52 | } 53 | 54 | var idea = new Idea(err => { 55 | if (err) { return logger.log(err, "error"); } 56 | var commands = { 57 | create: callback => { 58 | idea.create(process.argv[3], err => { 59 | if (err) { return callback(err); } 60 | callback("Idea was added."); 61 | }); 62 | idea.save(); 63 | } 64 | , list: callback => { 65 | idea.filter({}, callback); 66 | } 67 | , filter: callback => { 68 | try { 69 | var filter = JSON.parse(process.argv[3] || "{ \"state\": \"OPEN\" }"); 70 | } catch (e) { 71 | return callback("Cannot parse the filter.", "error"); 72 | } 73 | idea.filter(filter, callback); 74 | } 75 | , solve: callback => { 76 | idea.solve(process.argv[3], () => { 77 | if (err) { return callback(err); } 78 | callback("Idea was solved."); 79 | }); 80 | idea.save(); 81 | } 82 | , help: () => { 83 | console.log(require("./docs/help")); 84 | } 85 | , remove: () => { 86 | idea.remove(process.argv[3], () => { 87 | if (err) { return callback(err); } 88 | callback("Idea was removed"); 89 | }); 90 | idea.save(); 91 | } 92 | }; 93 | 94 | if (~process.argv.indexOf("-h") || ~process.argv.indexOf("--help")) { 95 | return commands.help(); 96 | } 97 | 98 | if (!commands[process.argv[2]]) { 99 | process.argv[2] = "filter"; 100 | } 101 | 102 | commands[process.argv[2]]((err, res) => { 103 | if (err) { 104 | return logger.log(err, "error"); 105 | } 106 | 107 | if (typeof res === "string") { 108 | return logger.log(res, "info"); 109 | } 110 | 111 | display(res); 112 | }); 113 | }); 114 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Dependencies 4 | const sift = require("sift") 5 | , isThere = require("is-there") 6 | , abs = require("abs") 7 | , rJson = require("r-json") 8 | , wJson = require("w-json") 9 | ; 10 | 11 | // Constants 12 | const DEFAULT_PATH = abs("~/.ideas.json"); 13 | 14 | /** 15 | * Idea 16 | * 17 | * @name Idea 18 | * @function 19 | * @param {String} path The path to the JSON file where your ideas will be stored (default: `~/.ideas.json`). 20 | * @param {Function} callback The callback function. 21 | * @return {Idea} The `Idea` instance. 22 | */ 23 | class Idea { 24 | constructor (path, callback) { 25 | if (typeof path === "function") { 26 | callback = path; 27 | path = null; 28 | } 29 | 30 | // Defaults 31 | this.path = path = path || DEFAULT_PATH; 32 | callback = callback || (err => { if (err) throw err }); 33 | 34 | // Init 35 | if (!isThere(this.path)) { 36 | this.ideas = []; 37 | this.save(callback); 38 | } else { 39 | this.list((err, ideas) => { 40 | if (err) { return callback(err); } 41 | this.ideas = ideas; 42 | callback(null, ideas, this); 43 | }); 44 | } 45 | } 46 | /** 47 | * list 48 | * Lists all ideas. 49 | * 50 | * @name list 51 | * @function 52 | * @param {Function} callback The callback function. 53 | * @return {Idea} The `Idea` instance. 54 | */ 55 | list (callback) { 56 | rJson(this.path, (err, content) => { 57 | if (err) { return callback(err); } 58 | callback(err, content); 59 | }); 60 | return this; 61 | } 62 | /** 63 | * filter 64 | * Filters ideas. 65 | * 66 | * @name filter 67 | * @function 68 | * @param {Object} filters An MongoDB like query object. 69 | * @param {Function} callback The callback function. 70 | * @return {Idea} The `Idea` instance. 71 | */ 72 | filter (filters, callback) { 73 | callback(null, sift(filters, this.ideas)); 74 | return this; 75 | } 76 | /** 77 | * create 78 | * 79 | * @name create 80 | * @function 81 | * @param {String} idea The idea you have. 82 | * @param {Function} callback The callback function. 83 | * @return {Idea} The `Idea` instance. 84 | */ 85 | create (idea, callback) { 86 | if (!idea) { 87 | return callback(new Error("Idea cannot be empty.")); 88 | } 89 | this.ideas.push({ 90 | id: this.ideas.length 91 | , idea: idea 92 | , date: new Date() 93 | , state: "OPEN" 94 | }); 95 | return this; 96 | } 97 | /** 98 | * solve 99 | * Solves an idea. 100 | * 101 | * @name solve 102 | * @function 103 | * @param {String} id The idea id. 104 | * @param {Function} callback The callback function. 105 | * @return {Idea} The `Idea` instance. 106 | */ 107 | solve (id, callback) { 108 | if (!this.ideas[id - 1]) { 109 | return callback(new Error("Cannot find any idea with this id.")); 110 | } 111 | this.ideas[id - 1].state = "SOLVED"; 112 | return this; 113 | } 114 | /** 115 | * remove 116 | * 117 | * @name remove 118 | * @function 119 | * @param {String} id The idea id. 120 | * @param {Function} callback The callback function. 121 | * @return {Idea} The `Idea` instance. 122 | */ 123 | remove (id, callback) { 124 | if (!this.ideas[id - 1]) { 125 | return callback(new Error("Cannot find any idea with this id.")) 126 | } 127 | this.ideas.splice(id - 1, 1); 128 | this.ideas.map((idea, index) => { 129 | idea.id = index + 1; 130 | }); 131 | return this; 132 | } 133 | /** 134 | * save 135 | * Saves the ideas in the file. 136 | * 137 | * @name save 138 | * @function 139 | * @param {Function} callback The callback function. 140 | * @return {Idea} The `Idea` instance. 141 | */ 142 | save (callback) { 143 | wJson(this.path, this.ideas, callback); 144 | return this; 145 | } 146 | } 147 | 148 | module.exports = Idea; 149 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | [![idea](http://i.imgur.com/BGMt0Ne.png)](#) 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | # `$ idea` 23 | 24 | [![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [![Ask me anything](https://img.shields.io/badge/ask%20me-anything-1abc9c.svg)](https://github.com/IonicaBizau/ama) [![Version](https://img.shields.io/npm/v/idea.svg)](https://www.npmjs.com/package/idea) [![Downloads](https://img.shields.io/npm/dt/idea.svg)](https://www.npmjs.com/package/idea) [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/@johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github) 25 | 26 | Buy Me A Coffee 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | > A lightweight CLI tool and module for keeping ideas in a safe place quick and easy. 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | ## :cloud: Installation 53 | 54 | You can install the package globally and use it as command line tool: 55 | 56 | 57 | ```sh 58 | # Using npm 59 | npm install --global idea 60 | 61 | # Using yarn 62 | yarn global add idea 63 | ``` 64 | 65 | 66 | Then, run `idea --help` and see what the CLI tool can do. 67 | 68 | 69 | ``` 70 | $ idea --help 71 | idea help 72 | usage: idea [command] 73 | 74 | A lightweight CLI tool and module for keeping your ideas in a safe place quick and easy. 75 | 76 | [command] 77 | create Creates and saves a new idea. Example: `idea create "Implement something very cool"` 78 | list Lists all ideas. Example: `idea list` 79 | filter Lists filtered ideas. Example: `idea filter '{"state": "SOLVED"}'` 80 | solve Solves an idea. Example `idea solve 1` 81 | remove Removes an idea. Example `idea remove 1` 82 | help Prints this help. 83 | 84 | Documentation can be found at https://github.com/IonicaBizau/idea 85 | ``` 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | ## :clipboard: Example 100 | 101 | 102 | 103 | Here is an example how to use this package as library. To install it locally, as library, you can use `npm install idea` (or `yarn add idea`): 104 | 105 | 106 | 107 | ```js 108 | // Dependencies 109 | var Idea = require("idea"); 110 | 111 | // Initialize the idea object 112 | var idea = new Idea("./ideas.json", err => { 113 | if (err) throw err; 114 | idea.create("Implement something cool.", err => { 115 | if (err) throw err; 116 | }); 117 | }); 118 | ``` 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | ## :question: Get Help 132 | 133 | There are few ways to get help: 134 | 135 | 136 | 137 | 1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question. 138 | 2. For bug reports and feature requests, open issues. :bug: 139 | 3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket: 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | ## :memo: Documentation 148 | 149 | For full API reference, see the [DOCUMENTATION.md][docs] file. 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | ## :yum: How to contribute 163 | Have an idea? Found a bug? See [how to contribute][contributing]. 164 | 165 | 166 | ## :sparkling_heart: Support my projects 167 | I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, 168 | this takes time. You can integrate and use these projects in your applications *for free*! You can even change the source code and redistribute (even resell it). 169 | 170 | However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it: 171 | 172 | 173 | - Starring and sharing the projects you like :rocket: 174 | - [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you after years if you buy me one. :grin: :book: 175 | - [![PayPal][badge_paypal]][paypal-donations]—You can make one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea: 176 | - [![Support me on Patreon][badge_patreon]][patreon]—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone). 177 | - **Bitcoin**—You can send me bitcoins at this address (or scanning the code below): `1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6` 178 | 179 | ![](https://i.imgur.com/z6OQI95.png) 180 | 181 | 182 | Thanks! :heart: 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | ## :dizzy: Where is this library used? 200 | If you are using this library in one of your projects, add it in this list. :sparkles: 201 | 202 | - `security-bcrypt` 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | ## :scroll: License 215 | 216 | [MIT][license] © [Ionică Bizău][website] 217 | 218 | 219 | 220 | 221 | 222 | 223 | [license]: /LICENSE 224 | [website]: https://ionicabizau.net 225 | [contributing]: /CONTRIBUTING.md 226 | [docs]: /DOCUMENTATION.md 227 | [badge_patreon]: https://ionicabizau.github.io/badges/patreon.svg 228 | [badge_amazon]: https://ionicabizau.github.io/badges/amazon.svg 229 | [badge_paypal]: https://ionicabizau.github.io/badges/paypal.svg 230 | [badge_paypal_donate]: https://ionicabizau.github.io/badges/paypal_donate.svg 231 | [patreon]: https://www.patreon.com/ionicabizau 232 | [amazon]: http://amzn.eu/hRo9sIZ 233 | [paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW 234 | --------------------------------------------------------------------------------