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

@nagwa-limited/kashida-engine

v0.1.4

Published

An engine to unify array of Arabic strings to the same width using Kashidas

Downloads

174

Readme

Kashida Engine

A kashida engine that adds kashida to poem lines to unify their widths to match the widest text.

Table of Content

1. Getting Started

These instructions will guide you to consume the API provided by the app.

1.1. Installation

Following these instructions will integrate the app into your website and will provide a globally defined API to be used. Also, if you're using the Script tag method then the app will automatically add kashidas to the poem lines if the following structure is found in DOM, if not then check the Documentation to manually invoke the required functions.

<element class="poem">
  <element class="linesGroup">
    <div>
      <div> [The line should exist here] </div>
    </div>
  </element>
  <element class="linesGroup">
    <div>
      <div> [The line should exist here] </div>
      <div> [The line should exist here] </div>
    </div>
  </element>
</element>

1.1.1. Using script tag

  1. Download the latest version of the app.

  2. Link the app's Javascript file in the body of your HTML File. Example:

    <body>
      <script src="/static/js/kashida-engine.js"></script>
    </body>

1.1.2. Using npm

Run the following command:

npm i kashida-engine

1.2. Documentation

Here will explain the API provided by our app that can be found under the globally defined namespace NagwaHTMLEditor.

1.2.1. API Interface

The KashidaEngine is implementing the following interface:

interface KashidaEngine  {
    unifyTextsWidths: (texts: string[], font: string) => string[]
    renderKashidaToPoems: (poemSelector?: string, lineSelector?: string) => void
    renderKashidaToPoems: (e?: Event) => void
    getTextWidth: (text: string, font: string) => number
    getTextsWidths: (texts: string[], font: string) => TextWidths
}

interface TextWidths {
  textWidths: number[]
  maxTextWidth: number
}

1.2.2. API Explanation

Here's an explanation of the provided API:

  • KashidaEngine:
    • unifyTextsWidths: Unifies the widths of all the inputted texts to match the max width.
    • renderKashidaToPoems: Has two overloads to render all the poem lines after adding kashida to it and unifying all its widths for all the poems available on page and still be able to use it as an event handler by using the second overload that accepts an Event as an argument.
    • getTextWidth: Uses canvas.measureText to compute and return the width of the given text of given font in pixels.
    • getTextsWidths: Uses getTextWidth to compute and return the widths of the given texts of given font in pixels and the max width of all the sentences.
  • TextWidths:
    • textWidths: An array of the width of the sentences.
    • maxTextWidth: The maximum width of all of these widths.

2. Forking Guide

These instructions will get you a copy of the project up and running on your local machine.

2.1. Prerequisites

You have to have Node.js v17.2.0, and npm v8.1.4 installed. Also, check ./package.json for all the packages used in this project.

2.2. Installing

Clone this repo, open the terminal and navigate to the repo directory on your local machine, and then run:

npm install

wait until it's done and you're good to go!

3. Built With

4. Main Features

  • Unify the poem lines widths with kashidas if the expected structure is met.
  • Provide a method in the public API to manually run the unifying widths method.
  • Provide a method in the public API to manually run the method that calculates the widths.
  • Provide a method in the public API that adds kashidas to a list of strings.

5. Git Style

5.1. Message Structure

A commit messages consists of three distinct parts separated by a blank line: the title, an optional body and an optional footer. The layout looks like this:

type: subject

body

5.1.1. The Type

The type is contained within the title and can be one of these types:

  • feat: a new feature
  • fix: a bug fix
  • docs: changes to documentation
  • style: formatting, missing semi colons, etc; no code change
  • refactor: refactoring production code
  • test: adding tests, refactoring test; no production code change
  • chore: updating build tasks, package manager configs, etc; no production code change

5.1.2. The Subject

Subjects should be no greater than 50 characters, should begin with a capital letter and do not end with a period.

Use an imperative tone to describe what a commit does, rather than what it did. For example, use change; not changed or changes.

5.1.3. The Body

Not all commits are complex enough to warrant a body, therefore it is optional and only used when a commit requires a bit of explanation and context. Use the body to explain the what and why of a commit, not the how.

When writing a body, the blank line between the title and the body is required and you should limit the length of each line to no more than 72 characters.

For more information about the style guide for Git and programming Languages check: Udacity's Code Style Guide or Conventional Commits