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

dom-crud

v2.1.0

Published

let't crud dom but not database

Downloads

15

Readme

👉 Install

  • If use with script tag, you need to invoke apis using crud. prefix :
<script src="https://unpkg.com/dom-crud@latest/build/index.umd.min.js"></script>
<script>
    // using crud as a namespace to invoke methods
    crud.methodName(...)
</script>
  • If use as es module: npm i dom-crud or yarn add dom-crud :
import { methodName } from "dom-crud"
// detail usage are below

👉 Basic Knowledge

Before going on, there are some terms you should know :

  • Sign represents a string contains two character, there are three signs :

    • == mean overwrite/replace
    • -= mean delete
    • += mean append
  • KVS string (short for "Key Value Sign") is a function parameter format in string style what will be used often:there are some [Builtin Keys](#Builtin Keys) for use, every other keys will be used with setAttribute method. Examples :

    • class-=a b c
    • style==color:red;font-size:2rem
    • html+=<span>hi</span>
    • id==a
  • KVSC string ("C" is short for "Config"), because some keys can have additional configs, details will discuss later. Examples :

    • id==a?configA=xx&configB=yy
  • KVS object is a function parameter format in object style what will be used often. Examples :

    • { 'id==': {value:'a'}}
    • you can also specify value directly: { 'id==':'a'} is equal to above
    • { 'class-=': {value: 'a b c'}} or { 'class-=': 'a b c'}
    • { 'style==': 'color:red;font-size:2rem'}
    • { 'html+=': '<span>hi</span>'}
  • KVSC object , Example :

    • use config key and value key at the same time if you need to pass configs: { 'text==': { value:"new text", config: {purText: true} }}

👉 API

cdom(htmlTagName, strOrObj1, strOrObj2, strOrObj3, strOrObj4, ...)

  • htmlTagName : string
  • strOrObj : KVS(C) string or KVS(C) object)
  • **return ** : HtmlElement
import {cdom} from 'dom-crud'

// below will create a dom like this:
// <input type='text' class='center big red' style='font-size:3rem;font-weight:bold'/>

// you can pass only KVS strings
const $input = cdom('input', 
'class==center big red', 
'style==font-size:3rem;font-weight:bold', 
'type==text'
);

// or pass only KVS objects
const $input2 = cdom('input', 
{
  'class==': 'center big red',
  'style==': "font-size:3rem;font-weight:bold",
}, 
{
  'type': 'text'
});

// or mixed
const $input3 = cdom('input', 
'class==center big red',
{
  'style==': "font-size:3rem;font-weight:bold",
  'type==': 'text'
});

rdom(selector)

  • selector : string same as querySelector
  • return : HtmlElement
import {rdom} from 'dom-crud'

// when reading single dom, you can chain it
const $input = rdom('.center').rdom('.word').rdom('.c'); 

rdoms(selector)

  • selector : string same as `querySelectorAll
  • **return **: NodeList
import {rdoms} from 'dom-crud'

// multi doms cannot chain
const $inputs = rdoms('input'); 

udom(dom, strOrObj1, strOrObj2, strOrObj3, strOrObj4, ...);

  • dom : Element
  • strOrObj : KVS(C) string or KVS(C) object
  • return : void
import {udom, rdom} from 'dom-crud'

// below will remove all inline styles and then add blue color
udom(rdom('input'), 'style==color:blue;');
// object style
udom(rdom('input'), {
    'style==':'color:blue'
});


// below will only remove color and font-size from inline styles if exists
udom(rdom('input'), 'style-=color;font-size')
// object style
udom(rdom('input'), {
    'style-=':'color;font-size'
})

// below will append color to inline styles
udom(rdom('input'), 'style+=color:blue;')
// object style
udom(rdom('input'), {
    'style+=':'color:blue'
})

ddom(dom)

  • dom : Element
  • return : boolean whether or not removed dom
import {ddom, rdom} from 'dom-crud'

ddom(rdom('input')); 

getCrudConfig()

  • return : global config object

    currently, the default global config is very simple as below:

import { getCrudConfig } from 'dom-crud'
const config = getCrudConfig();
console.log(config);
/*
{
  text: {
    // detailed below
    pureText: false
  },
  // whether log debug info(currently, nothing cumbersome logged)
  debug: false
} 
*/

updateCrudConfig(config)

  • config : it should be a subset of global config object, anything else will be ignored
  • return : void
import { getCrudConfig, updateCrudConfig } from 'dom-crud'
const config = getCrudConfig();
updateCrudConfig({
    text: {
        pureText: true,
        elseConfig: 'yes' // ignored because global config not contains this
    },
})

👉 Builtin Keys

Below list all builtin keys which made dom-crud funny. Remind: any other keys will be used in setAttribute(key, value)

text

This key modifies text conent in target dom, V(value) should be string. This key's configs as below:

| name | type | description | | -------- | --------- | ------------------------------------------------------------ | | pureText | boolean | If your dom content is 100% plain text, set it to true to make performance boost. This config can be changed by global config. |

html

This key modifies html content in target dom, V(value) should be string.

doms

This key modifies doms in target dom,V(value) should be one of below :

  • array contains Emelent
  • NodeList
  • ``HTMLCollection`

This key's configs as below:

| name | type | description | | ------ | --------- | ---------------------------------------------- | | before | Element | Remind: Element should child of parent element |

style

This key modifies dom inline styles.

class

This key modifies dom classes.

For more keys? Please give me advice🤣