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

@stonyx/utils

v0.2.0

Published

Utils module for Stonyx Framework

Readme

stonyx-utils

Utilities module for the Stonyx Framework. Provides helpers for files, objects, strings, dates, and promises.


Quick Reference Table

| Category | Function | Description | | ----------- | ----------------------- | -------------------------------------------------------- | | File | createFile | Create a file (supports JSON serialization). | | | updateFile | Atomically update a file. | | | copyFile | Copy a file, with optional overwrite. | | | readFile | Read a file (JSON optional), with missing file callback. | | | deleteFile | Delete a file (ignore missing optional). | | | deleteDirectory | Recursively delete a directory. | | | createDirectory | Recursively create a directory. | | | forEachFileImport | Dynamically import all JS files in a directory. | | | fileExists | Check if a file exists. | | Object | deepCopy | Deep clone an object or array. | | | objToJson | Convert object to formatted JSON string. | | | makeArray | Wrap a value in an array. | | | mergeObject | Deep merge two objects (ignore new keys optional). | | | get | Get nested property safely via dot path. | | | getOrSet | Get or set value in a Map. | | String | kebabCaseToCamelCase | Convert kebab-case to camelCase. | | | kebabCaseToPascalCase | Convert kebab-case to PascalCase. | | | generateRandomString | Generate a random alphanumeric string. | | | pluralize | Return plural form of English nouns. | | Date | getTimestamp | Return current UNIX timestamp in seconds. | | Promise | sleep | Async delay for a given number of seconds. |


Table of Contents


Installation

npm install @stonyx/utils

File Utils

The File utils wrap the path and fs libraries to manipulate the local file system asynchronously with full async/await support. Includes creation, reading, updating, copying, deleting files and directories, checking existence, and dynamic importing via forEachFileImport.

Functions

createFile(filePath, data, options={})

Creates a file at the given path.

  • options.json — boolean, if true, data will be serialized to JSON.

updateFile(filePath, data, options={})

Updates a file atomically by writing to a temporary file first.

  • options.json — boolean, serialize as JSON.

copyFile(sourcePath, targetPath, options={})

Copies a file from source to target.

  • options.overwrite — boolean, default false.

readFile(filePath, options={})

Reads a file, optionally parsing JSON.

  • options.json — boolean
  • options.missingFileCallback — function called if file doesn’t exist.

deleteFile(filePath, options={})

Deletes a file.

  • options.ignoreAccessFailure — boolean, ignores errors if file missing.

deleteDirectory(dir)

Recursively deletes a directory.

createDirectory(dir)

Recursively creates a directory.

forEachFileImport(dir, callback, options={})

Dynamically imports all .js files in a directory and calls callback(exports, details).

| Option | Type | Default | Description | | :-------------------: | :-----: | :-----: | :-------------------------------------------------------- | | fullExport | Boolean | false | If true, callback receives all exports, not just default. | | rawName | Boolean | false | If true, the file name is not converted to camelCase. | | ignoreAccessFailure | Boolean | false | If true, directory access errors are ignored. |

Example:

import { forEachFileImport } from '@stonyx/utils/file';

await forEachFileImport('./utils', (exports, details) => {
  console.log(details.name, exports);
}, { fullExport: true });

fileExists(filePath)

Returns true if file exists, else false.


Object Utils

Helpers for working with objects and arrays.

Functions

deepCopy(obj)

Returns a deep copy of an object or array.

objToJson(obj, format='\t')

Returns a formatted JSON string.

makeArray(obj)

Wraps a value in an array if it isn’t already one.

mergeObject(obj1, obj2, options={})

Deep merges two objects.

  • options.ignoreNewKeys — boolean, if true, keys not in obj1 are ignored.

get(obj, path)

Safely gets a nested property using dot notation. Returns null if path not found.

getOrSet(map, key, defaultValue)

Gets the value for a key in a Map, or sets it to defaultValue if missing.


String Utils

Functions

kebabCaseToCamelCase(str)

Converts 'my-string''myString'.

kebabCaseToPascalCase(str)

Converts 'my-string''MyString'.

generateRandomString(length=8)

Generates a random alphanumeric string.

pluralize(word)

Returns the plural form of an English noun, handling irregulars and uncountable nouns.

Example:

import { pluralize } from '@stonyx/utils/string';

console.log(pluralize('person')); // people
console.log(pluralize('box'));    // boxes

Date Utils

Functions

getTimestamp()

Returns the current UNIX timestamp (seconds since epoch).

import { getTimestamp } from '@stonyx/utils/date';

console.log(getTimestamp()); // e.g., 1693564800

Promise Utils

Functions

sleep(seconds)

Delays execution for the given number of seconds.

import { sleep } from '@stonyx/utils/promise';

await sleep(2); // waits 2 seconds

License

Apache — do what you want, just keep attribution.