Icontem

Vanilla JS Require: Require classes in a Web browser and Node.js

Recommend this page to a friend!
  Info   View files Example   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2019-04-27 (23 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 5 All time: 539 This week: 4Up
Version License JavaScript version Categories
vanilla-require 1.0GNU General Publi...5Node.js, Language, Libraries
Description Author

This package can require classes in a way that works in a Web browser and Node.js.

It implements a require functionality making a class load dynamically from a given file when running on Node.js or load via a HTTP request when running from browser.

This way the same class code can be used in a similar way on the Web or on the server side using Node.js.

  Performance   Level  
Name: Leonardo Mauro Pereira ... <contact>
Classes: 5 packages by
Country: Brazil Brazil
Age: 24
All time rank: 16116 in Brazil Brazil
Week rank: 21 Up3 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 3x

Winner: 3x

Details

vanilla-require

GPLv3 license npm JsClasses GitHub Codacy Badge

The Node.js and npm have an incredible system for the inclusion of packages, made by require. However, for use packages one must export their modules, through module.exports. Yet, it is not possible to use these packages on simple web classes because the web browser does not recognize the module.exports.

This package allows you to develop simple classes to the web and export them to Node.js script as a module. In this sense, you can use your classes in the web browser (pure Javascript) and in the Node.js script, using the vanilla-require package.

Vanilla JS: pure Javascript.

Installation

npm install --save vanilla-require

Example

See test/test.js for another example.

A Vanilla class (Calculator.js):

class Calculator {

    sum(num1, num2){
        return num1+num2;
    }
}

Your Node code:

/Include/
const vr = require('vanilla-require')(__dirname);
// Instance a Vanilla Class
const Calculator = vr.require('Calculator.js');

// Enjoy the Class!
let myCalc = new Calculator(),
    a = 2, b = 3;

console.log('a:'+a+' b:'+b)
console.log('sum:'+myCalc.sum(a, b));

---

Also look ~

  Files folder image Files  
File Role Description
Files folder imagetest (2 files)
Plain text file lib.js Class Class source
Accessible without login Plain text file LICENSE Example Example script
Accessible without login Plain text file package-lock.json Data Auxiliary data
Accessible without login Plain text file package.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Class source

  Files folder image Files  /  test  
File Role Description
  Plain text file Calculator.js Class Class source
  Accessible without login Plain text file test.js Example Example script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:5
This week:0
All time:539
This week:4Up