Skip to content

Instantly share code, notes, and snippets.

View IvanAdmaers's full-sized avatar

IvanAdmaers

View GitHub Profile
import toCamelCase from './toCamelCase';
describe('toCamelCase', () => {
it('should return a correct result for an underscore style', () => {
expect(toCamelCase('under_score')).toBe('underScore');
});
it('should return a correct result for a kebab style', () => {
expect(toCamelCase('kebab-style')).toBe('kebabStyle');
});
import isValidVin from './isValidVin.ts';
describe('isValidVin', () => {
it('should return false for an invalid 16 digit VIN', () => {
const vin = 'JHLRM4H70CC01839';
expect(isValidVin(vin)).toBe(false);
});
it('should return false for an invalid 18 digit VIN', () => {
import hasOwnProperty from './hasOwnProperty';
const object = {
name: 'John',
get userName(): string {
return object.name;
},
set setUserName(name: string) {
object.name = name;
},
const isArray = (item) => Array.isArray(item);
const isObject = (item) =>
item !== null && isArray(item) === false && typeof item === 'object';
const isFunction = (item) => typeof item === 'function';
const isBoolean = (item) => typeof item === 'boolean';
const hasOwnPrototypeOfToString = (object) =>
@IvanAdmaers
IvanAdmaers / Usage.md
Created August 27, 2022 00:59
Includes to Handlebars | Array method

Includes

{{#includes myArray 'apple'}}
  There is an apple!
{{/includes}}

Several includes

@IvanAdmaers
IvanAdmaers / generateUTCId.ts
Last active September 13, 2022 19:06
generateUTCId
/**
* This function returns an ID that depends on UTC
* !WARNING! It might return non-unique ID when the function
* will call more than one time in one milliseconds
* generateUTCId() === generateUTCId() // true
*/
export const generateUTCId = (): number => {
const date = new Date();
const components = [
@IvanAdmaers
IvanAdmaers / sliceByValue.test.ts
Created September 16, 2022 18:24
sliceByValue
import { sliceByValue } from './sliceByValue';
const array = [false, false, true, false, false, false];
describe('sliceByValue', () => {
it('should slice by a boolean type value', () => {
expect(sliceByValue(array, true)).toEqual([false, false, false]);
});
it('should slice by a boolean type value when its the last element', () => {
@IvanAdmaers
IvanAdmaers / example.js
Created September 16, 2022 19:47
Random drop chance JS
const items = [
{
name: 'Apple',
dropChance: 0.7
},
{
name: 'Knife',
dropChance: 0.25
},
{
import { getTimeGreetings, welcomes } from '.';
describe('getTimeGreetings', () => {
beforeEach(() => {
jest.useFakeTimers();
});
it('should return night greetings', () => {
jest.setSystemTime(
new Date('Thu Oct 06 2022 00:00:54 GMT-0400 (Eastern Daylight Time)')