npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

syv-webapp-commons

v1.0.1

Published

Common utilities, messages, and helpers for web applications

Downloads

5

Readme

webapp-commons

A comprehensive utility package containing common functions, messages, validators, and helpers for web applications. Includes special support for Lao language features.

Installation

npm install syv-webapp-commons

Features

  • Messages: Pre-defined validation, success, error, and UI messages
  • Validators: Common validation functions for forms and data
  • Formatters: Format dates, numbers, currency, phone numbers, etc.
  • HTTP Utilities: Request helpers, status checkers, URL builders
  • Date Utilities: Date manipulation with Lao date format support
  • String Utilities: Text processing with Lao language support

Usage

const {
  messages,
  validators,
  formatters,
  httpUtils,
  dateUtils,
  stringUtils
} = require('webapp-commons');

Messages

// Validation messages
console.log(messages.VALIDATION_MESSAGES.REQUIRED); // "This field is required"
console.log(messages.VALIDATION_MESSAGES.MIN_LENGTH(8)); // "Must be at least 8 characters long"

// Success messages
console.log(messages.SUCCESS_MESSAGES.SAVE_SUCCESS); // "Successfully saved!"

// Error messages
console.log(messages.ERROR_MESSAGES.NETWORK_ERROR); // "Network error. Please check your connection."

// UI messages
console.log(messages.UI_MESSAGES.LOADING); // "Loading..."
console.log(messages.UI_MESSAGES.ITEM_SELECTED(3)); // "3 items selected"

// Common labels
console.log(messages.COMMON_LABELS.EMAIL); // "Email"

Validators

// Basic validation
validators.isRequired('hello'); // true
validators.isValidEmail('[email protected]'); // true
validators.isValidPassword('Password123'); // true

// Form validation
const formData = {
  email: '[email protected]',
  password: '123'
};

const rules = {
  email: [
    { required: true },
    { email: true }
  ],
  password: [
    { required: true },
    { minLength: 8 }
  ]
};

const result = validators.validateForm(formData, rules);
console.log(result.isValid); // false
console.log(result.errors); // { password: "Must be at least 8 characters" }

Formatters

// Currency
formatters.formatCurrency(1234.56); // "$1,234.56"
formatters.formatCurrency(1234.56, 'EUR', 'de-DE'); // "1.234,56 €"

// Dates
formatters.formatDate(new Date(), 'medium'); // "Jan 15, 2024"
formatters.formatTimeAgo(new Date(Date.now() - 3600000)); // "1 hour ago"

// File size
formatters.formatFileSize(1048576); // "1 MB"

// Phone numbers
formatters.formatPhoneNumber('1234567890'); // "(123) 456-7890"

// Names
formatters.formatName('john doe'); // "John Doe"
formatters.formatInitials('John Doe'); // "JD"

HTTP Utilities

// Status checking
httpUtils.isSuccessStatus(200); // true
httpUtils.isClientError(404); // true

// URL building
const url = httpUtils.buildUrl('https://api.example.com', '/users', {
  page: 1,
  limit: 10
}); // "https://api.example.com/users?page=1&limit=10"

// Query string handling
const params = httpUtils.parseQueryString('?name=John&age=30');
console.log(params); // { name: 'John', age: '30' }

// HTTP requests with retry
const data = await httpUtils.withRetry(() => 
  httpUtils.get('https://api.example.com/data')
);

// Simple HTTP methods
const userData = await httpUtils.get('/api/users/1');
const newUser = await httpUtils.post('/api/users', { name: 'John' });
await httpUtils.put('/api/users/1', { name: 'Jane' });
await httpUtils.delete('/api/users/1');

Date Utilities

// Date manipulation
const tomorrow = dateUtils.addDays(new Date(), 1);
const nextMonth = dateUtils.addMonths(new Date(), 1);

// Date checking
dateUtils.isToday(new Date()); // true
dateUtils.isYesterday(new Date(Date.now() - 86400000)); // true

// Lao date formatting
dateUtils.toLaoDateFormat(new Date()); // "15/01/2024"
dateUtils.toLaoFullDateFormat(new Date()); // "ວັນອາທິດ, 15 ມັງກອນ 2024"
dateUtils.getCurrentLaoDate(); // "15/01/2024"

