OneLib.js is a minimalist JavaScript utility library designed to provide common functionality through simple, memorable one-word function names. With zero dependencies and a tiny footprint, it's perfect for rapid prototyping and production applications.
Powerful text manipulation and formatting utilities.
slug(text)
Convert text to URL-friendly slug.
Parameters: text (string) - Text to convert
Returns: string
Example:
const title = "How to Build Amazing Web Apps";
const urlSlug = OneLib.slug(title); // "how-to-build-amazing-web-apps"
const blogPost = "My First Blog Post!";
const url = `/posts/${OneLib.slug(blogPost)}`; // "/posts/my-first-blog-post"
truncate(text, length)
Truncate text to specified length with ellipsis.
Parameters: text (string), length (number, default: 100)
Returns: string
Example:
const longText = "This is a very long description that needs to be shortened";
const preview = OneLib.truncate(longText, 20); // "This is a very long..."
const excerpt = OneLib.truncate(article.content, 150);
Array & Object Helpers
Powerful utilities for array and object manipulation.
const currentTime = OneLib.now();
console.log(currentTime); // Current Date object
// Use in timestamps
const post = {
content: 'Hello world!',
createdAt: OneLib.now()
};
format(date, style)
Format date according to pattern.
Parameters: date (Date|string), style (string, default: 'YYYY-MM-DD')
const postDate = new Date('2024-01-10');
const timeAgo = OneLib.since(postDate); // '5 days ago'
// Use in social media feeds
const post = {
content: 'Just launched my new app!',
timestamp: OneLib.since(post.createdAt)
};
Network Helpers
HTTP requests and network utilities.
get(url)
Make GET request and return text response.
Parameters: url (string)
Returns: Promise<string>
Example:
// Load HTML template
const template = await OneLib.get('/templates/card.html');
// Load text data
const csvData = await OneLib.get('/data/export.csv');
json(url)
Make GET request and return JSON response.
Parameters: url (string)
Returns: Promise<Object>
Example:
// Fetch API data
const users = await OneLib.json('/api/users');
const config = await OneLib.json('/api/config');
// Use in applications
users.forEach(user => {
console.log(user.name);
});
// Show modal with fade effect
OneLib.fadein('#modal', 500);
// Show notification
OneLib.fadein('.notification', 300);
move(selector, x, y)
Move element to coordinates.
Parameters: selector (string|Element), x (number), y (number)
Returns: Element
Example:
// Move element to position
OneLib.move('#draggable', 100, 50);
// Animate to random position
const randomX = OneLib.rand(0, 200);
const randomY = OneLib.rand(0, 100);
OneLib.move('.floating-element', randomX, randomY);
Type Checking
Type validation and checking utilities.
isnum(val)
Check if value is a number.
Parameters: val (any)
Returns: boolean
Example:
if (OneLib.isnum(userInput)) {
const result = userInput * 2;
}
// Validate form input
const age = document.getElementById('age').value;
if (!OneLib.isnum(age)) {
showError('Please enter a valid number');
}
isempty(val)
Check if value is empty.
Parameters: val (any)
Returns: boolean
Example:
// Form validation
if (OneLib.isempty(email)) {
showError('Email is required');
}
// Check arrays and objects
if (!OneLib.isempty(cart)) {
showCheckoutButton();
}
Utilities
General purpose utility functions.
wait(ms)
Wait for milliseconds (Promise-based).
Parameters: ms (number)
Returns: Promise<void>
Example:
// Add delay in async function
async function showSequence() {
OneLib.html('#step1', 'Step 1 complete');
await OneLib.wait(1000);
OneLib.html('#step2', 'Step 2 complete');
await OneLib.wait(1000);
OneLib.html('#step3', 'All done!');
}
// Random integer 1-10
const dice = OneLib.rand(1, 6);
// Random decimal 0-1
const probability = OneLib.rand(0, 1);
// Random price
const price = OneLib.rand(10, 100);
Text Processing (8 functions)
slug(text)
Convert text to URL-friendly slug
const title = "How to Build Amazing Web Apps";
const url = OneLib.slug(title);
// Result: "how-to-build-amazing-web-apps"
const blogPost = "10 Tips & Tricks for JavaScript!";
const slug = OneLib.slug(blogPost);
// Result: "10-tips-tricks-for-javascript"
truncate(text, length)
Truncate text with ellipsis
const longText = "This is a very long description that needs to be shortened";
const preview = OneLib.truncate(longText, 30);
// Result: "This is a very long descrip..."
// Card descriptions
const description = OneLib.truncate(article.content, 150);
Performance
OneLib.js is optimized for performance and minimal bundle impact.
Bundle Size
12KB minified 4KB gzipped
Tree Shaking
Import only what you need Reduce bundle size further
Zero Dependencies
No external libraries No dependency conflicts
Optimized Algorithms
Efficient implementations Fast execution times
Tree Shaking Example
// Import only specific functions
import { sum, avg, slug } from 'onelib';
// Webpack will only include these functions in your bundle
const total = sum([1, 2, 3, 4, 5]);
const average = avg([1, 2, 3, 4, 5]);
const urlSlug = slug('My Blog Post');