Skip to content

Commit

Permalink
Separates utils and helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
ljdavies committed Apr 27, 2020
1 parent 2469c1f commit 3ea3144
Show file tree
Hide file tree
Showing 20 changed files with 297 additions and 296 deletions.
2 changes: 1 addition & 1 deletion __tests__/constants/anything.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Constants from '../../src/constants';
import { formatInternalExpression } from '../../src/utils';
import { formatInternalExpression } from '../../src/helpers';

/**
* anything constant test
Expand Down
2 changes: 1 addition & 1 deletion __tests__/constants/newline.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Constants from '../../src/constants';
import { formatInternalExpression } from '../../src/utils';
import { formatInternalExpression } from '../../src/helpers';

/**
* newline constant test
Expand Down
2 changes: 1 addition & 1 deletion __tests__/constants/number.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Constants from '../../src/constants';
import { formatInternalExpression } from '../../src/utils';
import { formatInternalExpression } from '../../src/helpers';

/**
* number constant test
Expand Down
2 changes: 1 addition & 1 deletion __tests__/constants/symbol.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Constants from '../../src/constants';
import { formatInternalExpression } from '../../src/utils';
import { formatInternalExpression } from '../../src/helpers';

/**
* symbol constant test
Expand Down
2 changes: 1 addition & 1 deletion __tests__/constants/whitespace.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Constants from '../../src/constants';
import { formatInternalExpression } from '../../src/utils';
import { formatInternalExpression } from '../../src/helpers';

/**
* whitespace constant test
Expand Down
2 changes: 1 addition & 1 deletion __tests__/constants/word.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Constants from '../../src/constants';
import { formatInternalExpression } from '../../src/utils';
import { formatInternalExpression } from '../../src/helpers';

/**
* word constant test
Expand Down
2 changes: 1 addition & 1 deletion __tests__/sequences/anything.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Sequences from '../../src/sequences';
import Constants from '../../src/constants';
import { formatInternalExpression } from '../../src/utils';
import { formatInternalExpression } from '../../src/helpers';

/**
* anything sequence test
Expand Down
2 changes: 1 addition & 1 deletion __tests__/sequences/newlines.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Sequences from '../../src/sequences';
import Constants from '../../src/constants';
import { formatInternalExpression } from '../../src/utils';
import { formatInternalExpression } from '../../src/helpers';

/**
* newlines sequence test
Expand Down
2 changes: 1 addition & 1 deletion __tests__/sequences/numbers.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Sequences from '../../src/sequences';
import Constants from '../../src/constants';
import { formatInternalExpression } from '../../src/utils';
import { formatInternalExpression } from '../../src/helpers';

/**
* numbers sequence test
Expand Down
2 changes: 1 addition & 1 deletion __tests__/sequences/symbols.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Sequences from '../../src/sequences';
import Constants from '../../src/constants';
import { formatInternalExpression } from '../../src/utils';
import { formatInternalExpression } from '../../src/helpers';

/**
* symbols sequence test
Expand Down
2 changes: 1 addition & 1 deletion __tests__/sequences/whitespace.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Sequences from '../../src/sequences';
import Constants from '../../src/constants';
import { formatInternalExpression } from '../../src/utils';
import { formatInternalExpression } from '../../src/helpers';

/**
* whitespace sequence test
Expand Down
5 changes: 2 additions & 3 deletions __tests__/utils/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import Sequences from '../../src/sequences';
import Constants from '../../src/constants';
import { or, anyOf } from '../../src/utils';
import {
escapeString,
matches,
wrapOptionalExpression,
wrapOrExpression,
validateExpression,
or,
validateFlags,
getGroupsByIndex,
anyOf,
} from '../../src/utils';
} from '../../src/helpers';

/**
* beginsWith test
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "exceptional-expressions",
"version": "0.2.1",
"version": "0.2.2",
"description": "An incredible way to build efficient, concise and human readable regular expressions.",
"keywords": [
"typescript",
Expand Down
47 changes: 47 additions & 0 deletions src/assertions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Assert that a value passed equals either null or undefined
*
* @param {any} val
* @param {string} message
*/
export const assertDoesntExist: (val: any, message?: string) => asserts val is null | undefined = (
val: any,
message?: string
): asserts val is null | undefined => {
if (!(val === undefined || val === null)) {
throw new Error(message);
}
};

/**
* Asser that the value passed is not null or undefined
*
* @param {T} val
* @param {string} message
*/
export const assertExists: <T>(val: T, message?: string) => asserts val is NonNullable<T> = <T>(
val: T,
message?: string
): asserts val is NonNullable<T> => {
if (val === undefined || val === null) {
throw new Error(message);
}
};

/**
* Assert that at least one of the values passed is not null or undefined
*
* @param {Array<T>} val
* @param {string} message
*/
export const assertOneExists: <T>(val: Array<T>, message?: string) => asserts val is T[] = <T>(
val: Array<T>,
message?: string
): asserts val is T[] => {
for (const item of val) {
if (item !== undefined && item !== null) {
return;
}
}
throw new Error(message);
};
4 changes: 3 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export default {
number: '~~\\d',
symbol: '~~[\\-!\\$%±§#\\^@&*\\(\\)_+|~=`{}\\[\\]:";\'<>\\?,\\.\\/]',
word: "~~[A-Za-z']+\\b",
anything: '~~.'
anything: '~~.',
lowercaseLetter: '~~(?:a-z)',
uppercaseLetter: '~~(?:A-Z)',
// email:
// '~~(([^<>()[]\\.,;:s@"]+(.[^<>()[]\\.,;:s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))'
};
8 changes: 4 additions & 4 deletions src/exceptional-expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import {
handleOptionalWrapping,
validateExpression,
wrapOrExpression,
assertExists,
assertOneExists,
assertDoesntExist,
validateFlags,
extractMatches,
extractMatchesWithGroup,
IGroupings,
} from './utils';
} from './helpers';

import { assertExists, assertOneExists, assertDoesntExist } from './assertions';

export default class ExpressionBuilder {
private beginsWithExpression: string | null = null;
private internal: Array<string> = [];
Expand Down
Loading

0 comments on commit 3ea3144

Please sign in to comment.