Code Monkey home page Code Monkey logo

mei.js's Introduction

Mei.js

a minimal, simple and helpful library for you

โญ Star the project

With your star in the project, you help us to make ourselves known and the project to continue. Thank you very much!

Documentation

You can also find the documentation on the website.

DOM Manipulation:

Get Elements:

  <h1 id="title">Mei.Js</h1>
  <ul id="list-container">
    <li class="item">Item-1</li>
    <li class="item">Item-2</li>
    <li class="item">Item-3</li>
  </ul>
 // Return, if exist, the element, if not return null
 let element = Mei.getElement('#title');
 // Return an array of all selected elements
 let elements = Mei.getElements('.item'); 

Events:

Set Events:

  <h1 id="title">Mei.Js</h1>
  <ul id="list-container">
    <li class="item">Item-1</li>
    <li class="item">Item-2</li>
    <li class="item">Item-3</li>
  </ul>
 // Event for the h1 
 Mei.getElement('#title', 'click', () => {
   console.log('#title clicked!');
 });

 // This is not so recommended, use event delegation instead.
 Mei.getElements('.item', 'click', () => {
   console.log('item clicked!');
 });

Elements:

Creation:

  <div id="container">

  </div>
  <ul id="list">

  </ul>
 // This will create a 'h1'
 Mei.createElement('h1', {
   textContent: 'Hello World!',
   className: 'title',
   id: 'title-js',
   parent: Mei.getElement('#container')
 });

 // Create Children's
 Mei.createElement('li', {
   textContent: 'Item',
   className: 'item',
   parent: Mei.getElement('#list'),
   children: [
     {element: 'a', textContent: ' x', href: '#'}
   ]
 });

Removing:

  <h1 id="title">Title</h1>
 // This will remove the 'h1'
 Mei.removeElement(Mei.getElement('#title'));

Cloning:

  <h1 id="title">Title 1</h1>
 // Cloning the 'h1'
 let copiedH1 = Mei.cloneElement(Mei.getElement('#title'));
 // output
 console.log(copiedH1);

Storage: Work with the API storage in a more easy way

Save data:

 
  let users = [{name: 'John'}, {name: 'Nick'}];
  // This will create a 'users' item/collection in a localStorage way.      
  Mei.store({
    store: 'local',
    item: 'users',
    data: users
  });

  // This will create a 'users' item/collection in a sessionStorage way.
  Mei.store({
    store: 'session',
    item: 'users',
    data: users
   });

Clear all the stored data:

  // This will delete all the localStorage data     
  Mei.clearStore('local');

  // This will delete all the sessionStorage data  
  Mei.clearStore('session');

Remove a specified item from the store:

  // This will delete only the 'users' item (if exist) from localStorage     
  Mei.removeItemStore('local', 'users');

  // This will delete only the 'users' item (if exist) from sessionStorage     
  Mei.removeItemStore('session', 'users');

Get all the records, if is empty returns a empty array:

  // This will display the 'users' item (if exist) from localStorage     
  let allUsersFromLocal = Mei.displayStore('local', 'users');
  console.log(allUsersFromLocal);
  
  // This will display the 'users' item (if exist) from sessionStorage     
  let allUsersFromSession = Mei.displayStore('session', 'users');
  console.log(allUsersFromSession);

mei.js's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.