Monthly Archives: July 2016

How to Programmatically Print Labels/Barcodes on a Zebra Printer

Here are a few things you need to know for when you want to print labels/barcodes using a Zebra Technologies printer.

Once you’ve figured this stuff out it’s actually pretty easy to embed a Zebra printer into your environment. I hope this has saved you some time.

Accessing JavaScript Properties via a Dot Notation String at Runtime

Problem

You have something like the following object and a string which you would like to use to access a property on said object:

{
  common: {
    de: {
      library: 'Bibliothek',
      manufacturer: 'Hersteller'
    }
  }
}
"common.de.library"

Solution

var accessPropertyViaString = function(object, keys) {
  try {
    return keys.split('.').reduce((prev, curr) => prev[curr], object) || keys;
  } catch (ex) {
    return keys;
  }
};

This function returns the value of the wanted property. If it can’t find the property it will return the input string. Please do not try to solve this problem using eval() for reasons explained in this answer on StackOverflow.