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

@beweco/utils-js

v0.0.11

Published

Utilidades de validación para BeWe

Downloads

406

Readme

@beweco/utils

Utility library for phone number validation and Tolgee localization management.

Installation

npm install @beweco/utils-js

Usage

Phone Validation

import { validatePhone } from '@beweco/utils-js';

// Validate a Chilean mobile number
const { isValid, formattedNumber, error } = validatePhone('912345678');
if (isValid) {
  console.log(formattedNumber); // '+56912345678'
} else {
  console.log(error);
}

// Validate with different country code
const result = validatePhone('912345678', '+1');

Tolgee Localization

import { 
  getAllKeysTolgee, 
  downloadTranslations, 
  uploadOnlyNewKeysToTolgee, 
  uploadToTolgee,
  getAvailableLanguages 
} from '@beweco/utils-js';

// Configuration
const config = {
  apiKey: 'your-tolgee-api-key',
  projectId: 'your-project-id',
  baseUrl: 'https://app.tolgee.io' // optional, defaults to this value
};

// Get all available languages
const languages = await getAvailableLanguages(config);

// Get all keys from project
const keys = await getAllKeysTolgee(config);

// Download all translations
const translations = await downloadTranslations(config);

// Upload new keys only
const uploadResult = await uploadOnlyNewKeysToTolgee({
  ...config,
  language: 'es-AR',
  namespace: 'common',
  data: {
    'welcome': 'Bienvenido',
    'hello': 'Hola'
  }
});

// Upload all keys (including duplicates)
const uploadAllResult = await uploadToTolgee({
  ...config,
  language: 'es-AR',
  namespace: 'common',
  data: {
    'welcome': 'Bienvenido',
    'hello': 'Hola'
  }
});

API Reference

Phone Validation

validatePhone(phone: string, countryCode?: string): PhoneValidationResult

Validates and formats a phone number.

Parameters:

  • phone - The phone number to validate
  • countryCode - Optional country code (default: '+56' for Chile)

Returns: PhoneValidationResult

interface PhoneValidationResult {
  isValid: boolean;
  formattedNumber?: string;
  error?: string;
}

Validation Rules:

  • Must be a mobile number (starts with 9)
  • Must be 9 digits long (excluding country code)
  • Can be provided with or without country code
  • Automatically formats to international format (e.g., '+56912345678')

Tolgee Localization

Types

interface TolgeeConfig {
  apiKey: string;
  projectId: string;
  baseUrl?: string;
}

interface Language {
  tag: string;
  name: string;
  originalName: string;
}

interface TranslationData {
  [key: string]: string;
}

interface DownloadTranslationsResult {
  languages: Language[];
  translations: {
    [language: string]: {
      [namespace: string]: {
        [key: string]: string;
      };
    };
  };
}

interface UploadResult {
  uploaded?: number;
  [key: string]: unknown;
}

Functions

getAvailableLanguages(config: TolgeeConfig): Promise<Language[]>

Gets all available languages in the Tolgee project.

getAllKeysTolgee(config: TolgeeConfig): Promise<string[]>

Gets all keys from the Tolgee project with pagination support.

downloadTranslations(config: TolgeeConfig & { namespace?: string }): Promise

Downloads all translations organized by language and namespace.

Parameters:

  • config - Tolgee configuration
  • namespace - Optional namespace filter
uploadOnlyNewKeysToTolgee(config: TolgeeConfig & { language: string; namespace: string; data: TranslationData }): Promise

Uploads only new keys that don't exist in the project.

Parameters:

  • config - Tolgee configuration
  • language - Target language (e.g., 'es-AR')
  • namespace - Namespace (e.g., 'common')
  • data - Translation data object
uploadToTolgee(config: TolgeeConfig & { language: string; namespace: string; data: TranslationData }): Promise

Uploads all keys without checking for duplicates.

Parameters:

  • config - Tolgee configuration
  • language - Target language (e.g., 'es-AR')
  • namespace - Namespace (e.g., 'common')
  • data - Translation data object

Constants

const DEFAULT_BASE_URL = 'https://app.tolgee.io';
const DEFAULT_PAGE_SIZE = 1000;

Development

Prerequisites

  • Node.js >= 14
  • npm

Available Scripts

  • npm run clean - Removes the dist directory
  • npm run build - Compiles TypeScript code
  • npm test - Runs Jest tests
  • npm run lint - Runs ESLint
  • npm run dev - Runs TypeScript compiler in watch mode

Contributing

  1. Create a new branch from main
  2. Make your changes
  3. Write/update tests if necessary
  4. Run linting and tests
  5. Create a pull request

License

MIT