Skip to content

Instantly share code, notes, and snippets.

View IvanAdmaers's full-sized avatar

IvanAdmaers

View GitHub Profile
@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 / 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 / Usage.md
Created August 27, 2022 00:59
Includes to Handlebars | Array method

Includes

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

Several includes

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) =>
import hasOwnProperty from './hasOwnProperty';
const object = {
name: 'John',
get userName(): string {
return object.name;
},
set setUserName(name: string) {
object.name = name;
},
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 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');
});
@IvanAdmaers
IvanAdmaers / createMD5Signature.test.ts
Created May 18, 2022 06:51
Create MD5 signature NodeJS | JavaScript | TypeScript
import createMD5Signature from './createMD5Signature';
describe('createMD5Signature', () => {
it('should return a correct hash', () => {
expect(createMD5Signature('JohnSmith:9129s$aW}a1')).toBe(
'6436241bc4170549efac409b8a4fc43f'
);
});
});
@IvanAdmaers
IvanAdmaers / README.md
Last active May 17, 2022 14:16
collectObjectValues

This function collects object values { a: 1, b: 2 } => [1, 2] { c: { d: 3, e: 4 } } => [3, 4]