Skip to content

Commit

Permalink
Merge branch 'master' of github.com:platformbuilders/helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
ammichael committed Jun 17, 2023
2 parents 69a193d + 55e359b commit 7af9e66
Show file tree
Hide file tree
Showing 21 changed files with 394 additions and 92 deletions.
8 changes: 4 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ module.exports = {
testMatch: ['**/__tests__/*.spec.+(ts|tsx)'],
coverageThreshold: {
global: {
branches: 50,
functions: 70,
lines: 75,
statements: 75,
branches: 80,
functions: 90,
lines: 90,
statements: 90,
},
},
unmockedModulePathPatterns: ['react'],
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@platformbuilders/helpers",
"version": "0.8.2",
"version": "0.9.0",
"description": "Builders helpers library",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -46,8 +46,8 @@
"react": ">=18",
"react-dom": ">=18",
"react-native": ">=0.69.3",
"react-native-device-info": ">=10.4.0",
"react-native-haptic": ">=1.0.1",
"react-native-safe-area-context": ">=4.5.3",
"react-native-size-matters": ">=0.3.0",
"styled-components": ">=5"
},
Expand All @@ -61,6 +61,8 @@
"@babel/preset-react": "7.18.6",
"@babel/runtime": "7.20.1",
"@platformbuilders/eslint-config-builders": "^0.1.2",
"@platformbuilders/theme-toolkit": "^0.2.0",
"@testing-library/react-hooks": "^8.0.1",
"@types/dompurify": "^2.4.0",
"@types/jest": "29.2.3",
"@types/lodash": "4.14.189",
Expand All @@ -69,6 +71,7 @@
"@types/react-dom": "18.0.9",
"@types/react-native": "0.70.6",
"@types/styled-components": "5.1.26",
"@types/styled-components-react-native": "5.1.3",
"@typescript-eslint/eslint-plugin": "5.43.0",
"@typescript-eslint/parser": "5.43.0",
"babel-jest": "29.3.1",
Expand All @@ -94,13 +97,16 @@
"mz": "2.7.0",
"numeral": "2.0.6",
"prettier": "2.7.1",
"react": "18.2.0",
"react-native": "0.70.6",
"react-native-device-info": "10.4.0",
"react-native-haptic": "1.0.1",
"react-native-safe-area-context": "^4.5.3",
"react-native-size-matters": "0.4.0",
"react-test-renderer": "18.2.0",
"rmfr": "2.0.0",
"rollup": "3.3.0",
"rollup-plugin-typescript2": "0.34.1",
"styled-components": "^5.3.6",
"ts-jest": "29.0.3",
"typescript": "4.9.3",
"uglify-js": "3.17.4"
Expand Down
7 changes: 0 additions & 7 deletions src/@types/styled-components.d.ts

This file was deleted.

8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
import 'styled-components';

declare module 'styled-components' {
export interface DefaultTheme {
white: string;
}
}

export * from './web';
35 changes: 35 additions & 0 deletions src/native/__tests__/useSpacingsWithSafeArea.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { renderHook } from '@testing-library/react-hooks';
import { useSpacingsWithSafeArea } from '../useSpacingsWithSafeArea';

jest.mock('react', () => ({
...jest.requireActual('react'),
useContext: () => ({
spacing: {
lg: 24,
sm: 8,
},
}),
}));

jest.mock('react-native-safe-area-context', () => {
const {
default: mockSafeAreaContext,
} = require('react-native-safe-area-context/jest/mock');
return mockSafeAreaContext;
});

describe('useSpacingsWithSafeArea', () => {
test("should return spacing lg value when don't have safe area value", async () => {
const { result } = renderHook(() => useSpacingsWithSafeArea());

expect(result.current.topSpacing).toBe(24);
expect(result.current.bottomSpacing).toBe(24);
});

test('should return spacing sm value when pass sm as parameter', async () => {
const { result } = renderHook(() => useSpacingsWithSafeArea('sm'));

expect(result.current.topSpacing).toBe(8);
expect(result.current.bottomSpacing).toBe(8);
});
});
2 changes: 1 addition & 1 deletion src/native/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export * from './isIOS';
export * from './generateHaptic';
export * from './getShadow';
export * from '../shared';
export * from './iphoneHelper';
export * from './useSpacingsWithSafeArea';
54 changes: 0 additions & 54 deletions src/native/iphoneHelper.ts

