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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@zorimo/common

v0.0.10

Published

A set of common utility methods

Downloads

143

Readme

@zorimo/common

npm version

A set of common utility methods.

Installation

You can install this package via npm:

npm install @zorimo/common

Usage

ClassNameHelper

Concatenate class names based on conditions:

import { ClassNameHelper } from '@zorimo/common';

const className = ClassNameHelper.concat('class1', null, 'class2', undefined, false, 'class3');
// className will be 'class1 class2 class3'

Advanced Usage

You can also use ClassNameHelper in more complex scenarios where conditional class names are necessary:

import { ClassNameHelper } from '@zorimo/common';

const isActive = true;
const className = ClassNameHelper.concat('class1', isActive && 'active', 'class3');
// className will be 'class1 active class3' if isActive is true

CookieProvider

Set, get, and remove cookies:

import { CookieProvider } from '@zorimo/common';

const cookieProvider = new CookieProvider();
cookieProvider.setCookie('testCookie', 'testValue', new Date(Date.now() + 3600 * 1000));

const value = cookieProvider.getCookie('testCookie'); // 'testValue'
cookieProvider.removeCookie('testCookie');

GenerateUUID

Generate a unique identifier:

import { GenerateUUID } from '@zorimo/common';

const uuid = GenerateUUID();
console.log(uuid); // e.g., 'f47ac10b-58cc-4372-a567-0e02b2c3d479'

LazySVGGenerator

Generate React components from SVG files and dynamically create files for lazy-loaded components.

How to Use

To process all SVG files in a specific folder and generate React components:

  1. Prepare your SVG files in the svgs folder.
  2. Run the following command to process the files:
npx tsx LazySVGGenerator.ts

This will generate:

  • A cleaned SVG file without fill attributes.
  • A React component (tsx file) that uses the SVG file.
  • A LazyComponent that loads the SVG lazily using React's Suspense.
  • An index.ts file for easy imports.

SVG File Configuration (svg.d.ts)

To properly import SVG files as React components, you need to configure TypeScript to understand SVG files. Add the following svg.d.ts file to your project:

declare module "*.svg" {
  import * as React from "react";
  export const ReactComponent: React.FunctionComponent<React.SVGProps<SVGSVGElement>>;
  const src: string;
  export default src;
}

This allows you to import SVG files as React components like this:

import { ReactComponent as MyIcon } from './my-icon.svg';

SVG2XML Converter

Convert SVG files into Android-compatible XML vector format, which can be used directly in Android projects.

How to Use

The svg2xml converter processes SVG files and generates XML files optimized for Android’s vector format:

  1. Place your SVG files in a folder.
  2. Use the following command to convert an SVG file:
npx tsx SVG2XML.ts <input.svg>

The output XML will include:

  • Path data extracted from SVG paths, circles, rectangles, and lines.
  • Color conversion with optional alpha transparency.
  • Gradients and animations, if present, mapped to Android-compatible attributes.

Example of Output Structure

A simple SVG input will be converted to an XML structure like:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="100dp"
    android:height="100dp"
    android:viewportWidth="100"
    android:viewportHeight="100">
    <path
        android:pathData="M0,0 L100,100"
        android:fillColor="#ff0000" />
</vector>

API

ClassNameHelper

  • concat(...names: Array<string | null | undefined | false>): string
    • Concatenates a list of class names, ignoring falsy values.

CookieProvider

  • setCookie(name: string, value: string, exp: Date): void

    • Sets a cookie with the specified name, value, and expiration date.
  • getCookie(name: string): string | null

    • Retrieves the value of the specified cookie.
  • removeCookie(name: string): void

    • Removes the specified cookie.

GenerateUUID

  • GenerateUUID(): string
    • Generates and returns a UUID (Universally Unique Identifier).

LazySVGGenerator

  • processSvgs(inputFolder: string, outputFolder: string): void

    • Processes all SVG files in the specified folder, generating React components and necessary files for lazy loading.
  • removeFillFromSvg(svgData: string): string

    • Removes the fill attributes from the SVG content.
  • getSvgDimensions(svgData: string): { width: string, height: string }

    • Extracts the width and height attributes from the SVG content.
  • createFilesForSvg(svgFile: string, inputFolder: string, outputFolder: string): void

    • Creates necessary files and directories for the given SVG file, including the React component and lazy-loaded component.
  • moveToOriginFolder(svgFile: string, inputFolder: string): void

    • Moves the original SVG file to the origin-svgs folder after processing.

SVG2XML Converter

  • convertSvgToAndroidVector(inputFile: string, outputFile: string): void
    • Converts an SVG file to an Android XML vector file format, processing paths, shapes, gradients, and animations.

Contributing

Contributions are welcome! Please open an issue or submit a pull request with your improvements.

License

This project is licensed under the MIT License - see the LICENSE file for details.