├── .editorconfig ├── .gitattributes ├── .gitignore ├── .jshintrc ├── .travis.yml ├── .verb.md ├── LICENSE ├── README.md ├── bower.json ├── index.js ├── package.json └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | end_of_line = lf 7 | charset = utf-8 8 | indent_size = 2 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | insert_final_newline = false 15 | 16 | [{,test/}{actual,fixtures}/**] 17 | trim_trailing_whitespace = false 18 | insert_final_newline = false 19 | 20 | [templates/**] 21 | trim_trailing_whitespace = false 22 | insert_final_newline = false 23 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | *.sublime-* 3 | _gh_pages 4 | bower_components 5 | node_modules 6 | npm-debug.log 7 | actual 8 | test/actual 9 | temp 10 | tmp 11 | TODO.md 12 | vendor 13 | .idea 14 | benchmark 15 | coverage 16 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "asi": false, 3 | "boss": true, 4 | "curly": true, 5 | "eqeqeq": true, 6 | "eqnull": true, 7 | "esnext": true, 8 | "immed": true, 9 | "latedef": false, 10 | "laxcomma": false, 11 | "mocha": true, 12 | "newcap": true, 13 | "noarg": true, 14 | "node": true, 15 | "sub": true, 16 | "undef": true, 17 | "unused": true 18 | } 19 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - "0.10" 5 | - "0.12" 6 | - "0.13" 7 | - "iojs" 8 | matrix: 9 | fast_finish: true 10 | allow_failures: 11 | - node_js: "0.13" 12 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | # {%= name %} {%= badge("fury") %} {%= badge("travis") %} 2 | 3 | > {%= description %} 4 | 5 | ## Install 6 | {%= include("install-npm", {save: true}) %} 7 | 8 | ## Usage 9 | 10 | ```js 11 | var regex = require('{%= name %}'); 12 | ``` 13 | 14 | **Examples** 15 | 16 | _(Any of the following can start with `todo` or `@todo` and an optional colon)_ 17 | 18 | JavaScript line comments: 19 | 20 | ```js 21 | var match = '// todo: foo bar baz'.match(regex()); 22 | //=> 'foo bar baz' 23 | ``` 24 | 25 | JavaScript block comments: 26 | 27 | ```js 28 | var match = '/*\n * @todo one two three\n */'.match(regex()); 29 | //=> 'one two three' 30 | ``` 31 | 32 | HTML comments: 33 | 34 | ```js 35 | var match = ''.match(regex()); 36 | //=> 'foo bar baz' 37 | ``` 38 | 39 | ## Related projects 40 | {%= related(['copyright-regex', 'dotfile-regex', 'path-regex']) %} 41 | 42 | ## Running tests 43 | {%= include("tests") %} 44 | 45 | ## Contributing 46 | {%= include("contributing") %} 47 | 48 | ## Author 49 | {%= include("author") %} 50 | 51 | ## License 52 | {%= copyright() %} 53 | {%= license() %} 54 | 55 | *** 56 | 57 | {%= include("footer") %} 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015, Jon Schlinkert. 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # todo-regex [![NPM version](https://badge.fury.io/js/todo-regex.svg)](http://badge.fury.io/js/todo-regex) [![Build Status](https://travis-ci.org/regexps/todo-regex.svg)](https://travis-ci.org/regexps/todo-regex) 2 | 3 | > Regular expression for matching TODO statements in a string. 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/) 8 | 9 | ```sh 10 | $ npm i todo-regex --save 11 | ``` 12 | 13 | ## Usage 14 | 15 | ```js 16 | var regex = require('todo-regex'); 17 | ``` 18 | 19 | **Examples** 20 | 21 | _(Any of the following can start with `todo` or `@todo` and an optional colon)_ 22 | 23 | JavaScript line comments: 24 | 25 | ```js 26 | var match = '// todo: foo bar baz'.match(regex()); 27 | //=> 'foo bar baz' 28 | ``` 29 | 30 | JavaScript block comments: 31 | 32 | ```js 33 | var match = '/*\n * @todo one two three\n */'.match(regex()); 34 | //=> 'one two three' 35 | ``` 36 | 37 | HTML comments: 38 | 39 | ```js 40 | var match = ''.match(regex()); 41 | //=> 'foo bar baz' 42 | ``` 43 | 44 | ## Related projects 45 | 46 | * [copyright-regex](https://github.com/regexps/copyright-regex): Regex for matching and parsing copyright statements. 47 | * [dotfile-regex](https://github.com/regexps/dotfile-regex): Regular expresson for matching dotfiles. 48 | * [path-regex](https://github.com/regexps/path-regex): Regular expression for matching the parts of a file path. 49 | 50 | ## Running tests 51 | 52 | Install dev dependencies: 53 | 54 | ```sh 55 | $ npm i -d && npm test 56 | ``` 57 | 58 | ## Contributing 59 | 60 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/regexps/todo-regex/issues/new) 61 | 62 | ## Author 63 | 64 | **Jon Schlinkert** 65 | 66 | + [github/jonschlinkert](https://github.com/jonschlinkert) 67 | + [twitter/jonschlinkert](http://twitter.com/jonschlinkert) 68 | 69 | ## License 70 | 71 | *** 72 | 73 | _This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on May 26, 2015._ -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "todo-regex", 3 | "description": "Regular expression for matching TODO statements in a string.", 4 | "repository": "regexps/todo-regex", 5 | "license": "MIT", 6 | "homepage": "https://github.com/regexps/todo-regex", 7 | "authors": [ 8 | "Jon Schlinkert (https://github.com/jonschlinkert)" 9 | ], 10 | "main": [ 11 | "index.js" 12 | ], 13 | "ignore": [".*"], 14 | "devDependencies": { 15 | "mocha": "*" 16 | }, 17 | "keywords": [ 18 | "expression", 19 | "regex", 20 | "regexp", 21 | "regular", 22 | "todo" 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * todo-regex 3 | * 4 | * Copyright (c) 2015, Jon Schlinkert. 5 | * Licensed under the MIT License. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | module.exports = function () { 11 | return /|(?:@|\/\/[ \t]*)?(?:todo|fixme):?[ \t]*([^\n]+)/i; 12 | }; 13 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "todo-regex", 3 | "description": "Regular expression for matching TODO statements in a string.", 4 | "version": "0.1.1", 5 | "homepage": "https://github.com/regexps/todo-regex", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "repository": "regexps/todo-regex", 8 | "bugs": { 9 | "url": "https://github.com/regexps/todo-regex/issues" 10 | }, 11 | "license": "MIT", 12 | "files": [ 13 | "index.js" 14 | ], 15 | "main": "index.js", 16 | "engines": { 17 | "node": ">=0.10.0" 18 | }, 19 | "scripts": { 20 | "test": "mocha" 21 | }, 22 | "devDependencies": { 23 | "mocha": "*" 24 | }, 25 | "keywords": [ 26 | "expression", 27 | "regex", 28 | "regexp", 29 | "regular", 30 | "todo" 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * todo-regex 3 | * 4 | * Copyright (c) 2015 Jon Schlinkert. 5 | * Licensed under the MIT license. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | /* deps: mocha */ 11 | var assert = require('assert'); 12 | var regex = require('./'); 13 | 14 | function todos(str) { 15 | var m = str.match(regex()); 16 | if (!m) return; 17 | return (m[1] || m[2]).trim(); 18 | } 19 | 20 | describe('regex', function () { 21 | it('should match todos in line comments:', function () { 22 | assert.equal(todos('// todo: abc'), 'abc', true); 23 | assert.equal(todos('// @todo: abc'), 'abc', true); 24 | assert.equal(todos('// todo abc xyz'), 'abc xyz', true); 25 | assert.equal(todos('// @todo abc xyz'), 'abc xyz', true); 26 | }); 27 | 28 | it('should match todos in block comments:', function () { 29 | assert.equal(todos('/*\n * @todo one two\n */'), 'one two', true); 30 | assert.equal(todos('/*\n * @todo: abc xyz\n */'), 'abc xyz', true); 31 | assert.equal(todos('/*\n * todo: abc xyz\n */'), 'abc xyz', true); 32 | }); 33 | 34 | it('should match todos in html comments:', function () { 35 | assert.equal(todos(''), 'foo bar baz', true); 36 | assert.equal(todos(''), 'a b c d', true); 37 | assert.equal(todos(''), 'a b c d', true); 38 | }); 39 | }); 40 | --------------------------------------------------------------------------------