Skip to content

Commit

Permalink
Chore(all): Tidy up RegExp
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Apr 25, 2024
1 parent fe0ebdb commit b2f13eb
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.json
Expand Up @@ -49,9 +49,11 @@
"import/no-duplicates": "error",
"import/order": "error",
"prettier/prettier": "error",
"unicorn/better-regex": "error",
"unicorn/no-abusive-eslint-disable": "error",
"unicorn/prefer-module": "error",
"unicorn/prefer-node-protocol": "error",
"unicorn/prefer-regexp-test": "error",
"unicorn/prefer-string-replace-all": "error"
},
"overrides": [
Expand Down
4 changes: 2 additions & 2 deletions packages/inquirer/examples/input.js
Expand Up @@ -5,7 +5,7 @@
import chalk from 'chalk';
import inquirer from '../lib/inquirer.js';

const hexRegEx = /([0-9]|[a-f])/gim;
const hexRegEx = /(\d|[a-f])/gim;
const isHex = (value) =>
(value.match(hexRegEx) || []).length === value.length &&
(value.length === 3 || value.length === 6);
Expand Down Expand Up @@ -43,7 +43,7 @@ const questions = [
message: "What's your phone number",
validate(value) {
const pass = value.match(
/^([01]{1})?[-.\s]?\(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?){1}(?:\d+)?)?$/i,
/^([01])?[\s.-]?\(?(\d{3})\)?[\s.-]?(\d{3})[\s.-]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?)(?:\d+)?)?$/i,
);
if (pass) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/examples/pizza.js
Expand Up @@ -21,7 +21,7 @@ const questions = [
message: "What's your phone number?",
validate(value) {
const pass = value.match(
/^([01]{1})?[-.\s]?\(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?){1}(?:\d+)?)?$/i,
/^([01])?[\s.-]?\(?(\d{3})\)?[\s.-]?(\d{3})[\s.-]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?)(?:\d+)?)?$/i,
);
if (pass) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/examples/regex-validate-input.js
Expand Up @@ -10,7 +10,7 @@ const questions = [
name: 'api_key',
message: 'Please enter a valid API key.',
validate(input) {
if (/([a-f0-9]{40})/g.test(input)) {
if (/([\da-f]{40})/g.test(input)) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/examples/rx-observable-array.js
Expand Up @@ -21,7 +21,7 @@ const questions = [
message: "What's your phone number",
validate(value) {
const pass = value.match(
/^([01]{1})?[-.\s]?\(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?){1}(?:\d+)?)?$/i,
/^([01])?[\s.-]?\(?(\d{3})\)?[\s.-]?(\d{3})[\s.-]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?)(?:\d+)?)?$/i,
);
if (pass) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/examples/rx-observable-create.js
Expand Up @@ -23,7 +23,7 @@ const observe = Observable.create((obs) => {
message: "What's your phone number",
validate(value) {
const pass = value.match(
/^([01]{1})?[-.\s]?\(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?){1}(?:\d+)?)?$/i,
/^([01])?[\s.-]?\(?(\d{3})\)?[\s.-]?(\d{3})[\s.-]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?)(?:\d+)?)?$/i,
);
if (pass) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/lib/ui/bottom-bar.js
Expand Up @@ -68,7 +68,7 @@ export default class BottomBar extends Base {
*/

enforceLF(str) {
return str.match(/[\r\n]$/) ? str : str + '\n';
return /[\n\r]$/.test(str) ? str : str + '\n';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/test/specs/utils/paginator.test.js
Expand Up @@ -33,7 +33,7 @@ const endIndex = output.split('\n').length - 1;
const getPage = (paginator, index) => {
const lines = paginator.paginate(output, index, pageSize).split('\n');
const lastLine = lines.pop();
if (!lastLine.match(/Move up and down/)) {
if (!/Move up and down/.test(lastLine)) {
lines.push(lastLine);
}
return lines.join('\n');
Expand Down
2 changes: 1 addition & 1 deletion packages/rawlist/src/index.mts
Expand Up @@ -11,7 +11,7 @@ import {
import type { PartialDeep } from '@inquirer/type';
import chalk from 'chalk';

const numberRegex = /[0-9]+/;
const numberRegex = /\d+/;

type Choice<Value> = {
value: Value;
Expand Down

0 comments on commit b2f13eb

Please sign in to comment.