npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

ignate-expression-eval

v1.0.0

Published

A JavaScript library for evaluating mathematical expressions with date functions

Downloads

37

Readme

Ignate Expression Evaluation Library with Date, Random, and String Functions

Overview

This JavaScript library extends the math.js library by adding custom functions for date manipulation, random number generation, and string operations. It uses moment-timezone for handling time zones and formatting dates effectively.

Features

  • Date Functions: Add, subtract, format, and get start/end of week, month, or year.
  • Random Functions: Generate random dates, integers, and floating-point numbers.
  • String Functions: Perform various string operations such as trimming, concatenation, replacement, and case conversion.
  • Expression Evaluation: Supports mathematical and logical expressions.

Dependencies

  • mathjs
  • moment-timezone

Installation

To use this library, install the required dependencies:

npm install mathjs moment-timezone

Usage

Import the library and evaluate expressions:

const { evaluateExpression } = require("./ignate-expression-eval");

console.log(evaluateExpression("2 + 3 * 5")); // 17
console.log(evaluateExpression("dateAdd('2025-02-11', 5, 'days', 'UTC')")); // "2025-02-16"
console.log(evaluateExpression("toUpperCase('hello')")); // "HELLO"
console.log(evaluateExpression("randomInt(1, 100)")); // Random integer between 1 and 100
console.log(evaluateExpression("2 + 3 * 5")); // 17
console.log(
  evaluateExpression("dateFormat(dateAdd(now(), 5, 'days'),'yyyy/MM/DD')")
); // "2025-02-16"
console.log(evaluateExpression("now()")); // Current date-time in ISO format
console.log(evaluateExpression("dateFormat('2025-02-11', 'yyyy/MM/dd')")); // "2025/02/11"
console.log(
  evaluateExpression("dateFormat(dateSubtract(now(), 5, 'days'),'yyyy/MM/dd')")
); // "2025/02/06"
console.log(evaluateExpression("getStartOfWeek(now())"));
console.log(evaluateExpression("getEndOfWeek(now())"));
console.log(evaluateExpression("getStartOfMonth(now())"));
console.log(evaluateExpression("getEndOfMonth(now())"));
console.log(evaluateExpression("getStartOfYear(now())"));
console.log(evaluateExpression("getEndOfYear(now())"));
console.log(evaluateExpression("randomInt(1,33)"));
console.log(evaluateExpression("generateUUID()"));

Available Functions

Date Functions

  • now(timeZone) - Returns the current date-time in the specified time zone.
  • today(timeZone) - Returns the current date in YYYY-MM-DD format.
  • dateAdd(dateStr, amount, unit, timeZone) - Adds a specified amount of time to a date.
  • dateSubtract(dateStr, amount, unit, timeZone) - Subtracts a specified amount of time from a date.
  • dateFormat(dateStr, format, timeZone) - Formats a date based on the given format string.
  • getStartOfWeek(dateStr, timeZone), getEndOfWeek(dateStr, timeZone) - Get start and end of the week.
  • getStartOfMonth(dateStr, timeZone), getEndOfMonth(dateStr, timeZone) - Get start and end of the month.
  • getStartOfYear(dateStr, timeZone), getEndOfYear(dateStr, timeZone) - Get start and end of the year.

Random Functions

  • randomDate(startDate, endDate) - Returns a random date between two dates.
  • randomInt(min, max) - Returns a random integer in the given range.
  • randomFloat(min, max) - Returns a random floating-point number in the given range.

String Functions

  • toUpperCase(str), toLowerCase(str) - Converts string to upper/lower case.
  • trim(str) - Trims whitespace from a string.
  • substring(str, start, end) - Extracts a substring.
  • replace(str, search, replacement) - Replaces occurrences of a substring.
  • includes(str, search) - Checks if a string contains another string.
  • split(str, delimiter) - Splits a string into an array.
  • concat(...args) - Concatenates multiple strings.
  • length(str) - Returns the length of a string.
  • startsWith(str, search), endsWith(str, search) - Checks if a string starts/ends with a given substring.

License

This library is open-source and available under the MIT License.