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

ojs-core

v1.13.0

Published

Open source JavaScript library for creating Object-oriented Web user interfaces.

Downloads

41

Readme

ojs-core

Open source JavaScript library for creating Object-oriented Web user interfaces. Core OrangutanJS module.

Install using npm:

npm i -D ojs-core

Quick start

input:
import o from 'ojs-core';
(...)

o('div').class('section border').id('first_section').add(
    o('h1').class('section__header').text('Hello oJS!!'),
    o('p').class('section__paragraph').text('This is OrangutanJS.')
]);
output:
<div class="section border" id="first_section">
    <h1 class="section__header">Hello oJS!</h1>
    <p class="section__paragraph">This is OrangutanJS.</p>
</div>

Render ojs to DOM:

import o, { oRender } from 'ojs-core';

const ojsContent = o('div').class('section border').id('first_section').add(
    o('h1').class('section__header').text('Hello oJS!!'),
    o('p').class('section__paragraph').text('This is OrangutanJS.')
]);

oRender(
    document.body,
    ojsContent
);

oJS instance

Before you use init method ojs instance is an object that you can work with using various methods.

o('div');           // o{ element: div, (...)}
o('div').init();    // <div></div>

You don't need to use init method when you are using oRender method. oRender would do it on its own.

oRender

oRender(parentNode: HTMLElement, childNode: HTMLElement | ojsInstance, cleanParentContent: boolean = false)

oFragment

oFragment is shadowElement where you can add multiple elements without creating unnecessary HTML Element.

oFragment(children: Array<HTMLElement|ojsInstance>)

Important: You can pass children in Array or just separated by a comma.

Example:

import o, { oRender, oFragment } from 'ojs-core';

oRender(
    document.body,
    oFragment(
        o('p').text('p1'),
        o('p').text('p2')
    )
)

Result:

<body>
    <p>p1</p>
    <p>p2</p>
</body>

.add()

You don't have to pass children elements right away when creating oFragment instance

Example:

import o, { oFragment } from 'ojs-core';

const fragment = oFragment();
const paragraphs = ['p1', 'p2'];

fragment.add(
    paragraphs.map(paragraph => o('p').text(paragraph))
)

oFragment - .init()

Init method returns Array of all children from instance;

Example:

const fragment = oFragment(
    o('p').text('p1').init(),
    o('p').text('p2').init()
);

fragment.init();
// [
//  <p>p1</p>,
//  <p>p2</p>
// ]

oDom

oDom allows to get element from DOM using query selector (css selectors). Returns ojs object. Returns null in all other cases (element not found or wrong arguments);

oDom(selector: String, parentNode: DOMElement|ojsInstance = document)
  • selector - query selector (css selector)
  • parentNode - element in the node of which we are looking for wanted element. Default parentNode is document.

Important - oDom returns always only one element!

Example:

import o,{ oDom } from 'ojs-core';

const pElement = oDom('#someParagraph');

pElement.text('new paragraph text set using ojs API');

Dev notes:

To run playground:

remove "type": "module" from package.json and

npm run dev