@edenred-falcon/shared

v1.3.8

Published

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

Downloads

200

Readme

@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 Name | Description | |--------|--------| | isEmailPatternValid | Check the email format. |

Printed Card validation rules

| Method Name | Description | |--------|--------| | isCardPrintedCompanyLengthValid | Check that the length of the company name is less or equal to the maximum number of characters accepted by the printer. | | isCardPrintedCompanyPatternValid | Check that the company name contain only characters accepted by the printer. | | isCardPrintedLicensePlatePatternValid | Check that license plate has valid format. | | isCardPrintedNameLengthValid | Check that the length of the driver short name is less or equal to the maximum number of characters accepted by the printer. | | isCardPrintedNamePatternValid | Check 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 Name | Description | |---|---| | alphanumeric | Allow alphabetic and numeric values. | | bic | Validate BIC format. | | cardPin | Allow a suite of 4 digits expect 0000. | | companyNumber | Must start by HR followed by alpha, numeric, undescore and whitespace characters. | | email | Validate email format. | | iban | Validate IBAN format. | | latin1 | Must be latin-1 characters. | | lettersAndNumbers | Must contain a mix of letters and numbers. | | lowerAndUpperCase | Must contain a mix of lowercase and uppercase characters. | | numbersOnly | Must contain only numbers. | | numbersSlashsAndHyphens | Must contain only numbers, slashs and hypens. | | phoneNumber | Validate phone number format. | | plateNumber | Validate vehicle plate number format. | | specialCharacters | Must contain special characters. | | taxId | Validate TAX ID format. | | vat | Validate 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 Name | Description | |--------|--------| | getLocale$ | Return the current locale as an observable | | getLocale | Return the current locale | getLang$ | Return the current lang as observable | getLang | Return the current lang | setLocale | Set a new locale (format: xx-XX).Will emit a new value from the getLocale$ and getLang$ observables.Will update the translations in your application. | | getSupportedLocales | Return the list of supported locales |

TranslateService

| Method Name | Description | |--------|--------| | 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. | instant | Gets 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. | setDefaultLang | Sets 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