Skip to content

Commit

Permalink
refactor(Helper methods into new file): Refactored Helper Methods int…
Browse files Browse the repository at this point in the history
…o new File
  • Loading branch information
Daniel Habenicht authored and Daniel Habenicht committed Aug 6, 2018
1 parent 3dd07ae commit 5bfd6c3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
22 changes: 22 additions & 0 deletions projects/ngx-vcard/src/lib/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Encodes string
*/
export function e(value: string | undefined): string {
if (value) {
if (typeof value !== 'string') {
value = '' + value;
}
return value
.replace(/\n/g, '\n')
.replace(/,/g, ',')
.replace(/;/g, ';');
}
return '';
}

/**
* Return new line characters
*/
export function nl(): string {
return '\n';
}
25 changes: 1 addition & 24 deletions projects/ngx-vcard/src/lib/ngx-vcard.formatter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { VCard, Address } from './types/vCard';
import { isArrayOfParameterTypeWorkHome } from './types/parameter/type/WorkHomeString.type';
import {
isPropertyWithParameters,
propertyToVCardString,
BasicPropertyParameters,
isPropertyWithParametersAddressValue
} from './types/parameter/BasicPropertyParameters.type';
import { nl, e } from './helpers';

export class VCardFormatter {
public static getVCardAsBlob(vCard: VCard): Blob {
Expand Down Expand Up @@ -228,29 +228,6 @@ export class VCardFormatter {
}
}

/**
* Encodes string
*/
export function e(value: string | undefined): string {
if (value) {
if (typeof value !== 'string') {
value = '' + value;
}
return value
.replace(/\n/g, '\n')
.replace(/,/g, ',')
.replace(/;/g, ';');
}
return '';
}

/**
* Return new line characters
*/
function nl(): string {
return '\n';
}

/**
* Get formatted photo
* @param photoType Photo type (PHOTO, LOGO)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { e } from '../../ngx-vcard.formatter';
import { Address } from '../vCard';
import { e } from '../../helpers';

/**
* A property can have attributes associated with it.
Expand Down

0 comments on commit 5bfd6c3

Please sign in to comment.