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

preeti-to-unicode-input

v1.0.3

Published

An input element or textarea to convert preeti font or nepali font to unicode with language toggle support for Nepali and english typing.

Downloads

13

Readme

Preeti to unicode input

This React component provides an input (or a textarea) field that automatically converts the user's preeti font input into Unicode format. The component is customizable and integrates seamlessly into any react-hook-form.

Features

  1. Type in Preeti font and get converted to unicode in same input box or textarea
  2. Write in preeti font or in english font in same input (using alt + i to toggle language)
  3. Customise input box and textarea
  4. Supports shadcn form, zod validation, tailwind css (see examples below)
  5. Support hrashwo akar ि as per preeti font typing. For example type ls and get कि.
  6. Provide props as required like className, style, etc. (see examples below).

Installation

Install it to your react project with npm

  npm install preeti-to-unicode-input

Usage/Examples

import PreetiToUnicodeInput from "preeti-to-unicode-input";
import { useState } from "react";

const MyForm = () => {
  const [inputValue, setInputValue] = useState("");

  return (
    <form>
      <PreetiToUnicodeInput 
        value={inputValue} 
        onChange={(val) => setInputValue(val)}
      />
    </form>
  );
};

Props

returns following dom elements that can be customised by you.

<div as container>
    <input or textarea/>
    <button for language toggle>
</div>

| Props | Optional | Parameters | Description | | :-------- | :------- | :------- | :------------------------- | | value | Optional |string| You can set value as initial props | | inputType | Optional |string| Set type of input to input or textarea by providing inputType props as "input" or "textarea". Default is input| | onChange | Optional |Functional Component| Use it if you want to process unicode value returned from component or update variable/state | | enableEnglishLanguageToggle | Optional |boolean| If you want user to enable switching english and preeti unicode in same input box.| | containerProps | Optional |React.HTMLAttributes <HTMLDivElement>| The props will be spread in container div | | inputProps | Optional |React.InputHTMLAttributes <HTMLInputElement>| The props will be spread in input element | | buttonProps | Optional |React.ButtonHTMLAttributes <HTMLButtonElement>| The props will be spread in button component |

More Examples

Example 1

import PreetiToUnicodeInput from "preeti-to-unicode-input";
import { useState } from "react";

const MyForm = () => {
  const [inputValue, setInputValue] = useState("");

  return (
    <form>
      <PreetiToUnicodeInput
            inputType="textarea"
            enableEnglishLanguageToggle={true}
            onChange={console.log} 
            inputProps={{
            placeholder: "Enter your text here",
            className: "custom-classname",
            }}
            containerProps={{ style: { width: "50%" } }}
       />
    </form>
  );
};

Example 2 Working with zod validation, zod resolver, react-hook-form and shadcn components

import { useForm } from "react-hook-form";
import { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
import PreetiToUnicodeInput from "preeti-to-unicode-input";
// Import Shadcn form components
import {
  Form,
  FormField,
  FormItem,
  FormControl,
  FormLabel,
  FormMessage,
} from "./components/ui/form";
import { Input } from "./components/ui/input";

// Define Zod schema for validation
const formSchema = z.object({
  normalInput: z
    .string()
    .min(4, { message: "Input must be at least 4 character" }),
  preetiInput: z
    .string()
    .min(3, { message: "Input must be at least 3 characters" })
    .max(50, { message: "Input must be less than 50 characters" }),
});

const MyForm = () => {
  // Initialize react-hook-form with Zod resolver
  const form = useForm({
    resolver: zodResolver(formSchema),
    defaultValues: {
      normalInput: "",
      preetiInput: "", // Default form value for the input
    },
  });

  const onSubmit = (data: any) => {
    console.log("Form Data:", data); // Log submitted form data
  };

  return (
    <Form {...form}>
      <form onSubmit={form.handleSubmit(onSubmit)}>
        <FormField
          name="normalInput"
          control={form.control}
          render={({ field }) => (
            <FormItem>
              <FormLabel>Normal Input</FormLabel>
              <FormControl>
                <Input placeholder="shadcn" {...field} />
              </FormControl>
              <FormMessage />
            </FormItem>
          )}
        />

        <FormField
          name="preetiInput"
          render={({ field }) => (
            <FormItem>
              <FormLabel>My Input</FormLabel>
              <FormControl>
                <PreetiToUnicodeInput
                  inputType="textarea"
                  enableEnglishLanguageToggle={true}
                  value={field.value}
                  onChange={field.onChange}
                  inputProps={{
                    ...field,
                    placeholder: "Type in Preeti here",
                    className: "custom-classname",
                  }}
                  containerProps={{ style: { width: "50%" } }}
                />
              </FormControl>
              <FormMessage />
            </FormItem>
          )}
        />

        <button type="submit">Submit</button>
      </form>
    </Form>
  );
};

export default MyForm;