Skip to content

Additional Scripting Libraries

In addition to the core BizzStream scripting functions and standard JavaScript features, the scripting environment includes several third-party libraries that provide helpful utilities for common programming tasks.

Underscore.js Library

Underscore.js is a JavaScript library that provides a wide range of utility functions for common programming tasks, especially working with collections (arrays and objects). It offers handy methods for iterating, mapping, reducing, filtering, and sorting data.

You can access Underscore.js methods through the global _ object within your scripts.

Extensive documentation for Underscore.js methods can be found here: Underscore.

Underscore.js Example: Iterating through an Array (_.each)

This example shows how to loop through an array using the _.each method, which can be a concise alternative to a standard JavaScript for loop.

// Loop in plain Javascript
var pizzas = ["Pizza Mozzarella", "Pizza Margaritha", "Pizza Funghi"];
for(var i = 0; i < pizzas.length; i++) {
  console.log('pizza: ' + pizzas[i]);
  // Expected console.log output:
  // pizza: Pizza Mozzarella
  // pizza: Pizza Margaritha
  // pizza: Pizza Funghi
}

// Loop in UnderscoreJS
var pizzas = ["Pizza Mozzarella", "Pizza Margaritha", "Pizza Funghi"];
_.each(pizzas, function(pizza, index, pizzas) {
  console.log('pizza: ' + pizza);
    // Expected console.log output:
    // pizza: Pizza Mozzarella
    // pizza: Pizza Margaritha
    // pizza: Pizza Funghi
});

Underscore.js Example: Filtering a Collection (_.filter)

This example demonstrates using the _.filter method to easily select elements from an array that pass a test function.

var numbers = [1, 2, 3, 4, 5, 6];

evenTester = function (number) { // Changed 'numbers' to 'number' for clarity in the function parameter
            return number % 2 === 0;
        };

console.log('Even numbers: ' + _.filter(numbers, evenTester));
// Expected console.log output:
// Even numbers: 2,4,6

Day.js Library

Day.js is a minimalist JavaScript library for parsing, validating, manipulating, and formatting dates and times. It is designed to be a lightweight alternative with a simple API similar to Moment.js.

You can access Day.js methods through the global dayjs object within your scripts.

Extensive documentation for Day.js methods and available plugins can be found here: Day.js.

Day.js Example: Parsing and Formatting a Date

This example shows how to parse a date string and format it using Day.js.

var date = '2017-09-10';
var jsDate = dayjs(date); // Use dayjs object
console.log(jsDate.format());

// Expected console.log output (format varies by locale/configuration, but typically ISO 8601):
// 2017-09-10T00:00:00+00:00

Day.js Setting the Locale

Day.js supports locales to handle date parsing and formatting based on regional conventions.

To set the locale, you typically need to load the locale data and then use the dayjs.locale() method:

// Assuming 'nl' locale data is loaded or available
dayjs.locale('nl'); // Set locale to Dutch

// After setting the locale, subsequent Day.js operations may use Dutch conventions.