pax_global_header00006660000000000000000000000064134516306110014512gustar00rootroot0000000000000052 comment=bf63ccebfdea142167aa46e4d149096c77c5ef99 kevva-astral-regex-59bea2d/000077500000000000000000000000001345163061100157175ustar00rootroot00000000000000kevva-astral-regex-59bea2d/.editorconfig000066400000000000000000000002571345163061100204000ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 kevva-astral-regex-59bea2d/.gitattributes000066400000000000000000000000231345163061100206050ustar00rootroot00000000000000* text=auto eol=lf kevva-astral-regex-59bea2d/.gitignore000066400000000000000000000000271345163061100177060ustar00rootroot00000000000000node_modules yarn.lock kevva-astral-regex-59bea2d/.npmrc000066400000000000000000000000231345163061100170320ustar00rootroot00000000000000package-lock=false kevva-astral-regex-59bea2d/.travis.yml000066400000000000000000000000541345163061100200270ustar00rootroot00000000000000language: node_js node_js: - '10' - '8' kevva-astral-regex-59bea2d/index.d.ts000066400000000000000000000012511345163061100176170ustar00rootroot00000000000000declare namespace astralRegex { interface Options { /** Only match an exact string. Useful with `RegExp#test()` to check if a string is a astral symbol. Default: `false` _(Matches any astral symbols in a string)_ */ readonly exact?: boolean; } } /** Regular expression for matching [astral symbols](https://everything2.com/title/astral+plane). @returns A `RegExp` for matching astral symbols. @example ``` import astralRegex = require('astral-regex'); astralRegex({exact: true}).test('🦄'); //=> true 'foo 🦄 💩 bar'.match(astralRegex()); //=> ['🦄', '💩'] ``` */ declare function astralRegex(options?: astralRegex.Options): RegExp; export = astralRegex; kevva-astral-regex-59bea2d/index.js000066400000000000000000000003131345163061100173610ustar00rootroot00000000000000'use strict'; const regex = '[\uD800-\uDBFF][\uDC00-\uDFFF]'; const astralRegex = options => options && options.exact ? new RegExp(`^${regex}$`) : new RegExp(regex, 'g'); module.exports = astralRegex; kevva-astral-regex-59bea2d/index.test-d.ts000066400000000000000000000002271345163061100205760ustar00rootroot00000000000000import {expectType} from 'tsd'; import astralRegex = require('.'); expectType(astralRegex()); expectType(astralRegex({exact: true})); kevva-astral-regex-59bea2d/license000066400000000000000000000021341345163061100172640ustar00rootroot00000000000000MIT License Copyright (c) Kevin Mårtensson (github.com/kevva) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. kevva-astral-regex-59bea2d/package.json000066400000000000000000000010621345163061100202040ustar00rootroot00000000000000{ "name": "astral-regex", "version": "2.0.0", "description": "Regular expression for matching astral symbols", "license": "MIT", "repository": "kevva/astral-regex", "author": { "name": "Kevin Mårtensson", "email": "kevinmartensson@gmail.com", "url": "github.com/kevva" }, "engines": { "node": ">=8" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "astral", "emoji", "regex", "surrogate" ], "devDependencies": { "ava": "^1.4.1", "tsd": "^0.7.2", "xo": "^0.24.0" } } kevva-astral-regex-59bea2d/readme.md000066400000000000000000000015071345163061100175010ustar00rootroot00000000000000# astral-regex [![Build Status](https://travis-ci.org/kevva/astral-regex.svg?branch=master)](https://travis-ci.org/kevva/astral-regex) > Regular expression for matching [astral symbols](https://everything2.com/title/astral+plane) ## Install ``` $ npm install astral-regex ``` ## Usage ```js const astralRegex = require('astral-regex'); astralRegex({exact: true}).test('🦄'); //=> true 'foo 🦄 💩 bar'.match(astralRegex()); //=> ['🦄', '💩'] ``` ## API ### astralRegex([options]) Returns a `RegExp` for matching astral symbols. #### options Type: `Object` ##### exact Type: `boolean`
Default: `false` *(Matches any astral symbols in a string)* Only match an exact string. Useful with `RegExp#test()` to check if a string is a astral symbol. ## License MIT © [Kevin Mårtensson](https://github.com/kevva) kevva-astral-regex-59bea2d/test.js000066400000000000000000000012131345163061100172310ustar00rootroot00000000000000import test from 'ava'; import astralRegex from '.'; const matches = [ '💩', '🦄', '🎠', '🌈', '🐴', '😹' ]; const nonMatches = [ 'a', '안', '1', 'Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍A̴̵̜̰͔ͫ͗͢L̠ͨͧͩ͘G̴̻͈͍͔̹̑͗̎̅͛́Ǫ̵̹̻̝̳͂̌̌͘!͖̬̰̙̗̿̋ͥͥ̂ͣ̐́́͜͞', '…', 'π', '®' ]; test('matches', t => { for (const x of matches) { t.true(astralRegex({exact: true}).test(x)); } for (const x of matches) { t.is((astralRegex().exec(`foo ${x} bar`) || [])[0], x); } }); test('non matches', t => { for (const x of nonMatches) { t.false(astralRegex({exact: true}).test(x)); } });