Skip to content

Instantly share code, notes, and snippets.

Robert S. codeBelt

Block or report user

Report or block codeBelt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View getCountdownFromSeconds.ts
export default class TimeUtility {
public static SECONDS_IN = {
WEEK: 604800,
DAY: 86400,
HOUR: 3600,
MINUTE: 60,
};
public static getCountdownFromSeconds(seconds: number): string {
if (seconds < 60) {
@codeBelt
codeBelt / SizeMap.ts
Created Jun 5, 2019
TypeScript Types
View SizeMap.ts
type SizeUnion =
| 'title1'
| 'title2'
| 'title3'
| 'headline'
| 'subhead'
| 'caption1'
| 'caption2'
| 'body1'
| 'callout'
View Util.ts
export default class Util {
/**
* Recursive function that makes a clone of an object.
*
* @param src {Object} The object you to clone.
* @param renamePropertyNameFunction {(keyName: string) => string} Optional function to rename property names
* @returns {any} Returns a clone object of the one passed in.
* @example
* let cloneOfObject = Util.clone(obj);
*/
View StringUtility.ts
export default class StringUtility {
/**
* Converts a string to a camel case string.
*
* @example
* StringUtility.toCamelCase("liveDown_by-the.River");
* // 'liveDownByTheRiver'
*/
static toCamelCase(str) {
return (
@codeBelt
codeBelt / ReduxProps.ts
Last active May 30, 2019
TypeScript Conditional Types for DispatchProp and RouteComponentProps
View ReduxProps.ts
import { DispatchProp } from 'react-redux';
import IAction from './IAction';
import { RouteComponentProps } from 'react-router';
export type ReduxProps<P = any, R = never> = [R] extends [never]
? DispatchProp<IAction<P>>
: DispatchProp<IAction<P>> & RouteComponentProps<R>;
View 2arrays.js
const intersection = array1.filter(element => array2.includes(element));
const intersection = array1.some(element => array2.includes(element));
View exampleBaseModel2.js
import LocationModel from './LocationModel';
import CarModel from './CarModel';
import {BaseModel} from 'sjs-base-model';
class PersonModel extends BaseModel {
firstName = '';
lastName = '';
age = 0;
address = LocationModel; // Creates a new LocationModel if there is address data
View exampleBaseModel1.js
import LocationModel from './LocationModel';
import CarModel from './CarModel';
class PersonModel {
firstName = '';
lastName = '';
age = 0;
address = null
cars = [];
View baseModelTypeScript.ts
import LocationModel from './LocationModel';
import CarModel from './CarModel';
import {BaseModel} from 'sjs-base-model';
class PersonModel extends BaseModel {
public readonly firstName: string = '';
public readonly lastName: string = '';
public readonly age: string = 0;
public readonly address: LocationModel = LocationModel as any;
View johndow.js
const person = new PersonModel({firstName: 'Joe', lastName: 'Doe', address: addressData});
console.log(person.fullName); // Joe Doe
person.update({firstName: 'John'});
console.log(person.fullName); // John Doe
You can’t perform that action at this time.