This file was deleted.

38 changes: 38 additions & 0 deletions src/native/useSpacingsWithSafeArea.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useContext, useEffect, useState } from 'react';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { ThemeContext } from 'styled-components/native';
import { FluidTheme } from '@platformbuilders/theme-toolkit';

export type SpacingValue =
| 'min'
| 'xxs'
| 'xs'
| 'sm'
| 'md'
| 'lg'
| 'xl'
| 'xxl'
| 'max';

export const useSpacingsWithSafeArea = (customSpacing: SpacingValue = 'lg') => {
const { bottom, top } = useSafeAreaInsets();
const themeContext: unknown = useContext(ThemeContext);
const [spacings, setSpacings] = useState({
topSpacing: 0,
bottomSpacing: 0,
});
const themeFluid = themeContext as FluidTheme;
const spacingFluid = themeFluid.spacing[customSpacing];

useEffect(() => {
setSpacings({
topSpacing: top + spacingFluid,
bottomSpacing: bottom + spacingFluid,
});
}, [bottom, top]);

return {
topSpacing: spacings.topSpacing,
bottomSpacing: spacings.bottomSpacing,
};
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addMaskToCardNumber } from '../shared/addMaskToCardNumber';
import { addMaskToCardNumber } from '../addMaskToCardNumber';

const expected = '**** **** **** 1234';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatToBase64 } from '../shared/base64';
import { formatToBase64 } from '../base64';

describe('base64 helpers tests', () => {
it('should return a formatted string when no string sent', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { currencyParser } from '../shared/currencyParser';
import { currencyParser } from '../currencyParser';

describe('currencyParser tests', () => {
describe('with string', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { currencyToNumber } from '../shared/currencyToNumber';
import { currencyToNumber } from '../currencyToNumber';

describe('currencyToNumber tests', () => {
it('should parse to thousands', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatCardNumber } from '../shared/formatCardNumber';
import { formatCardNumber } from '../formatCardNumber';

describe('formatCardNumber tests', () => {
it('should apply mask credit card number 5363 5085 9979 9238', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatToMonogram } from '../shared/formatToMonogram';
import { formatToMonogram } from '../formatToMonogram';

describe('formatToMonogram tests', () => {
it('should format to monogram', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatToPhone } from '../shared/formatToPhone';
import { formatToPhone } from '../formatToPhone';

const expected = '(11) 99999-8888';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseToThousands } from '../shared/parseToThousands';
import { parseToThousands } from '../parseToThousands';

describe('parseToThousands tests', () => {
it('should parse to thousands', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { removeWhiteSpaces } from '../shared/removeWhiteSpaces';
import { removeWhiteSpaces } from '../removeWhiteSpaces';

describe('removeWhiteSpaces tests', () => {
it('should remove white empty spaces properly', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isSecureLink, sanitizeValues } from '../shared/sanitizer';
import { isSecureLink, sanitizeValues } from '../sanitizer';

describe('Sanitizer', () => {
describe('isSecureLink', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { toOnlyNumbers } from '../shared/toOnlyNumbers';
import { toOnlyNumbers } from '../toOnlyNumbers';

describe('toOnlyNumbers tests', () => {
it('should format to string empty properly', () => {
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"target": "es6",
"module": "es6",
"lib": ["esnext", "DOM"],
"types": ["react", "jest"],
"types": ["react", "jest", "@types/styled-components-react-native"],
"jsx": "react",
"declaration": true,
"declarationMap": true,
Expand All @@ -22,7 +22,6 @@
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"suppressImplicitAnyIndexErrors": true,
/* Additional Checks */
"noUnusedLocals": true,
"noUnusedParameters": true,
Expand Down
Loading

0 comments on commit 7af9e66

Please sign in to comment.