Skip to content

Commit 78956d7

Browse files
committed
migrate helpers index to ts and AvatarHelper
1 parent 74a0dcb commit 78956d7

File tree

11 files changed

+22
-97
lines changed

11 files changed

+22
-97
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export declare function getAvatarColors(): string[];
2+
export declare function getColorById(id: string, avatarColors?: string[]): string;
3+
export declare function getInitials(name: string): string;
4+
export declare function isGravatarUrl(url: string): any;
5+
export declare function isBlankGravatarUrl(url: string): boolean;
6+
export declare function patchGravatarUrl(gravatarUrl: string): any;

generatedTypes/helpers/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as AvatarHelper from './AvatarHelper';
2+
export { default as Constants } from './Constants';
3+
export { AvatarHelper };

generatedTypes/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export {
5555
forwardRef,
5656
AvatarHelper,
5757
Constants,
58-
DocsGenerator,
5958
LogService,
6059
LoaderScreen,
6160
Modal,

src/commons/baseComponent.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import React from 'react';
33
import {StyleSheet} from 'react-native';
44
import _ from 'lodash';
55
import {Colors} from '../style';
6-
import {DocsGenerator} from '../helpers';
76
import * as Modifiers from './modifiers';
87

98
export default function baseComponent(usePure) {
@@ -35,7 +34,7 @@ export default function baseComponent(usePure) {
3534

3635
// TODO: stop using this and remove it
3736
getSnippet() {
38-
return DocsGenerator.generateSnippet(DocsGenerator.extractComponentInfo(this));
37+
return null;
3938
}
4039

4140
generateStyles() {

src/helpers/AvatarHelper.js renamed to src/helpers/AvatarHelper.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import _ from 'lodash';
2+
// @ts-ignore
23
import URL from 'url-parse';
34
import Colors from '../style/colors';
45

5-
function hashStringToNumber(str) {
6+
function hashStringToNumber(str: string) {
67
let hash = 5381;
78
for (let i = 0; i < str.length; i++) {
89
const char = str.charCodeAt(i);
@@ -16,7 +17,7 @@ export function getAvatarColors() {
1617
Colors.orange20, Colors.red20, Colors.purple20, Colors.violet20];
1718
}
1819

19-
export function getColorById(id, avatarColors = getAvatarColors()) {
20+
export function getColorById(id: string, avatarColors = getAvatarColors()) {
2021
if (!id) {
2122
return avatarColors[0];
2223
}
@@ -26,7 +27,7 @@ export function getColorById(id, avatarColors = getAvatarColors()) {
2627
return avatarColors[colorIndex];
2728
}
2829

29-
export function getInitials(name) {
30+
export function getInitials(name: string) {
3031
let initials = '';
3132
if (name && _.isString(name)) {
3233
const nameSplitted = _.chain(name)
@@ -42,16 +43,16 @@ export function getInitials(name) {
4243
return _.toUpper(initials);
4344
}
4445

45-
export function isGravatarUrl(url) {
46+
export function isGravatarUrl(url: string) {
4647
const {hostname, pathname} = new URL(url);
4748
return _.split(hostname, '.').includes('gravatar') && pathname.startsWith('/avatar/');
4849
}
4950

50-
export function isBlankGravatarUrl(url) {
51+
export function isBlankGravatarUrl(url: string) {
5152
return isGravatarUrl(url) && _.endsWith(url, '?d=blank');
5253
}
5354

54-
export function patchGravatarUrl(gravatarUrl) {
55+
export function patchGravatarUrl(gravatarUrl: string) {
5556
const url = new URL(gravatarUrl, true);
5657
const {query} = url;
5758
query.d = '404';

src/helpers/__tests__/DocsGenerator.spec.js

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/helpers/index.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/helpers/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as AvatarHelper from './AvatarHelper';
2+
3+
export {default as Constants} from './Constants';
4+
export {AvatarHelper};

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,5 @@ export {
2020
FeatureHighlight, Hint, BaseInput, TextArea, TextField, MaskedInput, ListItem, PageControl, PanningProvider,
2121
PanGestureView, PanListenerView, PanDismissibleView, PanResponderView, Picker, ProgressBar, Slider, GradientSlider,
2222
ColorSliderGroup, Stepper, TabBar, TagsInput, SharedTransition, StackAggregator, Toast,
23-
WheelPickerDialog, Assets, BaseComponent, PureBaseComponent, UIComponent, forwardRef, AvatarHelper, Constants,
24-
DocsGenerator, LogService, LoaderScreen, Modal, StateScreen, WheelPicker, Incubator, ColorPicker
23+
WheelPickerDialog, Assets, BaseComponent, PureBaseComponent, UIComponent, forwardRef, AvatarHelper, Constants, LogService, LoaderScreen, Modal, StateScreen, WheelPicker, Incubator, ColorPicker
2524
} from '../typings';

typings/helpers/DocsGenerator.d.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

typings/helpers/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11

22
export * from './AvatarHelper';
33
export * from './Constants';
4-
export * from './DocsGenerator';

0 commit comments

Comments
 (0)