Git Product home page Git Product logo

named-characters's Introduction

named-characters

Provides a collection of named character references commonly used in HTML. It offers functions to check if a character is a named character reference, retrieve information about a named character reference, and obtain an iterable of all named character references. This module is useful for handling and manipulating HTML character references in your web development projects.

Install

You can install this module using npm or yarn:

npm install named-characters

# or

yarn add named-characters

Usage

isNamedChar(char: string): boolean

You can use the isNamedChar function to check if a character is a named character reference. It returns true if the character is a named character reference, and false otherwise.

import { isNamedChar } from 'named-characters'

isNamedChar('<') // yields: true
isNamedChar('lt') // yields: true
isNamedChar('&') // yields: true
isNamedChar('&') // yields: true
isNamedChar('amp') // yields: true
isNamedChar('&amp') // yields: false
isNamedChar('amp;') // yields: false
isNamedChar('&foo;') // yields: false

getCharInfo(char: string): CharInfo | undefined

To retrieve information about a named character reference, use the getCharInfo function. It returns an object containing the name, Unicode code point, and glyph representation of the character reference. If the character is not found, it returns undefined.

import { getCharInfo } from 'named-characters'

const charInfo = getCharInfo('♥')

console.log(charInfo)

Yields:

{
  name: 'hearts',
  unicode: 'U+02665',
  glyph: '♥'
}

getCharRefs(): IterableIterator

To obtain an iterable of all named character references, you can use the getCharRefs function. It returns an iterable that allows you to iterate through all the named character references in the collection.

import { getCharRefs } from 'named-characters'

const charRefs = getCharRefs()

for (const charInfo of charRefs) {
  console.log(charInfo)
}

Yields:

{ name: 'AElig', unicode: 'U+000C6', glyph: 'Æ' }
{ name: 'AMP', unicode: 'U+00026', glyph: '&' }
{ name: 'Aacute', unicode: 'U+000C1', glyph: 'Á' }
{ name: 'Abreve', unicode: 'U+00102', glyph: 'Ă' }
{ name: 'Acirc', unicode: 'U+000C2', glyph: 'Â' }
...

Related

  • attributes-parser - Tokenize and parse attributes string into meaningful tokens and key-value pairs.

Contributing

We 💛  issues.

When committing, please conform to the semantic-release commit standards. Please install commitizen and the adapter globally, if you have not already.

npm i -g commitizen cz-conventional-changelog

Now you can use git cz or just cz instead of git commit when committing. You can also use git-cz, which is an alias for cz.

git add . && git cz

License

GitHub

A project by Stilearning © 2023.

named-characters's People

Contributors

bent10 avatar renovate[bot] avatar semantic-release-bot avatar

Stargazers

 avatar

Watchers

 avatar  avatar

named-characters's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/pr-title.yml
  • actions/checkout v4
  • clowdhaus/actions v0.4.0
.github/workflows/release.yml
  • actions/checkout v4
  • actions/setup-node v4
.github/workflows/validate.yml
  • actions/checkout v4
  • actions/setup-node v4
npm
package.json
  • doogu 3.2.12

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.