Skip to content

Commit

Permalink
Merge 54466ef into 7b3c8ce
Browse files Browse the repository at this point in the history
  • Loading branch information
Keimeno authored Aug 30, 2020
2 parents 7b3c8ce + 54466ef commit 291c398
Show file tree
Hide file tree
Showing 82 changed files with 280 additions and 124 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ jobs:
strategy:
matrix:
deno:
- { version: v1.2.0, name: v1.2.0 }
- { version: v0.34.0, name: v0.34.0 }
- { version: v1.0.0, name: v1.0.0 }
- { version: vx, name: latest }
name: Deno ${{ matrix.deno.name }} testing
steps:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
package-lock.json
node_modules
node_modules
.vscode
2 changes: 1 addition & 1 deletion deps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export {
assertEquals,
assertThrows,
} from 'https://deno.land/std@0.61.0/testing/asserts.ts';
} from 'https://deno.land/std@0.34.0/testing/asserts.ts';
2 changes: 1 addition & 1 deletion egg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "segno",
"description": "segno (Segnosaurus). Validation library for Deno. Enforcing a high security standard.",
"version": "1.0.0",
"version": "1.1.0",
"unlisted": false,
"stable": true,
"entry": "./mod.ts",
Expand Down
14 changes: 12 additions & 2 deletions lib/helpers/alpha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const alpha = {
'ku-IQ': /^[ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i,
ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
he: /^[א-ת]+$/,
'fa-IR': /^['آابپتثجچهخدذرزژسشصضطظعغفقکگلمنوهی']+$/i,
fa: /^['آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی']+$/i,
};

export const alphanumeric = {
Expand Down Expand Up @@ -57,12 +57,13 @@ export const alphanumeric = {
'vi-VN': /^[0-9A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i,
ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
he: /^[0-9א-ת]+$/,
'fa-IR': /^['0-9آابپتثجچهخدذرزژسشصضطظعغفقکگلمنوهی۱۲۳۴۵۶۷۸۹۰']+$/i,
fa: /^['0-9آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی۱۲۳۴۵۶۷۸۹۰']+$/i,
};

export const decimal = {
'en-US': '.',
ar: '٫',
fa: '٫',
};

export const englishLocales = ['AU', 'GB', 'HK', 'IN', 'NZ', 'ZA', 'ZM'];
Expand Down Expand Up @@ -103,6 +104,15 @@ for (let locale, i = 0; i < arabicLocales.length; i++) {
(decimal as any)[locale] = decimal.ar;
}

export const farsiLocales = ['IR', 'AF'];

for (let locale, i = 0; i < farsiLocales.length; i++) {
locale = `fa-${farsiLocales[i]}`;
(alpha as any)[locale] = alpha.fa;
(alphanumeric as any)[locale] = alphanumeric.fa;
(decimal as any)[locale] = decimal.fa;
}

// Source: https://en.wikipedia.org/wiki/Decimal_mark
export const dotDecimal = ['ar-EG', 'ar-LB', 'ar-LY'];
export const commaDecimal = [
Expand Down
4 changes: 2 additions & 2 deletions lib/validations/isAfter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { toDate } from '../helpers/toDate.ts';

export const isAfter = (str: string, date = String(new Date())) => {
Expand Down
4 changes: 2 additions & 2 deletions lib/validations/isAlpha.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { alpha } from '../helpers/alpha.ts';

export const isAlpha = (str: string, locale = 'en-US') => {
Expand Down
4 changes: 2 additions & 2 deletions lib/validations/isAlphanumeric.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { alphanumeric } from '../helpers/alpha.ts';

export const isAlphanumeric = (str: string, locale = 'en-US') => {
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isAscii.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isBIC.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isBase32.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isBase64.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/validations/isBefore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { toDate } from '../helpers/toDate.ts';

export const isBefore = (str: string, date = String(new Date())) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isBoolean.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

export const isBoolean = (str: string) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isBtcAddress.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

// supports Bech32 addresses
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isByteLength.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

type ByteLengthOptions = {
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isCreditCard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isCurrency.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

type CurrencyOptions = {
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isDataURI.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/validations/isDecimal.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { decimal } from '../helpers/alpha.ts';
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { includes } from '../helpers/includes.ts';

type DecimalOptions = {
Expand Down
4 changes: 2 additions & 2 deletions lib/validations/isDivisibleBy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { toFloat } from '../helpers/toFloat.ts';

export const isDivisibleBy = (str: string, num: string) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isEAN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Reference: https://en.wikipedia.org/wiki/International_Article_Number
*/

// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/validations/isEmail.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { isByteLength } from './isByteLength.ts';
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { isFQDN } from './isFQDN.ts';
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { isIP } from './isIP.ts';

type EmailOptions = {
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isEmpty.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

type EmptyOptions = {
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isEthereumAddress.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isFQDN.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

type FQDNOptions = {
Expand Down
4 changes: 2 additions & 2 deletions lib/validations/isFloat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { decimal } from '../helpers/alpha.ts';

type FloatOptions = {
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isFullWidth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

export const fullWidth = /[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isHalfWidth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

export const halfWidth = /[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isHash.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

type Algorithm =
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isHexColor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isHexadecimal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isHsl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

/**
Expand Down
10 changes: 5 additions & 5 deletions lib/validations/isIBAN.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

/**
Expand Down Expand Up @@ -135,17 +135,17 @@ const hasValidIbanChecksum = (str: string) => {
const rearranged = strippedStr.slice(4) + strippedStr.slice(0, 4);
const alphaCapsReplacedWithDigits = rearranged.replace(
/[A-Z]/g,
// @ts-ignore
// @ts-ignore allowing typedoc to build
(char) => char.charCodeAt(0) - 55
);

// @ts-ignore
// @ts-ignore allowing typedoc to build
const remainder = alphaCapsReplacedWithDigits
.match(/\d{1,7}/g)
// @ts-ignore
// @ts-ignore allowing typedoc to build
.reduce((acc, value) => Number(acc + value) % 97, '');

// @ts-ignore
// @ts-ignore allowing typedoc to build
return remainder === 1;
};

Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isIMEI.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isIP.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/validations/isIPRange.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { isIP } from './isIP.ts';

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isISBN.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/validations/isISIN.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

/**
Expand All @@ -13,7 +13,7 @@ export const isISIN = (str: string) => {
}

const checksumStr = str.replace(/[A-Z]/g, (character) =>
// @ts-ignore
// @ts-ignore allowing typedoc to build
parseInt(character, 36)
);

Expand Down
4 changes: 2 additions & 2 deletions lib/validations/isISO31661Alpha2.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { includes } from '../helpers/includes.ts';

// from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
Expand Down
4 changes: 2 additions & 2 deletions lib/validations/isISO31661Alpha3.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { includes } from '../helpers/includes.ts';

// from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
Expand Down
4 changes: 2 additions & 2 deletions lib/validations/isISO8601.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

// from http://goo.gl/0ejHHW
Expand All @@ -25,7 +25,7 @@ const isValidDate = (str: string) => {
return oDay <= 365;
}

// @ts-ignore
// @ts-ignore allowing typedoc to build
const match = str.match(/(\d{4})-?(\d{0,2})-?(\d*)/).map(Number);
const year = match[1];
const month = match[2];
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isISRC.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

// see http://isrc.ifpi.org/en/isrc-standard/code-syntax
Expand Down
2 changes: 1 addition & 1 deletion lib/validations/isISSN.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';

/**
Expand Down
Loading

0 comments on commit 291c398

Please sign in to comment.