@typeolymp/utils 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@typeolymp/utils",
3
+ "version": "0.1.0",
4
+ "author": "TypeOlymp",
5
+ "scripts": {
6
+ "build": "tsc -p .",
7
+ "refresh": "rm -rf ./node_modules ./package-lock.json && npm install",
8
+ "prepublishOnly": "npm run build"
9
+ },
10
+ "publishConfig": {
11
+ "access": "restricted"
12
+ },
13
+ "devDependencies": {
14
+ "@types/node": "^18.16.0",
15
+ "ts-node": "^10.9.1",
16
+ "tslint": "^6.1.3",
17
+ "typescript": "^5.0.4"
18
+ }
19
+ }
@@ -0,0 +1,11 @@
1
+ export enum Color {
2
+ RED = "red",
3
+ YELLOW = "yellow",
4
+ BLUE = "blue",
5
+ GREEN = "green",
6
+ PURPLE = "purple",
7
+ PINK = "pink",
8
+ ORANGE = "orange",
9
+ DARK_GRAY = "darkGray",
10
+ LIGHT_GRAY = "lightGray",
11
+ }
@@ -0,0 +1,4 @@
1
+ export enum Country {
2
+ NL = "Nederland",
3
+ BE = "België",
4
+ }
@@ -0,0 +1,4 @@
1
+ export enum CourseTranslation {
2
+ NL_NL = "nl-NL",
3
+ // EN_GB = "en-GB",
4
+ }
@@ -0,0 +1,9 @@
1
+ export enum KeyboardLayout {
2
+ QWERTY_NL = "qwerty-nl",
3
+ // QWERTY_UK = "qwerty-uk",
4
+ // QWERTY_US = "qwerty-us",
5
+ // QWERTY_TR = "qwerty-tr",
6
+ AZERTY_BE = "azerty-be",
7
+ // AZERTY_FR = "azerty-fr",
8
+ // QWERTZ_DE = "qwertz-de",
9
+ }
@@ -0,0 +1,8 @@
1
+ export enum Locale {
2
+ NL_NL = "nl-NL",
3
+ NL_BE = "nl-BE",
4
+ // EN_GB = "en-GB",
5
+ // FR_FR = "fr-FR",
6
+ // FR_BE = "fr-BE",
7
+ // DE_DE = "de-DE",
8
+ }
@@ -0,0 +1,5 @@
1
+ export enum Medal {
2
+ GOLD = "gold",
3
+ SILVER = "silver",
4
+ BRONZE = "bronze",
5
+ }
@@ -0,0 +1,4 @@
1
+ export enum Plan {
2
+ HOBBY = "hobby",
3
+ PROFESSIONAL = "professional",
4
+ }
@@ -0,0 +1,11 @@
1
+ export enum TextTopic {
2
+ SPORT = "sport",
3
+ MUSIC = "music",
4
+ TECHNIC = "technic",
5
+ MOVIES = "movies",
6
+ NATURE = "nature",
7
+ HISTORY = "history",
8
+ ART = "art",
9
+ FASHION = "fashion",
10
+ OTHER = "other",
11
+ }
@@ -0,0 +1,8 @@
1
+ export * from "./Color";
2
+ export * from "./Country";
3
+ export * from "./CourseTranslation";
4
+ export * from "./KeyboardLayout";
5
+ export * from "./Locale";
6
+ export * from "./Plan";
7
+ export * from "./TextTopic";
8
+ export * from "./Medal"
@@ -0,0 +1,5 @@
1
+ export const hasCapitalLetter = (input: string): boolean => {
2
+ const regex = new RegExp(/[A-Z]/g);
3
+
4
+ return regex.test(input);
5
+ };
@@ -0,0 +1,5 @@
1
+ export const hasNumber = (input: string): boolean => {
2
+ const regex = new RegExp(/\d/g);
3
+
4
+ return regex.test(input);
5
+ };
@@ -0,0 +1,7 @@
1
+ export const hasSpecialCharacter = (input: string): boolean => {
2
+ const regex = new RegExp(
3
+ /`|~|!|"|-|_|@|#|\$|%|\^|&|\*|\(|\)|\+|=|\[|\{|\]|\}|\||\\|'|<|,|\.|>|\?|\/|""|;|:|\s/g
4
+ );
5
+
6
+ return regex.test(input);
7
+ };
@@ -0,0 +1,6 @@
1
+ export * from "./hasCapitalLetter";
2
+ export * from "./hasNumber";
3
+ export * from "./hasSpecialCharacter";
4
+ export * from "./isValidEmail";
5
+ export * from "./isValidUsername";
6
+ export * from "./isStrongPassword";
@@ -0,0 +1,7 @@
1
+ import { hasNumber, hasSpecialCharacter, hasCapitalLetter } from ".";
2
+
3
+ export const isStrongPassword = (password: string): boolean =>
4
+ password.length >= 8 &&
5
+ hasNumber(password) &&
6
+ hasSpecialCharacter(password) &&
7
+ hasCapitalLetter(password);
@@ -0,0 +1,7 @@
1
+ export const isValidEmail = (email: string): boolean => {
2
+ const regex = new RegExp(
3
+ /^(([^<>()[\]\\.,;:\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,}))$/
4
+ );
5
+
6
+ return regex.test(email);
7
+ };
@@ -0,0 +1,7 @@
1
+ import { isValidEmail } from "./isValidEmail";
2
+
3
+ export const isValidUsername = (username: string): boolean =>
4
+ username.length >= 5 &&
5
+ username.length <= 15 &&
6
+ username.indexOf(" ") < 0 &&
7
+ !isValidEmail(username);
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * as enums from "./enums";
2
+ export * as expressions from "./expressions";
3
+ export * as parsers from "./parsers";
@@ -0,0 +1,10 @@
1
+ import { Locale, Country } from "../enums";
2
+
3
+ export const getCountryByLocale = (locale: Locale) => {
4
+ const countries: { [key in Locale]: Country } = {
5
+ "nl-NL": Country.NL,
6
+ "nl-BE": Country.BE,
7
+ };
8
+
9
+ return countries[locale];
10
+ };
@@ -0,0 +1,15 @@
1
+ import { Locale, CourseTranslation } from "../enums";
2
+
3
+ export const getCourseTranslationByLocale = (locale: Locale) => {
4
+ const courseTranslations: { [key in Locale]: CourseTranslation } = {
5
+ "nl-NL": CourseTranslation.NL_NL,
6
+ "nl-BE": CourseTranslation.NL_NL,
7
+ // "en-GB": KeyboardLayout.QWERTY_UK,
8
+ // "en-US": KeyboardLayout.QWERTY_US,
9
+ // "fr-BE": KeyboardLayout.AZERTY_FR,
10
+ // "fr-FR": KeyboardLayout.AZERTY_FR,
11
+ // "de-DE": KeyboardLayout.QWERTZ_DE,
12
+ };
13
+
14
+ return courseTranslations[locale];
15
+ };
@@ -0,0 +1,15 @@
1
+ import { Locale, KeyboardLayout } from "../enums";
2
+
3
+ export const getKeyboardLayoutByLocale = (locale: Locale) => {
4
+ const keyboardLayouts: { [key in Locale]: KeyboardLayout } = {
5
+ "nl-NL": KeyboardLayout.QWERTY_NL,
6
+ "nl-BE": KeyboardLayout.AZERTY_BE,
7
+ // "en-GB": KeyboardLayout.QWERTY_UK,
8
+ // "en-US": KeyboardLayout.QWERTY_US,
9
+ // "fr-BE": KeyboardLayout.AZERTY_FR,
10
+ // "fr-FR": KeyboardLayout.AZERTY_FR,
11
+ // "de-DE": KeyboardLayout.QWERTZ_DE,
12
+ };
13
+
14
+ return keyboardLayouts[locale];
15
+ };
@@ -0,0 +1,3 @@
1
+ import { Locale } from "../enums";
2
+
3
+ export const getLanguageCodeByLocale = (locale: Locale) => locale.split("-")[0];
@@ -0,0 +1,15 @@
1
+ import { Locale } from "../enums";
2
+
3
+ export const getNativeLanguageByLocale = (locale: Locale) => {
4
+ const nativeLanguages: { [key in Locale]: string } = {
5
+ "nl-NL": "Nederlands",
6
+ "nl-BE": "Nederlands (BE)",
7
+ // "en-GB": "English (UK)",
8
+ // "en-US": "English (US)",
9
+ // "fr-BE": "Français (BE)",
10
+ // "fr-FR": "Français",
11
+ // "de-DE": "Deutsch",
12
+ };
13
+
14
+ return nativeLanguages[locale];
15
+ };
@@ -0,0 +1,5 @@
1
+ export * from "./getCountryByLocale";
2
+ export * from "./getCourseTranslationByLocale";
3
+ export * from "./getKeyboardLayoutByLocale";
4
+ export * from "./getLanguageCodeByLocale";
5
+ export * from "./getNativeLanguageByLocale";
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "src",
4
+ "sourceMap": true,
5
+ "target": "ES5",
6
+ "module": "CommonJS",
7
+ "lib": ["ES2019", "DOM"],
8
+ "declaration": true,
9
+ "outDir": "build",
10
+ "strict": true,
11
+ "types": ["node"],
12
+ "esModuleInterop": true,
13
+ "resolveJsonModule": true
14
+ }
15
+ }