1.3.8 • Published 2 years ago

@edenred-falcon/shared v1.3.8

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

@edenred-falcon/shared

A library that implements business validation rules of Edenred's Falcon project.

Install the NPM module

To install this package, please run the following command-line within a terminal inside your project.

npm install @edenred-falcon/shared

Using the library

Email validation

Method NameDescription
isEmailPatternValidCheck the email format.

Printed Card validation rules

Method NameDescription
isCardPrintedCompanyLengthValidCheck that the length of the company name is less or equal to the maximum number of characters accepted by the printer.
isCardPrintedCompanyPatternValidCheck that the company name contain only characters accepted by the printer.
isCardPrintedLicensePlatePatternValidCheck that license plate has valid format.
isCardPrintedNameLengthValidCheck that the length of the driver short name is less or equal to the maximum number of characters accepted by the printer.
isCardPrintedNamePatternValidCheck that the driver short name contain only characters accepted by the printer.

Examples of Use

const companyName = "New Company Ltd.";
const isValid = isCardPrintedCompanyLengthValid(companyName);

if (isValid) {
    // The company name has a valid length
} else {
    // ERROR: The company name exceed the maximum length
}

Validation patterns

Validate Pattern

To validate an input string using validation patterns, you have to use helper function validatePattern. The validatePattern(input, patternName, countryCode?) function get three parameters input (the input string to validate), patternName (see the list bellow) and countryCode (optional).

The country code parameter make the pattern more restrictive regarding the country specific rules.

Get Pattern To get validation pattern, you have to use helper function getPattern. The getPattern(patternName, countryCode?) function get two parameters patternName (see the list bellow) and countryCode (optional).

The country code parameter make the pattern more restrictive regarding the country specific rules.

Available patterns

Pattern NameDescription
alphanumericAllow alphabetic and numeric values.
bicValidate BIC format.
cardPinAllow a suite of 4 digits expect 0000.
companyNumberMust start by HR followed by alpha, numeric, undescore and whitespace characters.
emailValidate email format.
ibanValidate IBAN format.
latin1Must be latin-1 characters.
lettersAndNumbersMust contain a mix of letters and numbers.
lowerAndUpperCaseMust contain a mix of lowercase and uppercase characters.
numbersOnlyMust contain only numbers.
numbersSlashsAndHyphensMust contain only numbers, slashs and hypens.
phoneNumberValidate phone number format.
plateNumberValidate vehicle plate number format.
specialCharactersMust contain special characters.
taxIdValidate TAX ID format.
vatValidate VAT format.

Examples of Use

let ibanPattern: RegExp;

// Get a generic regex pattern to validate iban (permissive mode)
ibanPattern = getPattern('iban');

// Or, get a country specific regex pattern to validate iban (restrictive mode)
ibanPattern = getPattern('iban', 'de');

// Then use the regular expression as in vanilla JavaScript
const isIbanValid: boolean = ibanPattern.test('DE021894367439832');

Angular Modules

Internationalization (i18n)

This module relies on the NgxTranslate package

Examples of Use

Import the TranslateModule

import { TranslateModule } from '@edenred-falcon/shared/angular/i18n';

@NgModule({
    imports: [
        TranslateModule.forRoot({
            defaultLanguage: 'en',
            supportedLocales: ['en-EN', 'de-DE']
        }),
    ]
})
export class AppModule {
}
import { TranslateModule } from '@edenred-falcon/shared/angular/i18n';

@NgModule({
    imports: [
        TranslateModule
    ]
})
export class FeatureModule {
}

Use it in your templates:

{{ 'greetings' | translate }}
{{ 'greetings.with.number.of.cards' | translate: { number_of_cards: 3 } }}

Your translations will be loaded from /assets/i18n/lang.json

LocaleService

Method NameDescription
getLocale$Return the current locale as an observable
getLocaleReturn the current locale
getLang$Return the current lang as observable
getLangReturn the current lang
setLocaleSet a new locale (format: xx-XX).Will emit a new value from the getLocale$ and getLang$ observables.Will update the translations in your application.
getSupportedLocalesReturn the list of supported locales

TranslateService

Method NameDescription
get$Gets the translated value of a key (or an array of keys) or the key if the value was not found
stream$Returns a stream of translated values of a key (or an array of keys) or the key if the value was not found. Without any onLangChange events this returns the same value as get but it will also emit new values whenever the used language changes.
instantGets the instant translated value of a key (or an array of keys). /!\ This method is synchronous and the default file loader is asynchronous. You are responsible for knowing when your translations have been loaded and it is safe to use this method. If you are not sure then you should use the get method instead.
setDefaultLangSets the default language to use as a fallback

POEditor CLI

Import your POEditor translations into your project

Generate the configuration file

npx -p @edenred-falcon/shared poeditor init .

Run import

npx -p @edenred-falcon/shared poeditor import ./poeditor.config.json

Help

npx -p @edenred-falcon/shared poeditor <command> --help
1.3.7

2 years ago

1.3.6

2 years ago

1.3.5

2 years ago

1.3.4

2 years ago

1.3.8

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.5

2 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.0.5

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.4

3 years ago

0.0.1

3 years ago