Skip to content

Commit

Permalink
remove env const
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitskvmdam committed Oct 29, 2021
1 parent 6a74d34 commit 963812b
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 34 deletions.
2 changes: 0 additions & 2 deletions src/constants/env.ts

This file was deleted.

13 changes: 6 additions & 7 deletions src/styles/colors/color.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { __DEV__ } from '../../constants/env'
import { isValidColorHex, isColorOrRGBA } from './check'
import { hex2rgba } from './convert'
import { RGBA } from './rgba'
Expand All @@ -19,7 +18,7 @@ export const getTintOrShade = (
factor = 0.1
): string => {
if (!isColorOrRGBA(color)) {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error(
'[Chromatin - getTintOrShade]: color should be'.concat(
' a valid hex code or an instance of RGBA class. Got: ',
Expand All @@ -34,7 +33,7 @@ export const getTintOrShade = (
}

if (factor > 1 || factor < 0) {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error(
'[Chromatin - getTintOrShade] Factor should be between 0 and 1',
'Got: '.concat(factor.toString())
Expand Down Expand Up @@ -91,7 +90,7 @@ export const createColor = (
options = {} as CreateColorOptions
): BasicColor => {
if (!isValidColorHex(baseColor)) {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error(
'[Chromatin - createColor]: Expecting baseColor as hex'.concat(
' as string. Got',
Expand Down Expand Up @@ -156,7 +155,7 @@ export const createColor = (
*/
export const getLuminous = (color: RGBA): number => {
if (!(color instanceof RGBA)) {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error(
'[Chromatin - getLuminous]: color is not an instance of RGBA'
)
Expand Down Expand Up @@ -190,7 +189,7 @@ export const getContrastRatio = (
color2: string | RGBA
): number => {
if (!isColorOrRGBA(color1)) {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error(
'[Chromatin - getContrastRatio]: color1 is not valid.'.concat(
' It should be hex code or an instance of RGBA',
Expand All @@ -204,7 +203,7 @@ export const getContrastRatio = (
}

if (!isColorOrRGBA(color2)) {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error(
'[Chromatin - getContrastRatio]: color2 is not valid.'.concat(
' It should be hex code or an instance of RGBA',
Expand Down
5 changes: 2 additions & 3 deletions src/styles/colors/convert.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { __DEV__ } from '../../constants/env'
import { isValidColorHex } from './check'
import { RGBA } from './rgba'

Expand All @@ -11,7 +10,7 @@ import { RGBA } from './rgba'
*/
export const hex2rgbArray = (hexValue: string): [number, number, number] => {
if (!isValidColorHex(`#${hexValue}`)) {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error(
'[Chromatin - hex2rgbArray]: Expecting hex value only.',
'Hex without "#". Got: '.concat(hexValue)
Expand Down Expand Up @@ -74,7 +73,7 @@ export const hex2rgbArray = (hexValue: string): [number, number, number] => {
*/
export const hex2rgba = (hex: string, alpha = 1): RGBA => {
if (!isValidColorHex(hex)) {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error('[Chromatin - hex2rgba]: Not a valid hex. Given', hex)
}

Expand Down
3 changes: 1 addition & 2 deletions src/styles/theme/create/typography.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { __DEV__ } from '../../../constants/env'
import { mergeDeep } from '../../../utils'
import {
namedTypographyScales as scales,
Expand All @@ -18,7 +17,7 @@ export const createThemeTypography = (
options = {} as CreateThemeTypographyOptions
): ThemeTypography => {
if (typeof options !== 'function' && typeof options !== 'object') {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error(
'[Chromatin - createTypography]: Expecting options as'.concat(
' an object or a function. Got',
Expand Down
7 changes: 3 additions & 4 deletions src/styles/theme/theme-css.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CSSObject } from 'styled-components'
import { __DEV__ } from '../../constants/env'
import { Theme } from './create'

export type ThemeCSSStyles = CSSObject | ((theme: Theme) => CSSObject)
Expand All @@ -9,7 +8,7 @@ export const getThemeCSSObject = (
theme?: Theme
): CSSObject => {
if (typeof styles !== 'object' && typeof styles !== 'function') {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error(
'[Chromatin - themeCSSObject]: Expecting styles as'.concat(
' Object or Function. Got ',
Expand All @@ -23,7 +22,7 @@ export const getThemeCSSObject = (
if (typeof styles === 'object') return styles

if (!theme) {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error(
'[Chromatin - themeCSSObject]: If styles is a Function'.concat(
' then theme object is required. '
Expand All @@ -34,7 +33,7 @@ export const getThemeCSSObject = (
}

if (typeof theme !== 'object') {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error(
'[Chromatin - themeCSSObject]: theme is not valid'.concat(
' Expecting theme as an object. Got ',
Expand Down
7 changes: 3 additions & 4 deletions src/styles/theme/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Theme, ThemeColorName, ThemePaletteColor } from './create'
import { isThemeColorName, isThemePaletteColorKey } from './validate'
import { isBasicColorKey } from '../colors/utils'
import { __DEV__ } from '../../constants/env'

import type { BasicColor, ThemeType } from '../colors'

Expand All @@ -15,7 +14,7 @@ export const getColorNameAndKey = (
options = {} as { theme: Theme; defaultKey?: string }
): ColorAndKeyTuple | undefined => {
if (typeof color !== 'string') {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error(
'[Chromatin - getColorNameAndKey]: Expecting '.concat(
'color as string. Got: ',
Expand Down Expand Up @@ -44,7 +43,7 @@ export const getThemeColorUsingKey = (
theme: Theme
): string => {
if (!Array.isArray(colorTuple)) {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error(
'[Chromatin - getThemeColorUsingKey]: Expecting'.concat(
'colorTuple but Got: ',
Expand All @@ -62,7 +61,7 @@ export const getThemeColorUsingKey = (
const colorName = color.slice(1)
return (theme.palette.other[colorName] as any)[key]
} catch {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error(
'[Chromatin - getThemeColorUsingKey]: Other color '.concat(
'is not defined. theme.palette.other.',
Expand Down
7 changes: 3 additions & 4 deletions src/styles/theme/validate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { __DEV__ } from '../../constants/env'
import { isBasicColorKey } from '../colors/utils'

import type {
Expand All @@ -13,7 +12,7 @@ export const isThemeColorName = (
theme?: Theme
): colorName is ThemeColorName => {
if (typeof colorName !== 'string') {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error(
'[Chromatin - isThemeColorName]: Expecting '.concat(
'colorName as string. Got: ',
Expand Down Expand Up @@ -53,7 +52,7 @@ export const isThemeFontVariant = (
name: string
): name is ThemeTypographyVariant => {
if (typeof name !== 'string') {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error(
'[Chromatin - isThemeFontVariant]: Expecting '.concat(
'name as string. Got: ',
Expand Down Expand Up @@ -86,7 +85,7 @@ export const isThemePaletteColorKey = (
key: string | number
): key is keyof ThemePaletteColor => {
if (typeof key !== 'string' && typeof key !== 'number') {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error(
'[Chromatin - isThemePaletteColorKey]: Expecting '.concat(
'key as string or number. Got: ',
Expand Down
4 changes: 1 addition & 3 deletions src/utils/attach-signature-to-component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { __DEV__ } from '../constants/env'

export const attachSignatureToComponent = <T>(
Component: T,
id: string
): void => {
if (typeof id !== 'string') {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error(
[
'[Chromatin - attachSignatureToComponent]: id is required,',
Expand Down
8 changes: 3 additions & 5 deletions src/utils/validate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { __DEV__, __TEST__ } from '../constants/env'

export const isValidAnchorElement = (
// eslint-disable-next-line max-len
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
Expand All @@ -8,7 +6,7 @@ export const isValidAnchorElement = (
if (anchorElement === null) return false

if (!anchorElement || typeof anchorElement !== 'object') {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.error(
[
'[Chromatin - isValidAnchorElement]: Anchor Element is not',
Expand All @@ -24,13 +22,13 @@ export const isValidAnchorElement = (
const element = anchorElement.getBoundingClientRect()

if (
!__TEST__ &&
process.env.NODE_ENV !== 'test' &&
element.top === 0 &&
element.left === 0 &&
element.right === 0 &&
element.bottom === 0
) {
if (__DEV__) {
if (process.env.NODE_ENV !== 'production') {
console.warn(
[
'[Chromatin - isValidAnchorElement]: Anchor Element',
Expand Down

0 comments on commit 963812b

Please sign in to comment.