Skip to content

Instantly share code, notes, and snippets.

@jjherscheid
jjherscheid / js-interface-validation.js
Last active April 9, 2024 10:16
Check is object matches expected interface in Javascript
/**
* Check if object matches interface including type of property
* Nested propertys not supported for now
*/
function checkInterface(originalObject, interfaceObject, disableTypeChecking) {
for (var key in interfaceObject) {
// If original object does not contain property of interface
if (!originalObject.hasOwnProperty(key)) {
return false;
}
@jjherscheid
jjherscheid / testing.spec.ts
Created September 12, 2018 07:28
Testing Angular with TsMocks and TestBed
import { TestBed, inject } from '@angular/core/testing';
import { Mock } from 'ts-mocks';
import { MainService } from './main.service';
import { SubService } from './sub.service';
describe('MainService using useValue', () => {
let mockService: Mock<SubService>;
let systemUnderTest: MainService;
import _ from "lodash";
/** This method can be used to simplify objects with empty properties. propX: undefined of propX: {} will be removed */
const compact = (obj: any): any => {
return _(obj)
.mapValues((propertyValue) => {
if (!_.isObject(propertyValue)) {
return propertyValue;
} else if (_.isArray(propertyValue)) {
return propertyValue.map((arrayItem) => {