Giter VIP home page Giter VIP logo

utilify's Introduction

  • Parameter validator

  • Hot reloading

  • Info Proxy

doc

paramProxy(target, conf)

Verification parameter

  • target: Original object
  • conf: default value
index.test.js
let util = require('./index')

let data = {
  number1: '1',
  string1: 2,
  boolean1: 'true',
  object1: {a: 1},
  array1: [1, 'a'],
  database1: ';show tables',
  anyone1: 'abc'
}
// int,str,bool,obj,arr,db  They are Parameter Types
let {
  int: {number1},
  str: {string1},
  bool: {boolean1},
  obj: {object1},
  arr: {array1},
  db: {database1},
  anyone1,
  aab,
  RESULT,  // It is a mandatory parameter before it, after which it is an optional parameter
  xyz,
} = util.pramProxy(data)
// let aab=1
console.log(number1, string1, boolean1, object1, array1, database1, anyone1, aab, RESULT, xyz)

----------------------------------------------------------------------------------------------
> node index.test.js
1 '2' true { a: 1 } [ 1, 'a' ] '\';show tables\'' 'abc' null 'aab is null or TYPE err' null 

hotReload()

hot reloading code

hot-reload.js
let Node = (param) => {
  console.log('real-time-func',param,12)
}
Node.id = 123

module.exports = Node
index.test.js
let util = require('./index')

util.hotReload(__dirname) // watch path

let d = require('./hot-reload')

if (!global.i) global.i = 1
 
setInterval(() => {
  d(++global.i) // d(--global.i)  Modify it  
  console.log('real-time-value',d.id)
}, 2000)

---------------------------------------------------------------------
> node index.test.js
real-time-func 666 12
real-time-value 123
hot reloaded  C:\Users\Administrator\Desktop\git\utilify\index.test.js
real-time-func 66611 12
real-time-value 123

Used in Babel

Experimental

babel.test.js
require('babel-register')
require('babel-polyfill')
const path = require('path')
const util = require('./index')
const watch_path = path.join(__dirname, './src')
util.hotReload(watch_path)

// edit es6 code

import api from './src/api'

...

infoProxy()

console.log proxy

index.test.js
let util = require('./index')

util.infoProxy()

console.log(123)

-----------------------------------------------------------------
> node index.test.js
123
at (C:\Users\Administrator\Desktop\git\utilify\index.test.js:38:9)

test

> node index.test.js

TODO

paramProxy()

  • More configuration items
  • Hot updates when deleting files

hotReload()

  • Join non-updateable configuration
  • Remove references

With multiple methods...

utilify's People

Stargazers

 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.