Skip to content

Commit

Permalink
Remove asserting string from issue Jinglong7#11
Browse files Browse the repository at this point in the history
  • Loading branch information
haylinmoore committed Oct 11, 2020
1 parent 41cf747 commit 331165d
Show file tree
Hide file tree
Showing 60 changed files with 7 additions and 239 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
3 changes: 0 additions & 3 deletions src/libs/isAfter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';
// @ts-ignore allowing typedoc to build
import toDate from '../utils/toDate.ts';

export const isAfter = (str: string, date = String(new Date())) => {
assertString(str);
const comparison = toDate(date);
const original = toDate(str);
return !!(original && comparison && original > comparison);
Expand Down
3 changes: 0 additions & 3 deletions src/libs/isAlpha.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';
// @ts-ignore allowing typedoc to build
import { alpha } from '../utils/alpha.ts';

export const isAlpha = (str: string, locale = 'en-US') => {
assertString(str);
if (locale in alpha) {
return (alpha as any)[locale].test(str);
}
Expand Down
4 changes: 1 addition & 3 deletions src/libs/isAlphanumeric.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

// @ts-ignore allowing typedoc to build
import { alphanumeric } from '../utils/alpha.ts';

export const isAlphanumeric = (str: string, locale = 'en-US') => {
assertString(str);
if (locale in alphanumeric) {
return (alphanumeric as any)[locale].test(str);
}
Expand Down
4 changes: 0 additions & 4 deletions src/libs/isAscii.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

const ascii = /^[\x00-\x7F]+$/;

export const isAscii = (str: string) => {
assertString(str);
return ascii.test(str);
};
4 changes: 0 additions & 4 deletions src/libs/isBIC.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

const ascii = /^[\x00-\x7F]+$/;

export const isAscii = (str: string) => {
assertString(str);
return ascii.test(str);
};
4 changes: 0 additions & 4 deletions src/libs/isBase32.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

const base32 = /^[A-Z2-7]+=*$/;

export const isBase32 = (str: string) => {
assertString(str);
const len = str.length;
if (len > 0 && len % 8 === 0 && base32.test(str)) {
return true;
Expand Down
4 changes: 0 additions & 4 deletions src/libs/isBase64.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

const notBase64 = /[^A-Z0-9+\/=]/i;
const urlSafeBase64 = /^[A-Z0-9_\-]+$/i;

Expand All @@ -13,7 +10,6 @@ const defaultBase64Options: Base64Options = {
};

export const isBase64 = (str: string, options?: Base64Options) => {
assertString(str);
options = {
...defaultBase64Options,
...options,
Expand Down
3 changes: 0 additions & 3 deletions src/libs/isBefore.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';
// @ts-ignore allowing typedoc to build
import toDate from '../utils/toDate.ts';

export const isBefore = (str: string, date = String(new Date())) => {
assertString(str);
const comparison = toDate(date);
const original = toDate(str);
return !!(original && comparison && original < comparison);
Expand Down
4 changes: 0 additions & 4 deletions src/libs/isBoolean.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

export const isBoolean = (str: string) => {
assertString(str);
return ['true', 'false', '1', '0'].indexOf(str) >= 0;
};
4 changes: 0 additions & 4 deletions src/libs/isBtcAddress.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

// supports Bech32 addresses
const btc = /^(bc1|[13])[a-zA-HJ-NP-Z0-9]{25,39}$/;

export const isBtcAddress = (str: string) => {
assertString(str);
return btc.test(str);
};
4 changes: 0 additions & 4 deletions src/libs/isByteLength.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

type ByteLengthOptions = {
min?: number;
max?: number;
Expand All @@ -11,7 +8,6 @@ const defaultByteLengthOptions: ByteLengthOptions = {
};

export const isByteLength = (str: string, options?: ByteLengthOptions) => {
assertString(str);
options = { ...defaultByteLengthOptions, ...options };
let { min, max } = options;
min = min || 0;
Expand Down
4 changes: 0 additions & 4 deletions src/libs/isCreditCard.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

const creditCard = /^(?:4[0-9]{12}(?:[0-9]{3,6})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12,15}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14})$/;

export const isCreditCard = (str: string) => {
assertString(str);
const sanitized = str.replace(/[- ]+/g, '');
if (!creditCard.test(sanitized)) {
return false;
Expand Down
4 changes: 0 additions & 4 deletions src/libs/isCurrency.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

type CurrencyOptions = {
symbol?: string;
requireSymbol?: boolean;
Expand Down Expand Up @@ -103,7 +100,6 @@ const defaultCurrencyOptions: CurrencyOptions = {
};

export const isCurrency = (str: string, options?: CurrencyOptions) => {
assertString(str);
options = {
...defaultCurrencyOptions,
...options,
Expand Down
4 changes: 0 additions & 4 deletions src/libs/isDataURI.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

const validMediaType = /^[a-z]+\/[a-z0-9\-\+]+$/i;
const validAttribute = /^[a-z\-]+=[a-z0-9\-]+$/i;
const validData = /^[a-z0-9!\$&'\(\)\*\+,;=\-\._~:@\/\?%\s]*$/i;

export const isDataURI = (str: string) => {
assertString(str);
let data = str.split(',');
if (data.length < 2) {
return false;
Expand Down
3 changes: 0 additions & 3 deletions src/libs/isDecimal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';
// @ts-ignore allowing typedoc to build
import { decimal } from '../utils/alpha.ts';
// @ts-ignore allowing typedoc to build
import includes from '../utils/includes.ts';
Expand Down Expand Up @@ -29,7 +27,6 @@ const defaultDecimalOptions = {
const blacklist = ['', '-', '+'];

export const isDecimal = (str: string, options?: DecimalOptions) => {
assertString(str);
options = {
...defaultDecimalOptions,
...options,
Expand Down
3 changes: 0 additions & 3 deletions src/libs/isDivisibleBy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';
// @ts-ignore allowing typedoc to build
import toFloat from '../utils/toFloat.ts';

export const isDivisibleBy = (str: string, num: string) => {
assertString(str);
return toFloat(str) % parseInt(num, 10) === 0;
};
4 changes: 0 additions & 4 deletions src/libs/isEAN.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

/**
* The most commonly used EAN standard is
* the thirteen-digit EAN-13, while the
Expand Down Expand Up @@ -69,7 +66,6 @@ const calculateCheckDigit = (ean: string) => {
* @return {boolean}
*/
export const isEAN = (str: string) => {
assertString(str);
const actualCheckDigit = Number(str.slice(-1));

return (
Expand Down
3 changes: 0 additions & 3 deletions src/libs/isEmail.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';
// @ts-ignore allowing typedoc to build
import { isByteLength } from './isByteLength.ts';
// @ts-ignore allowing typedoc to build
import { isFQDN } from './isFQDN.ts';
Expand Down Expand Up @@ -84,7 +82,6 @@ export const validateDisplayName = (displayName: string) => {
* ```
*/
export const isEmail = (email: string, options?: EmailOptions) => {
assertString(email);
options = {
...defaultEmailOptions,
...options
Expand Down
4 changes: 0 additions & 4 deletions src/libs/isEmpty.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

type EmptyOptions = {
ignoreWhitespace?: boolean,
};
Expand All @@ -10,7 +7,6 @@ const defaultEmptyOptions: EmptyOptions = {
};

export const isEmpty = (str: string, options?: EmptyOptions) => {
assertString(str);
options = {
...defaultEmptyOptions,
...options,
Expand Down
4 changes: 0 additions & 4 deletions src/libs/isEthereumAddress.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

const eth = /^(0x)[0-9a-f]{40}$/i;

export const isEthereumAddress = (str: string) => {
assertString(str);
return eth.test(str);
};
4 changes: 0 additions & 4 deletions src/libs/isFQDN.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

type FQDNOptions = {
requireTLD?: boolean;
allowUnderscores?: boolean;
Expand All @@ -14,7 +11,6 @@ const defaultFQDNOptions: FQDNOptions = {
};

export const isFQDN = (str: string, options?: FQDNOptions) => {
assertString(str);
options = {
...defaultFQDNOptions,
...options
Expand Down
3 changes: 0 additions & 3 deletions src/libs/isFloat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';
// @ts-ignore allowing typedoc to build
import { decimal } from '../utils/alpha.ts';

type FloatOptions = {
Expand All @@ -12,7 +10,6 @@ type FloatOptions = {
};

export const isFloat = (str: string, options?: FloatOptions) => {
assertString(str);
options = options || {};
const float = new RegExp(
`^(?:[-+])?(?:[0-9]+)?(?:\\${
Expand Down
4 changes: 0 additions & 4 deletions src/libs/isFullWidth.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

export const fullWidth = /[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;

export const isFullWidth = (str: string) => {
assertString(str);
return fullWidth.test(str);
};
4 changes: 0 additions & 4 deletions src/libs/isHalfWidth.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

export const halfWidth = /[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;

export const isHalfWidth = (str: string) => {
assertString(str);
return halfWidth.test(str);
};
4 changes: 0 additions & 4 deletions src/libs/isHash.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

type Algorithm =
| 'md5'
| 'md4'
Expand Down Expand Up @@ -33,7 +30,6 @@ const lengths = {
};

export const isHash = (str: string, algorithm: Algorithm) => {
assertString(str);
const hash = new RegExp(`^[a-fA-F0-9]{${lengths[algorithm]}}$`);
return hash.test(str);
};
8 changes: 2 additions & 6 deletions src/libs/isHexColor.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

const hexcolor = /^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;
const hexColor = /^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;

export const isHexColor = (str: string) => {
assertString(str);
return hexcolor.test(str);
return hexColor.test(str);
};
4 changes: 0 additions & 4 deletions src/libs/isHexadecimal.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

const hexadecimal = /^(0x|0h)?[0-9A-F]+$/i;

export const isHexadecimal = (str: string) => {
assertString(str);
return hexadecimal.test(str);
};
10 changes: 3 additions & 7 deletions src/libs/isHsl.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

const hslcomma = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i;
const hslspace = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i;
const hslComma = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i;
const hslSpace = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i;

export const isHSL = (str: string) => {
assertString(str);
return hslcomma.test(str) || hslspace.test(str);
return hslComma.test(str) || hslSpace.test(str);
};
4 changes: 0 additions & 4 deletions src/libs/isIBAN.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

/**
* List of country codes with
* corresponding IBAN regular expression
Expand Down Expand Up @@ -141,6 +138,5 @@ const hasValidIbanChecksum = (str: string) => {
};

export const isIBAN = (str: string) => {
assertString(str);
return hasValidIbanFormat(str) && hasValidIbanChecksum(str);
};
5 changes: 0 additions & 5 deletions src/libs/isIMEI.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

let imeiRegexWithoutHypens = /^[0-9]{15}$/;
let imeiRegexWithHypens = /^\d{2}-\d{6}-\d{6}-\d{1}$/;

Expand All @@ -9,11 +6,9 @@ type IMEIOptions = {
};

export const isIMEI = (str: string, options?: IMEIOptions) => {
assertString(str);
options = options || {};

// default regex for checking imei is the one without hyphens

let imeiRegex = imeiRegexWithoutHypens;

if (options.allowHyphens) {
Expand Down
4 changes: 0 additions & 4 deletions src/libs/isIP.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// @ts-ignore allowing typedoc to build
import assertString from '../utils/assertString.ts';

const ipv4Maybe = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
const ipv6Block = /^[0-9A-F]{1,4}$/i;

export const isIP = (str: string, ipVersion?: string | number): boolean => {
assertString(str);
const version = ipVersion ? String(ipVersion) : '';

if (!version) {
Expand Down
Loading

0 comments on commit 331165d

Please sign in to comment.