├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .github └── contributing.md ├── .gitignore ├── .travis.yml ├── .verb.md ├── LICENSE ├── README.md ├── index.js ├── package.json └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | end_of_line = lf 6 | charset = utf-8 7 | indent_size = 2 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [{**/{actual,fixtures,expected,templates}/**,*.md}] 12 | trim_trailing_whitespace = false 13 | insert_final_newline = false -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "ecmaFeatures": { 3 | "modules": true, 4 | "experimentalObjectRestSpread": true 5 | }, 6 | 7 | "env": { 8 | "browser": false, 9 | "es6": true, 10 | "node": true, 11 | "mocha": true 12 | }, 13 | 14 | "globals": { 15 | "document": false, 16 | "navigator": false, 17 | "window": false 18 | }, 19 | 20 | "rules": { 21 | "accessor-pairs": 2, 22 | "arrow-spacing": [2, { "before": true, "after": true }], 23 | "block-spacing": [2, "always"], 24 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 25 | "comma-dangle": [2, "never"], 26 | "comma-spacing": [2, { "before": false, "after": true }], 27 | "comma-style": [2, "last"], 28 | "constructor-super": 2, 29 | "curly": [2, "multi-line"], 30 | "dot-location": [2, "property"], 31 | "eol-last": 2, 32 | "eqeqeq": [2, "allow-null"], 33 | "generator-star-spacing": [2, { "before": true, "after": true }], 34 | "handle-callback-err": [2, "^(err|error)$" ], 35 | "indent": [2, 2, { "SwitchCase": 1 }], 36 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }], 37 | "keyword-spacing": [2, { "before": true, "after": true }], 38 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }], 39 | "new-parens": 2, 40 | "no-array-constructor": 2, 41 | "no-caller": 2, 42 | "no-class-assign": 2, 43 | "no-cond-assign": 2, 44 | "no-const-assign": 2, 45 | "no-control-regex": 2, 46 | "no-debugger": 2, 47 | "no-delete-var": 2, 48 | "no-dupe-args": 2, 49 | "no-dupe-class-members": 2, 50 | "no-dupe-keys": 2, 51 | "no-duplicate-case": 2, 52 | "no-empty-character-class": 2, 53 | "no-eval": 2, 54 | "no-ex-assign": 2, 55 | "no-extend-native": 2, 56 | "no-extra-bind": 2, 57 | "no-extra-boolean-cast": 2, 58 | "no-extra-parens": [2, "functions"], 59 | "no-fallthrough": 2, 60 | "no-floating-decimal": 2, 61 | "no-func-assign": 2, 62 | "no-implied-eval": 2, 63 | "no-inner-declarations": [2, "functions"], 64 | "no-invalid-regexp": 2, 65 | "no-irregular-whitespace": 2, 66 | "no-iterator": 2, 67 | "no-label-var": 2, 68 | "no-labels": 2, 69 | "no-lone-blocks": 2, 70 | "no-mixed-spaces-and-tabs": 2, 71 | "no-multi-spaces": 2, 72 | "no-multi-str": 2, 73 | "no-multiple-empty-lines": [2, { "max": 1 }], 74 | "no-native-reassign": 0, 75 | "no-negated-in-lhs": 2, 76 | "no-new": 2, 77 | "no-new-func": 2, 78 | "no-new-object": 2, 79 | "no-new-require": 2, 80 | "no-new-wrappers": 2, 81 | "no-obj-calls": 2, 82 | "no-octal": 2, 83 | "no-octal-escape": 2, 84 | "no-proto": 0, 85 | "no-redeclare": 2, 86 | "no-regex-spaces": 2, 87 | "no-return-assign": 2, 88 | "no-self-compare": 2, 89 | "no-sequences": 2, 90 | "no-shadow-restricted-names": 2, 91 | "no-spaced-func": 2, 92 | "no-sparse-arrays": 2, 93 | "no-this-before-super": 2, 94 | "no-throw-literal": 2, 95 | "no-trailing-spaces": 0, 96 | "no-undef": 2, 97 | "no-undef-init": 2, 98 | "no-unexpected-multiline": 2, 99 | "no-unneeded-ternary": [2, { "defaultAssignment": false }], 100 | "no-unreachable": 2, 101 | "no-unused-vars": [2, { "vars": "all", "args": "none" }], 102 | "no-useless-call": 0, 103 | "no-with": 2, 104 | "one-var": [0, { "initialized": "never" }], 105 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], 106 | "padded-blocks": [0, "never"], 107 | "quotes": [2, "single", "avoid-escape"], 108 | "radix": 2, 109 | "semi": [2, "always"], 110 | "semi-spacing": [2, { "before": false, "after": true }], 111 | "space-before-blocks": [2, "always"], 112 | "space-before-function-paren": [2, "never"], 113 | "space-in-parens": [2, "never"], 114 | "space-infix-ops": 2, 115 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 116 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], 117 | "use-isnan": 2, 118 | "valid-typeof": 2, 119 | "wrap-iife": [2, "any"], 120 | "yoda": [2, "never"] 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.github/contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to punctuation-regex 2 | 3 | First and foremost, thank you! We appreciate that you want to contribute to punctuation-regex, your time is valuable, and your contributions mean a lot to us. 4 | 5 | **What does "contributing" mean?** 6 | 7 | Creating an issue is the simplest form of contributing to a project. But there are many ways to contribute, including the following: 8 | 9 | - Updating or correcting documentation 10 | - Feature requests 11 | - Bug reports 12 | 13 | If you'd like to learn more about contributing in general, the [Guide to Idiomatic Contributing](https://github.com/jonschlinkert/idiomatic-contributing) has a lot of useful information. 14 | 15 | **Showing support for punctuation-regex** 16 | 17 | Please keep in mind that open source software is built by people like you, who spend their free time creating things the rest the community can use. 18 | 19 | Don't have time to contribute? No worries, here are some other ways to show your support for punctuation-regex: 20 | 21 | - star the [project](https://github.com/jonschlinkert/punctuation-regex) 22 | - tweet your support for punctuation-regex 23 | 24 | ## Issues 25 | 26 | ### Before creating an issue 27 | 28 | Please try to determine if the issue is caused by an underlying library, and if so, create the issue there. Sometimes this is difficult to know. We only ask that you attempt to give a reasonable attempt to find out. Oftentimes the readme will have advice about where to go to create issues. 29 | 30 | Try to follow these guidelines 31 | 32 | - **Investigate the issue**: 33 | - **Check the readme** - oftentimes you will find notes about creating issues, and where to go depending on the type of issue. 34 | - Create the issue in the appropriate repository. 35 | 36 | ### Creating an issue 37 | 38 | Please be as descriptive as possible when creating an issue. Give us the information we need to successfully answer your question or address your issue by answering the following in your issue: 39 | 40 | - **version**: please note the version of punctuation-regex are you using 41 | - **extensions, plugins, helpers, etc** (if applicable): please list any extensions you're using 42 | - **error messages**: please paste any error messages into the issue, or a [gist](https://gist.github.com/) 43 | 44 | ## Above and beyond 45 | 46 | Here are some tips for creating idiomatic issues. Taking just a little bit extra time will make your issue easier to read, easier to resolve, more likely to be found by others who have the same or similar issue in the future. 47 | 48 | - read the [Guide to Idiomatic Contributing](https://github.com/jonschlinkert/idiomatic-contributing) 49 | - take some time to learn basic markdown. This [markdown cheatsheet](https://gist.github.com/jonschlinkert/5854601) is super helpful, as is the GitHub guide to [basic markdown](https://help.github.com/articles/markdown-basics/). 50 | - Learn about [GitHub Flavored Markdown](https://help.github.com/articles/github-flavored-markdown/). And if you want to really go above and beyond, read [mastering markdown](https://guides.github.com/features/mastering-markdown/). 51 | - use backticks to wrap code. This ensures that code will retain its format, making it much more readable to others 52 | - use syntax highlighting by adding the correct language name after the first "code fence" 53 | 54 | 55 | [node-glob]: https://github.com/isaacs/node-glob 56 | [micromatch]: https://github.com/jonschlinkert/micromatch 57 | [so]: http://stackoverflow.com/questions/tagged/punctuation-regex -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # always ignore files 2 | *.DS_Store 3 | *.sublime-* 4 | 5 | # test related, or directories generated by tests 6 | test/actual 7 | actual 8 | coverage 9 | .nyc* 10 | 11 | # npm 12 | node_modules 13 | npm-debug.log 14 | 15 | # yarn 16 | yarn.lock 17 | yarn-error.log 18 | 19 | # misc 20 | _gh_pages 21 | _draft 22 | _drafts 23 | bower_components 24 | vendor 25 | temp 26 | tmp 27 | TODO.md 28 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | os: 3 | - linux 4 | - osx 5 | language: node_js 6 | node_js: 7 | - node 8 | - '6' 9 | - '4' 10 | - '0.12' 11 | - '0.10' 12 | matrix: 13 | allow_failures: 14 | - node_js: '4' 15 | - node_js: '0.12' 16 | - node_js: '0.10' 17 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | See the [wikipedia punctuation](https://en.wikipedia.org/wiki/Punctuation) article for more details. 2 | 3 | ## Usage 4 | 5 | ```js 6 | var punctuation = require('{%= name %}'); 7 | 8 | // the main export is a function that must be called 9 | console.log(punctuation().test('!')); 10 | //=> true 11 | ``` 12 | 13 | Pass `true` to get a regex for matching the additional "supplemental" characters mentioned in the wikipedia article. 14 | 15 | ```js 16 | console.log(punctuation(true).test('‘')); 17 | //=> true 18 | ``` 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017, 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 | # punctuation-regex [![NPM version](https://img.shields.io/npm/v/punctuation-regex.svg?style=flat)](https://www.npmjs.com/package/punctuation-regex) [![NPM monthly downloads](https://img.shields.io/npm/dm/punctuation-regex.svg?style=flat)](https://npmjs.org/package/punctuation-regex) [![NPM total downloads](https://img.shields.io/npm/dt/punctuation-regex.svg?style=flat)](https://npmjs.org/package/punctuation-regex) [![Linux Build Status](https://img.shields.io/travis/regexhq/punctuation-regex.svg?style=flat&label=Travis)](https://travis-ci.org/regexhq/punctuation-regex) 2 | 3 | > Regular expression for matching punctuation characters. 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | ```sh 10 | $ npm install --save punctuation-regex 11 | ``` 12 | 13 | See the [wikipedia punctuation](https://en.wikipedia.org/wiki/Punctuation) article for more details. 14 | 15 | ## Usage 16 | 17 | ```js 18 | var punctuation = require('punctuation-regex'); 19 | 20 | // the main export is a function that must be called 21 | console.log(punctuation().test('!')); 22 | //=> true 23 | ``` 24 | 25 | Pass `true` to get a regex for matching the additional "supplemental" characters mentioned in the wikipedia article. 26 | 27 | ```js 28 | console.log(punctuation(true).test('‘')); 29 | //=> true 30 | ``` 31 | 32 | ## About 33 | 34 | ### Related projects 35 | 36 | * [is-punctuation](https://www.npmjs.com/package/is-punctuation): Returns true if the given string is punctuation characters. | [homepage](https://github.com/jonschlinkert/is-punctuation "Returns true if the given string is punctuation characters.") 37 | * [path-root-regex](https://www.npmjs.com/package/path-root-regex): Regular expression for getting the root of a posix or windows filepath. | [homepage](https://github.com/regexhq/path-root-regex "Regular expression for getting the root of a posix or windows filepath.") 38 | * [whitespace-regex](https://www.npmjs.com/package/whitespace-regex): Regular expression for matching the whitespace in a string. | [homepage](https://github.com/regexps/whitespace-regex "Regular expression for matching the whitespace in a string.") 39 | * [word-regex](https://www.npmjs.com/package/word-regex): Regular expression for matching words in a string. Support for english, CJK and Cyrillic. | [homepage](https://github.com/regexps/word-regex "Regular expression for matching words in a string. Support for english, CJK and Cyrillic.") 40 | 41 | ### Contributing 42 | 43 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). 44 | 45 | Please read the [contributing guide](.github/contributing.md) for avice on opening issues, pull requests, and coding standards. 46 | 47 | ### Building docs 48 | 49 | _(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_ 50 | 51 | To generate the readme and API documentation with [verb](https://github.com/verbose/verb): 52 | 53 | ```sh 54 | $ npm install -g verb verb-generate-readme && verb 55 | ``` 56 | 57 | ### Running tests 58 | 59 | Install dev dependencies: 60 | 61 | ```sh 62 | $ npm install -d && npm test 63 | ``` 64 | 65 | ### Author 66 | 67 | **Jon Schlinkert** 68 | 69 | * [github/jonschlinkert](https://github.com/jonschlinkert) 70 | * [twitter/jonschlinkert](http://twitter.com/jonschlinkert) 71 | 72 | ### License 73 | 74 | Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). 75 | Released under the [MIT license](LICENSE). 76 | 77 | *** 78 | 79 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.2.3, on January 04, 2017._ -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * punctuation-regex 3 | * 4 | * Copyright (c) 2016 Jon Schlinkert. 5 | * Licensed under the MIT license. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | module.exports = function(extended) { 11 | return extended === true 12 | ? /^[\‒\–\—\―|$&~=\\\/⁄@+*!?({[\]})<>‹›«».;:^‘’“”'",،、`·\•†‡°″¡¿※#№÷×%‰\−‱¶′‴§_‖¦]+$/ 13 | : /^[!"#$%&'()*+,./:;<=>?@\^_`{|}~\-]+$/; 14 | }; 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "punctuation-regex", 3 | "description": "Regular expression for matching punctuation characters.", 4 | "version": "0.2.0", 5 | "homepage": "https://github.com/regexhq/punctuation-regex", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "repository": "regexhq/punctuation-regex", 8 | "bugs": { 9 | "url": "https://github.com/regexhq/punctuation-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 | "keywords": [ 23 | "punctuation", 24 | "regex" 25 | ], 26 | "devDependencies": { 27 | "gulp-format-md": "^0.1.11", 28 | "mocha": "^3.2.0" 29 | }, 30 | "verb": { 31 | "toc": false, 32 | "layout": "default", 33 | "tasks": [ 34 | "readme" 35 | ], 36 | "plugins": [ 37 | "gulp-format-md" 38 | ], 39 | "related": { 40 | "list": [ 41 | "is-punctuation", 42 | "whitespace-regex", 43 | "path-root-regex", 44 | "word-regex" 45 | ] 46 | }, 47 | "lint": { 48 | "reflinks": true 49 | }, 50 | "reflinks": [ 51 | "verb", 52 | "verb-generate-readme" 53 | ] 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * punctuation-regex 3 | * 4 | * Copyright (c) 2016 Jon Schlinkert. 5 | * Licensed under the MIT license. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | require('mocha'); 11 | var assert = require('assert'); 12 | var regex = require('./'); 13 | 14 | describe('punctuation-regex', function() { 15 | it('should match punctuation', function () { 16 | assert(!regex().test('foo')); 17 | assert(!regex().test('bar!')); 18 | assert(regex().test('!')); 19 | assert(regex().test('@')); 20 | assert(regex().test('$')); 21 | assert(regex().test('&')); 22 | assert(regex().test('/')); 23 | assert(regex().test('*')); 24 | }); 25 | 26 | it('should match extended punctuation characters', function () { 27 | assert(!regex().test('‘')); 28 | assert(regex(true).test('‘')); 29 | }); 30 | }); 31 | --------------------------------------------------------------------------------