• About
  • Privacy Policy
  • Utilities
Darchuk.NET

JavaScript

Karma / Jasmine Unit Test Cheat Sheet

June 8, 2018 by Robert Leave a Comment

I find that writing unit tests in JavaScript kind of sucks, so this post will (hopefully) serve as a cheat sheet of all the stuff I keep looking up.  As such, it will be updated as I learn new stuffs. How To: scope test run to specific tests Remember to set it back before you … [Read more…]

Posted in: Angular, AngularJS, Jasmine, JavaScript, Typescript, Unit Testing, Web Development Tagged: Cheatsheet, Guide, Jasmine, JavaScript, js, Karma, Testing, ts, Typescript, unit testing

JavaScript–toggling an item in a list with xor

June 1, 2018 by Robert Leave a Comment

I had a problem where I wanted to either remove an item from a list if it existed or add it to the list if it did not exist. A use case for this might be selecting which day(s) of the week you want: Behind the scenes, you might store this as a simple array: … [Read more…]

Posted in: JavaScript, Typescript Tagged: Array, JavaScript, js, list, lodash, toggle, ts, Typescript, xor

TypeScript async / await

May 4, 2018 by Robert Leave a Comment

JavaScript is pretty dumb.  I know its the most popular language right now (due to the pervasiveness of browsers and other things that can run it), but, I mean, its just… dumb. Luckily TypeScript is pretty awesome.  It takes a lot of what makes JavaScript stupid and fixes it.  It makes it a lot more … [Read more…]

Posted in: Angular, AngularJS, Asynchronous, Concurrency, JavaScript, Typescript, Web Development Tagged: async, await, JavaScript, multi-threaded, promise, single-threaded, threading, threads, Typescript

Angular 2+: Binding HTML Select ngModel to a number

April 20, 2018 by Robert Leave a Comment

I hate magic things.  In programming, I mean.  I try to avoid magic strings and magic numbers as much as possible because I can barely remember the thing I typed five seconds ago, let alone something that you have to maybe type five hours from now.  So, I tend to use a lot of enums … [Read more…]

Posted in: Angular, HTML, Typescript, Web Development Tagged: Angular, HTML, JavaScript, Option, Select, Typescript, Web Development

D3.js, “this”, and TypeScript

February 23, 2018 by Robert Leave a Comment

D3.js is a super cool and very powerful library for creating some really interesting visualizations. One of the problems that I ran into recently was regarding the “this” keyword in D3 functions.  For example, in regular old javascript you would do: Which is fine.  “this” is scoped to the function, so it would point back … [Read more…]

Posted in: D3, JavaScript, Typescript, Web Development Tagged: d3, JavaScript, this, Typescript

Javascript – Combining arrays with the spread operator

February 9, 2018 by Robert Leave a Comment

Recently I had several small arrays in Javascript that I wanted to combine into one array.  It would be easy enough to write a function to accept two arrays, push the values from one into the other, and return the resulting array, but ECMAScript 6 introduced the spread operator (<—a lot more examples in this … [Read more…]

Posted in: JavaScript, Typescript Tagged: JavaScript, Spread, Typescript

Unit testing error paths of Observable

December 8, 2017 by Robert 1 Comment

When you write code against an Observable, you subscribe to the result.  In the subscribe method you provide the callbacks to perform when the Observable is called back.  That means you can execute different code for success and failure. In the last post I wrote about how to mock up and test Observable<T> in Jasmine … [Read more…]

Posted in: Angular, JavaScript, Unit Testing, Web Development Tagged: JavaScript, rxjs, Typescript, unit testing

Removing non-printable characters in JavaScript

October 13, 2017 by Robert Leave a Comment

A quick look at the Unicode table or the ASCII character table proves that not all characters are meant for us humans to consume.  Some of them are control characters – things that tell the computer what to do.  Most of the time they go unnoticed, but sometimes they can cause problems, especially if you’re … [Read more…]

Posted in: HTML, JavaScript Tagged: ASCII, HTML, JavaScript, Unicode

Getting the text out of HTML select options

October 6, 2017 by Robert Leave a Comment

The HTML select tag is a dropdown.  The elements of a select are defined by the option tag.  The option tag also has the ability to contain values, which may be used to store useful information such as an index. However, what if you don’t need the index, but rather the text being displayed of … [Read more…]

Posted in: HTML, JavaScript Tagged: Dropdown, HTML, JavaScript, Option, Select

MomentJS date manipulation

May 21, 2015 by Robert Leave a Comment

moment.js is a library for manipulating dates and times in JavaScript.  Since programming basically anything to do with dates and times is a pain (due to time zones, localization information, etc), using a well-established library like moment.js is essential. As with any framework, it is important to read the documentation.  In this case, it is … [Read more…]

Posted in: JavaScript Tagged: Dates, JavaScript, moment.js, Times
« Previous 1 2

Recent Posts

  • Allowing trailing JSON commas in ASP.NET Core 3
  • YADNC3JSG–Yet Another .NET Core 3.0 JSON Serializer Gotcha
  • Logging in a .NET Core 3 SignalR client
  • .NET Core 3 unit testing project sdk
  • .NET Core 3.0 Upgrade–New JSON Serializer Gotchas

Recent Comments

  1. Robert on C# Setting Socket Keep-Alive
  2. Oliver Schramm on C# Setting Socket Keep-Alive
  3. John Anderson on Waiting for a keypress asynchronously in a C# console app
  4. Ronald Garlit on .NET Core 3 unit testing project sdk
  5. Ronald Garlit on .NET Core 3 unit testing project sdk

Copyright © 2025 Darchuk.NET.

Omega WordPress Theme by ThemeHall