Getting Started
Learn how to install and set up Lopos in your JavaScript project.
Guide
Installation
Setup
Quick Start
Installation
Install Lopos via npm
Import
Import the functions you need
Use
Start using Lopos functions
Installation
Using npm
npm install loposUsing yarn
yarn add loposUsing pnpm
pnpm add loposImporting Functions
Import All Functions
const {
test,
lopif,
deepMerge,
flexibleDate,
advancedThrottle,
deepClone
} = require("lopos");Import Specific Functions
// Import only what you need
const { test, deepMerge } = require("lopos");
// Or import individual functions
const test = require("lopos").test;ES6 Modules (if supported)
import { test, lopif, deepMerge } from "lopos";
// Or import all
import * as lopos from "lopos";Basic Usage Examples
Testing Values
const { test } = require("lopos");
// Basic equality testing
console.log(test("equals", 5, 5)); // true
console.log(test("contains", "Hello World", "World", { ignoreCase: true })); // true
console.log(test("inRange", 10, [5, 15])); // trueConditional Logic
const { lopif } = require("lopos");
// Execute functions based on conditions
const result = lopif(
10 > 5,
() => "Greater than 5",
() => "Less than or equal to 5"
);
console.log(result); // "Greater than 5"Deep Merging
const { deepMerge } = require("lopos");
const config = { api: { timeout: 1000 } };
const userConfig = { api: { retries: 3 }, debug: true };
const finalConfig = deepMerge(config, userConfig);
console.log(finalConfig);
// { api: { timeout: 1000, retries: 3 }, debug: true }Date Handling
const { flexibleDate } = require("lopos");
// Parse and format dates
const date = flexibleDate("2023-01-01", { format: "locale" });
console.log(date); // "1/1/2023, 12:00:00 AM"
// Relative time
const relative = flexibleDate(new Date(Date.now() - 86400000), { relative: true });
console.log(relative); // "1 day ago"Requirements
Node.js 12.0.0 or higher
Modern browsers (ES5+ support)
No external dependencies
TypeScript Support
While Lopos is written in JavaScript, it works seamlessly with TypeScript projects. You can create your own type definitions or use the library with implicit any types.
// Example TypeScript usage
import { test, deepMerge } from "lopos";
interface Config {
timeout: number;
retries?: number;
}
const defaultConfig: Config = { timeout: 1000 };
const userConfig: Partial<Config> = { retries: 3 };
const finalConfig = deepMerge(defaultConfig, userConfig) as Config;
// Type-safe testing
const isValid: boolean = test("greaterThan", finalConfig.timeout, 500);Next Steps
Now that you have Lopos installed, explore the documentation: