@sassywares/trunk
v1.0.3
Published
Trunk is a simple set of utilities for your JavaScript applications. Read the documentation at https://github.com/sassywares/trunk#readme
Downloads
4
Maintainers
Readme
Trunk
Trunk is a set of utilities for JavaScript applications. Read more below.
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);
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';
Contributing
Trunk comes from the community for the community. We are 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.