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

bonaparte-core

v0.0.36

Published

Bonaparte UX Framework Core

Downloads

9

Readme

Bonaparte Core - API

npm version

  var bp = require('bonaparte');


bp.attribute

Utility functions that should be used to handle attributes. They automatically handle both name and data-name attributes in one go and normalize events across browsers.


bp.attribute.get();

Get an attribute from the given tag by attribute name. Automatically checks for data-[name] as well. Return: attribute value.

bp.attribute.get(
  (HTMLElement)   element,
  (String)        attributeName,
)

bp.attribute.matchName();

Compares two attribute names and checks if they are the same with: "attributeName" === "data-attributeName" Returns: true|false

bp.attribute.matchName(
  (String)      attributeName1,
  (String)      attributeName2
)

bp.attribute.remove();

Removes an attribute from the given tag. Checks automatically if the attribute exists with or without data- prefix.

bp.attribute.remove(
  (HTMLElement)   element,
  (String)        attributeName
)

bp.attribute.set();

Set an attribute on the given tag. Checks automatically if the attribute exists with or without data- prefix.

bp.attribute.set(
  (HTMLElement)   element,
  (String)        attributeName,
  (String)        value
)

bp.module

bp.module.mixin()

Combines modules into a new module Returns a module.


var module = bp.modules.mixin(
    (Function)   module,                 // Modules to be combined
    (Function)   module,                 // Modules will be instanciated in the order they they are passed to the mixin funcition.
    ...
)

Modules are combinded to an objct. Read more about the objct library here


bp.tag

bp.tag.closest();

Traverses up the element tree to find the first element that matches the given selector. Returns: Element|undefined

bp.tag.closest(
  (HTMLElement)   element,
  (querySelector) selector
)

bp.tag.contains();

Checks one Element is placed inside another. Returns: true|false

bp.tag.contains(
  (HTMLElement) parent,
  (HTMLElement) child
)

bp.tag.create();

Creates a new bonaparte-tag from modules. Returns Tag Factory.


var tag = bp.tag.create( 
    (String) name,                    // Tag name. "-bonaparte" is automatically appended.
    (Array|Function) modules,         // Modules the new tag includes.
  [ (HTMLElement) htmlBaseElement ]   // Define the html element this tag inherits from (Default: HTMLElement)
)

////////////
// Static functions

tag.register();                         // Registers tag in HTML. After calling this function, the tag can be used in HTML.
tag.initialize( (HTMLElement) tag );    // Initializes the tag on an existion HTMLElement.
tag.mixin( (Array) mixins );            // Define mixins to chustomize existing tags behaviors.      

The returned Tag Factory that can be.

  • Used as a mixin in other tags to extend their functionality.
  • Registered to the DOM with tag.register()
  • Initiated on an existing element in the DOM with tag.initialize(element)
  • Extended with modules through tag.mixin(module)

A Tag Factory is an objct. Read more about the objct library here

Static methods on modules become static methods on the Tag Factory.


bp.tag.DOMReady();

Calls the handler function when the DOM is ready. If the DOM is already completed, the handler is called imediately.

bp.tag.DOMReady(
  (function) handler
)

bp.tag.observe();

Sets on observer on the given Element. The observed element now emits bonaparte.tag.attributeChanged and bonaparte.tag.attributeUpdated events.

bp.tag.observe(
  (HTMLElement) element
)

bp.tag.triggerEvent();

Triggers a event on the given HTMLElement Returns: undefined

bp.tag.triggerEvent(
  (String)        event,
  (HTMLElement)   target,
  (Object)        data,
 [(Boolean)       bubbles = true ]
 [(Boolean)       cancelable=true]
)