Giter VIP home page Giter VIP logo

html-class's Introduction

html-class build status

A basic utility to retrieve DOM nodes names from their constructors and vice-versa.

API

Right now this module has two methods: htmlClass.get(...) and htmlClass.set(...).

The purpose of this API is to maintain in a single module all relations between HTML constructors and relative nodes. This module is environment agnostic and it does not require any DOM understand from the engine.

htmlClass.get(...)

The .get(...) method has 3 overloads. Following their description.

htmlClass.get(nodeName:string):string

Given a generic DOM node name, it returns its constructor name.

const htmlClass = require('html-class');

// for known elements
// logs: 'HTMLAnchorElement'
htmlClass.get('a');

// unknown elements, empty string
// logs: ''
htmlClass.get('not-registered');

htmlClass.get(Class:string):Array

Given a generic DOM Class name, it returns a collection of elements that inherits form that prototype.

const htmlClass = require('html-class');

// for known constructors
// logs: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']
htmlClass.get('HTMLHeadingElement');

// logs: ['button']
htmlClass.get('HTMLButtonElement');


// unknown constructors, empty Array
// logs: []
htmlClass.get('NotRegistered');

htmlClass.get(re:RegExp):Array

Given a generic regular expression, it returns a collection of elements or constructors that matched such test.

// returns ['HTMLButtonElement']
htmlClass.get(/^HTMLButton/);

// returns all known/registered custom elements
// ['my-el', 'x-form', 'some-data']
htmlClass.get(/^[a-z]+-/);

htmlClass.set(...)

The .set(...) method has 2 overloads. Following their description.

htmlClass.set(nodeName:string, Class:string):htmlClass

If not previously registered, adds nodeName to the list and associate it with the Class.

// register a generic custom element
htmlClass.set('my-custom-element', 'MyCustomElement');

// logs: 'MyCustomElement'
htmlClass.get('my-custom-element');
// logs: ['my-custom-element']
htmlClass.get('MyCustomElement');

// if repeated, nothing happens
htmlClass.set('my-custom-element', 'MyOtherElement');

// if another component wasn't registered though
// it will be added to the generic constructor list
htmlClass.set('my-other-element', 'MyCustomElement');

// logs: ['my-custom-element', 'my-other-element']
htmlClass.get('MyCustomElement');

htmlClass.set(Class:string, nodeName:string):htmlClass

Does exactly the same thing htmlClass.set(nodeName, Class) does, assuming by specs constructors are PascalCase and node names are either fully lower or upper case.

Compatibility

The code is compatible with every JavaScript engine, old or new, either via browser or server.

html-class's People

Contributors

webreflection avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

html-class's Issues

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.