/trunk

Trunk is a sassy-little-set of utilities for JavaScript applications.

Primary LanguageTypeScriptMIT LicenseMIT

Trunk

npm version Builds

Trunk is a set of utilities for JavaScript applications. Read more below. Trunk is built using Crust, a simple boilerplate for creating and publishing packages to NPM.

Getting Started

To get started with Trunk, install it using NPM, Yarn, or PNPM:

npm install @sassywares/trunk
yarn add @sassywares/trunk
pnpm add @sassywares/trunk

Then, import the functions you need:

import { isObject, detectBrowser } from '@sassywares/trunk';

Functions

log

import { log } from '@sassywares/trunk';

// Only logs when NODE_ENV is set to development
log('Hello World');

scrollIntoViewById

import { scrollIntoViewById } from '@sassywares/trunk';

// Scrolls to the element with the id of 'my-id'
scrollIntoViewById('my-id');

// Can pass behavior as the second argument
scrollIntoViewById('my-id', 'smooth');

detectBrowser

import { detectBrowser } from '@sassywares/trunk';

// Returns the detected browser as well as sets it as a class on the html element
detectBrowser();

detectOs

import { detectOs } from '@sassywares/trunk';

// Returns the detected OS as well as sets it as a class on the html element
detectOs();

isArray

import { isArray } from '@sassywares/trunk';

// Returns true
isArray([]);

// Returns false
isArray({});

isObject

import { isObject } from '@sassywares/trunk';

// Returns true
isObject({});

// Returns false
isObject([]);

switchTheme

import { switchTheme } from '@sassywares/trunk';

// Switches the theme to dark
switchTheme('dark');

// Switches the theme to light
switchTheme('light');

// Switches the theme to user's preferred theme and observes for changes
switchTheme('system');

getTheme

import { getTheme } from '@sassywares/trunk';

// Returns the current theme or null if no theme is set
getTheme();

debounce

import { debounce } from '@sassywares/trunk';

// Debounces the function by 500ms
const debouncedLog = debounce((obj) => console.log(obj), 500);

msToSeconds

import { msToSeconds } from '@sassywares/trunk';

// Returns 1
msToSeconds(1000);

// Returns 2
msToSeconds(2000);

Contributing

Trunk comes from the community for the community. As you know, I made trunk as a way to have all the functions I use again and again to be in a separate package. You can do the same and contribute to trunk, add your functions, write their tests and then re-use them anywhere you want. I'm always looking for ways to improve Trunk and make it better. If you have any suggestions, ideas, or feedback, please open an issue or a pull request.

License

Trunk is open source software released under the MIT License. We encourage you to use, modify, and distribute Trunk as you see fit.