Skip to content

Instantly share code, notes, and snippets.

Robert S. codeBelt

View GitHub Profile
@codeBelt
codeBelt / IAppDomId.ts
Last active Apr 22, 2019
CRA multiple apps
View IAppDomId.ts
import {ComponentType} from 'react';
export default interface IAppDomId {
// Component: ComponentType<any>; // TODO: add when used with code splitting
Component: JSX.Element;
domId: string;
}
View craco.config.js
const path = require('path');
/*
* If the value of process.env.CLIENT_ENV is 'development'.
*
* Below will create the following file path:
* 'src/environments/development'
*
* When you use this import statement in the applicaiton:
* import environment from 'environment';
*
View config-overrides.js for CRA 1.0
const path = require('path');
module.exports = function override(config, env) {
config.resolve.alias = Object.assign({}, config.resolve.alias, {
environment: path.join(__dirname, 'src', 'environments', process.env.NODE_ENV)
});
return config;
};
@codeBelt
codeBelt / JavaScript Case Converter Using Lodash.js
Last active Mar 5, 2019
JavaScript Case Converter Using Lodash
View JavaScript Case Converter Using Lodash.js
import {camelCase, kebabCase, lowerCase, snakeCase, startCase, upperCase, upperFirst} from 'lodash';
export default class StringUtility {
static toCamelCase(str) {
return camelCase(str);
}
static toTitleCase(str) {
return startCase(camelCase(str));
View Array.fill.js
const numberArray = new Array(10).fill(1);
console.log(numberArray);
View PropertyNormalizerUtility.js
import StringUtility from './StringUtility';
import {Util} from 'sjs-base-model';
export class PropertyNormalizerUtility {
/**
* Makes all property names camelCase so they are consistent in the application.
* Also recursively goes through child objects.
*
* @param json
View SomeThingReducer.ts
import ISomeThingReducerState from './models/ISomeThingReducerState';
import IAction from '../IAction';
import SomeThingAction, {SomeThingActionUnion} from './SomeThingAction';
import OtherThingResponseModel from './models/OtherThingResponseModel';
export default class SomeThingReducer {
private static readonly _initialState: ISomeThingReducerState = {
isLoadingOtherThing: false,
otherThing: null,
};
View generate.js
const {generateTemplateFiles} = require('generate-template-files');
generateTemplateFiles([
// Example of generating multiple files
{
option: 'Create Redux Store',
defaultCase: '(pascalCase)',
entry: {
folderPath: './tools/templates/',
},
View __store__Reducer.ts
import I__store__ReducerState from './models/I__store__ReducerState';
import IAction from '../IAction';
import __store__Action, {__store__ActionUnion} from './__store__Action';
import __model__ResponseModel from './models/__model__ResponseModel';
export default class __store__Reducer {
private static readonly _initialState: I__store__ReducerState = {
isLoading__model__: false,
__model__(camelCase): null,
};
View checkUtility.ts
const typeError = (obj: any) =>
new Error(`check()'s first argument must be a boolean but argument was of type ${typeof obj}`);
const isNotTypeBoolean = (arg: any) => typeof arg !== 'boolean';
/**
* Helper function for throwing errors if a given expression evaluates to false.
* This function is strict and will throw an error the the type of the first
* argument is not "boolean".
*/
You can’t perform that action at this time.