// Buddhist Era conversion
dateUtils.gregorianToBuddhist(2024); // 2567
dateUtils.buddhistToGregorian(2567); // 2024

// Lao date with Buddhist Era
dateUtils.toLaoDateWithBE(new Date()); // "15/01/2567"

// Date validation
dateUtils.isValidLaoDateFormat('15/01/2024'); // true

String Utilities

// Case conversion
stringUtils.capitalize('hello world'); // "Hello world"
stringUtils.toTitleCase('hello world'); // "Hello World"
stringUtils.toCamelCase('hello world'); // "helloWorld"
stringUtils.toKebabCase('Hello World'); // "hello-world"
stringUtils.toSnakeCase('Hello World'); // "hello_world"

// Text processing
stringUtils.slugify('Hello World!'); // "hello-world"
stringUtils.truncateWords('This is a long sentence', 3); // "This is a..."
stringUtils.countWords('Hello world'); // 2
stringUtils.getReadingTime('Lorem ipsum...'); // "2 minutes"

// Validation
stringUtils.isNumeric('12345'); // true
stringUtils.isAlpha('hello'); // true
stringUtils.isAlphanumeric('hello123'); // true

// Lao language support
stringUtils.toLaoNumerals('123'); // "໑໒໓"
stringUtils.fromLaoNumerals('໑໒໓'); // "123"
stringUtils.containsLaoText('Hello ສະບາຍດີ'); // true

// Data extraction
stringUtils.extractEmails('Contact us at [email protected] or [email protected]');
// ["[email protected]", "[email protected]"]

stringUtils.extractUrls('Visit https://example.com or https://test.com');
// ["https://example.com", "https://test.com"]

API Reference

Messages Module

  • VALIDATION_MESSAGES: Form validation messages
  • SUCCESS_MESSAGES: Success operation messages
  • ERROR_MESSAGES: Error messages
  • UI_MESSAGES: User interface messages
  • HTTP_STATUS_MESSAGES: HTTP status code messages
  • COMMON_LABELS: Common form labels

Validators Module

  • isRequired(value): Check if value is not empty
  • isValidEmail(email): Validate email format
  • isValidPassword(password, minLength): Validate password strength
  • isValidPhone(phone): Validate phone number
  • isValidUrl(url): Validate URL format
  • validateForm(data, rules): Comprehensive form validation

Formatters Module

  • formatCurrency(amount, currency, locale): Format currency
  • formatDate(date, format, locale): Format dates
  • formatTimeAgo(date): Relative time formatting
  • formatFileSize(bytes): Format file sizes
  • formatPhoneNumber(phone, format): Format phone numbers

HTTP Utils Module

  • get(url, params, options): GET request
  • post(url, data, options): POST request
  • put(url, data, options): PUT request
  • delete(url, options): DELETE request
  • buildUrl(baseUrl, path, params): Build URLs with query parameters
  • withRetry(requestFn, maxRetries, delay): Retry failed requests

Date Utils Module

  • addDays(date, days): Add days to date
  • toLaoDateFormat(date): Convert to Lao date format (dd/mm/yyyy)
  • toLaoFullDateFormat(date): Format with Lao month/day names
  • gregorianToBuddhist(year): Convert to Buddhist Era year
  • isValidLaoDateFormat(dateString): Validate Lao date format

String Utils Module

  • capitalize(str): Capitalize first letter
  • toTitleCase(str): Convert to title case
  • slugify(str): Create URL-friendly slug
  • toLaoNumerals(str): Convert Arabic to Lao numerals
  • containsLaoText(str): Check for Lao characters
  • extractEmails(str): Extract email addresses from text

Special Features for Lao Language

This package includes special support for Lao language applications:

  • Lao Date Formatting: Convert dates to Lao format (dd/mm/yyyy)
  • Buddhist Era Support: Convert between Gregorian and Buddhist Era years
  • Lao Numerals: Convert between Arabic (0-9) and Lao (໐-໙) numerals
  • Lao Text Detection: Check if text contains Lao characters
  • Lao Month/Day Names: Full month and day names in Lao language

Testing

npm test

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT License - see the LICENSE file for details.

Support

For support, please create an issue on the GitHub repository or contact the maintainers.