@aamirtech/utils
v0.1.7
Published
Library packed with your basic code utils.
Downloads
58
Maintainers
Readme
@aamirtech/utils
Library packed with your basic code utils.
Documentation
The documentation is available at aamir.tech.
Installation
Install with npm
npm install @aamirtech/utilsInstall with yarn
yarn add @aamirtech/utilsInstall with bun
bun add @aamirtech/utilsUsage
All utility functions use snake_case naming:
import {
snowflake, // lowercase object name (with backward compatibility)
Snowflake, // alias for backward compatibility
get_public_id,
get_initials,
is_email,
get_sanitized_email,
get_base_email,
to_title_case,
to_camel_case,
to_pascal_case,
to_snake_case,
to_kebab_case
} from "@aamirtech/utils";Snowflake ID Generation
// Preferred lowercase naming
console.log(snowflake.generate());
// 7167216930510602240
console.log(snowflake.generate(1));
// 7167216930510602241
// Parse snowflake components
const id = snowflake.generate(1);
const parsed = snowflake.parse(id);
console.log(parsed.nodeId); // 1
// Backward compatibility also supported
console.log(Snowflake.generate()); // Still worksPublic ID Generation
// Generate 6-character alphanumeric ID (default)
get_public_id(); // "A3B9C2"
// Generate 10-character numeric ID
get_public_id(10, { numeric: true, alphabetic: false }); // "1234567890"
// Generate 8-character alphabetic ID
get_public_id(8, { numeric: false, alphabetic: true }); // "ABCDEFGH"Email Validation
// Standard email addresses
is_email("[email protected]"); // true
is_email("[email protected]"); // true
// Plus addressing (email filtering/sub-addressing)
is_email("[email protected]"); // true
is_email("[email protected]"); // true
is_email("[email protected]"); // true
is_email("[email protected]"); // true
// Invalid emails
is_email("invalid-email"); // false
is_email("user@"); // false
is_email("@example.com"); // false
is_email("[email protected]"); // false (plus at start)
is_email("[email protected]"); // false (plus at end)Email Sanitization
// Remove plus addressing and normalize email
get_sanitized_email("[email protected]"); // "[email protected]"
get_sanitized_email("[email protected]"); // "[email protected]"
// Handle multiple plus signs and dots
get_sanitized_email("[email protected]"); // "[email protected]"
get_sanitized_email("[email protected]"); // "[email protected]"
get_sanitized_email("[email protected]"); // "[email protected]"
// Remove subdomains (optional)
get_sanitized_email("[email protected]", { keepSubdomains: false }); // "[email protected]"
// Simple alias for common use case
get_base_email("[email protected]"); // "[email protected]"Initials Extraction
get_initials("John Doe"); // "JD"
get_initials("Alice Mary Smith"); // "AS"
get_initials("Bob"); // "B"
get_initials("Mary-Jane Watson"); // "MW"String Case Conversion
to_title_case("hello_world"); // "Hello World"
to_camel_case("hello_world"); // "helloWorld"
to_pascal_case("hello_world"); // "HelloWorld"
to_snake_case("Hello World"); // "hello_world"
to_kebab_case("Hello World"); // "hello-world"Tests
Tests are written in Bun Test. To run tests, run the following command:
bun testTo run tests with coverage, run the following command:
bun test:coverageLicense
The project contains part based on a fork off of (snowflake-generator)[https://github.com/FatAussieFatBoy/snowflake-generator].
