Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

micro-definition

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

micro-definition - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

dist/micro-definition.js

6

dist/micro-definition.min.js
/*!
* @ProjectName micro-definition
* @Version 0.0.3
* @Version 0.0.4
* @Author lixinliang(https://github.com/lixinliang)
* @Update 2016-09-29 8:39:12 pm
* @Update 2016-11-30 2:05:40 pm
*/
!function(n){function t(o){if(e[o])return e[o].exports;var r=e[o]={exports:{},id:o,loaded:!1};return n[o].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var e={};return t.m=n,t.c=e,t.p="",t(0)}([function(n,t){"use strict";function e(n){throw new TypeError("micro-definition: "+n)}function o(){}function r(n,t,e){var i=n.length;i?!function(){var d=function(){i--,i||e(t.apply(window,p))},l=function(n,t,e,o){var i=n.dependency,c=n.content,u=new Function("return "+c)();r(i,u,function(n){a[t]=p[e]=n,d(),o()})},p=[];n.forEach(function(n,t){if("function"==typeof u[n]&&(n=u[n].call(u)),a[n])p[t]=a[n],d();else{var e=c(n);e?l(e,n,t,o):u[n]?f[n]?f[n].push(function(){p[t]=a[n],d()}):!function(){f[n]=[];var e=document.createElement("script");e.src=u[n],e.onload=function(){document.head.removeChild(e);var o=c(n);l(o,n,t,function(){f[n].forEach(function(n){n()})})},document.head.appendChild(e)}():(p[t]=a[n]=void 0,d())}})}():e(t())}function i(n,t,i){arguments.length<2&&e("2 arguments required at least."),"string"!=typeof n?(i=t,t=n,n=null):n||e("Module id can not be empty."),t instanceof Array||(i=t,t=[]),"function"!=typeof i&&e("Module should be a function."),n?c(n,{dependency:t,timestamp:+new Date,content:i.toString()}):r(t,i,o)}var c=microStorage("micro-definition"),u={},a={},f={};i.alias=function(n){for(var t in n)u[t]=n[t]},i.version="0.0.3",i.storage=c,window.define=i}]);
!function(n){function e(o){if(t[o])return t[o].exports;var r=t[o]={exports:{},id:o,loaded:!1};return n[o].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var t={};return e.m=n,e.c=t,e.p="",e(0)}([function(n,e){"use strict";function t(n){throw new TypeError("micro-definition: "+n)}function o(){}function r(n,e,t){var i=n.length;i?!function(){var d=function(){i--,i||t(e.apply(window,s))},l=function(n,e,t,o){if(n){var i=n.dependency,c=n.content,u=new Function("return "+c)();r(i,u,function(n){a[e]=s[t]=n,d(),o()})}else a[e]=s[t]=new SyntaxError('micro-definition: "'+e+'" is not defined'),d(),o()},s=[];n.forEach(function(n,e){if("function"==typeof u[n]&&(n=u[n].call(u)),a[n])s[e]=a[n],d();else{var t=c(n);t?l(t,n,e,o):u[n]?f[n]?f[n].push(function(){s[e]=a[n],d()}):!function(){f[n]=[];var t=document.createElement("script");t.src=u[n],t.onload=function(){document.head.removeChild(t);var o=c(n);l(o,n,e,function(){f[n].forEach(function(n){n()})})},document.head.appendChild(t)}():(s[e]=a[n]=void 0,d())}})}():t(e())}function i(n,e,i){arguments.length<2&&t("2 arguments required at least."),"string"!=typeof n?(i=e,e=n,n=null):n||t("Module id can not be empty."),e instanceof Array||(i=e,e=[]),"function"!=typeof i&&t("Module should be a function."),n?c(n,{dependency:e,timestamp:+new Date,content:i.toString()}):r(e,i,o)}var c=microStorage("micro-definition"),u={},a={},f={};i.alias=function(n){for(var e in n)u[e]=n[e]},i.version="0.0.4",i.storage=c,window.Define=i}]);
{
"name": "micro-definition",
"version": "0.0.3",
"description": "(<2kb) A lite module definition tool.",
"version": "0.0.4",
"description": "(<2kb) A lite module loader and cache module in localStorage.",
"main": "dist/micro-definition.min.js",

@@ -6,0 +6,0 @@ "scripts": {

@@ -0,3 +1,7 @@

[![npm](https://img.shields.io/npm/l/micro-definition.svg?style=flat-square)](https://www.npmjs.org/package/micro-definition)
[![npm](https://img.shields.io/npm/v/micro-definition.svg?style=flat-square)](https://www.npmjs.org/package/micro-definition)
[![npm](https://img.shields.io/npm/dm/micro-definition.svg?style=flat-square)](https://www.npmjs.org/package/micro-definition)
# micro-definition
> (<2kb) A lite module definition tool.
> (<2kb) A lite module loader and cache module in localStorage.

@@ -13,8 +17,12 @@ ## Try it now

## Dependency
* [micro-storage](https://github.com/micro-app/micro-storage)
## How to use
#### Define a module
define(String: id, Function: method);
```
define('mod', function () {
Define(String: id, Function: method);
```javascript
Define('mod', function () {
// some code;

@@ -26,5 +34,5 @@ return value;

#### Define a module with dependencies
define(String: id, Array: Dependency, Function: method);
```
define('mod-a', ['mod-b', 'mod-c'], function ( b, c ) {
Define(String: id, Array: Dependency, Function: method);
```javascript
Define('mod-a', ['mod-b', 'mod-c'], function ( b, c ) {
// some code;

@@ -36,5 +44,5 @@ return value;

#### Use modules
define(Array: Dependency, Function: method);
````
define(['jQuery', 'lodash'], function ( $, _ ) {
Define(Array: Dependency, Function: method);
````javascript
Define(['jQuery', 'lodash'], function ( $, _ ) {
// some code;

@@ -45,4 +53,4 @@ });

#### Config of alias
````
define.alias({
````javascript
Define.alias({
'mod-a' : 'a.js',

@@ -53,11 +61,11 @@ 'mod-b' : 'b.js',

#### Show definitional modules
#### Show all defined modules
````javascript
Define.storage.list();
````
define.storage.list();
````
#### Remove a definitional module
#### Remove a defined module
````javascript
Define.storage.remove('mod-a');
````
define.storage.remove('mod-a');
````

@@ -64,0 +72,0 @@ ## License

@@ -47,14 +47,22 @@ /**

function loadModule ( result, id, index, callback ) {
let { dependency, content } = result;
let method = new Function('return ' + content)();
resolve(dependency, method, function ( value ) {
cache[id] = args[index] = value;
if (result) {
let { dependency, content } = result;
let method = new Function('return ' + content)();
resolve(dependency, method, function ( value ) {
cache[id] = args[index] = value;
done();
callback();
});
} else {
cache[id] = args[index] = new SyntaxError(`@NAME: "${ id }" is not defined`);
done();
callback();
});
}
}
dependency.forEach(function ( id, index ) {
// alias redirect
if (typeof alias[id] == 'function') {
id = alias[id].call(alias);
}
// get from cache
if (cache[id]) {

@@ -64,2 +72,3 @@ args[index] = cache[id];

} else {
// get from storage
let result = storage(id);

@@ -69,4 +78,6 @@ if (result) {

} else {
// get from network
if (alias[id]) {
if (loading[id]) {
// push in queue when loading
loading[id].push(function () {

@@ -92,2 +103,3 @@ args[index] = cache[id];

} else {
// not exist then skip
args[index] = cache[id] = void 0;

@@ -110,3 +122,3 @@ done();

*/
function define ( id, dependency, method ) {
function Define ( id, dependency, method ) {
if (arguments.length < 2) {

@@ -129,3 +141,3 @@ throwError('2 arguments required at least.');

if (typeof method != 'function') {
throwError('Module should be a function.')
throwError('Module should be a function.');
}

@@ -147,3 +159,3 @@ if (id) {

*/
define.alias = function ( config ) {
Define.alias = function ( config ) {
for (let id in config) {

@@ -154,5 +166,5 @@ alias[id] = config[id];

define.version = '@VERSION';
define.storage = storage;
Define.version = '@VERSION';
Define.storage = storage;
window.define = define;
window.Define = Define;

@@ -1,4 +0,4 @@

define('mod-b', ['mod-c'], function ( c ) {
Define('mod-b', ['mod-c'], function ( c ) {
console.log('i am mod-b');
return 'mod-b,' + c;
});

@@ -1,4 +0,4 @@

define('mod-c', function () {
Define('mod-c', function () {
console.log('i am mod-c');
return 'mod-c';
});

@@ -91,8 +91,17 @@ 'use strict';

if (process.argv[process.argv.length-1] == '--build=js') {
let output = {
path : './dist/',
filename : '[name].min.js',
};
module.exports.plugins.shift();
process.argv.forEach(( param ) => {
if (/^--/.test(param)) {
let temp = param.slice(2).split('=');
let key = temp[0];
let value = temp[1] || true;
process.argv[key] = value;
}
});
if (process.argv.build == 'js') {
if (process.argv.uglify) {
module.exports.plugins.shift();
} else {
module.exports.plugins.splice(3, 1);
module.exports.plugins.shift();
}
let loaders = module.exports.module.loaders;

@@ -102,7 +111,8 @@ loaders[3].loaders = ['css', 'autoprefixer'];

loaders[3].loader = loaders[4].loader = void 0;
process.argv.slice(-3).slice(0, 2).forEach(( argument ) => {
let result = argument.trim().replace('--', '').split('=');
output[result[0]] = result[1];
});
module.exports.output = output;
module.exports.output = {
path : './dist/',
filename : `[name]${ process.argv.uglify ? '.min' : '' }.js`,
library : process.argv.library,
libraryTarget : process.argv.libraryTarget,
};
}

@@ -23,3 +23,5 @@ 'use strict';

if (/listen EADDRINUSE/.test(err.toString())) {
step6().then(step7).then(step8).catch(( err ) => {
console.log(`\n${ port } is aleary in use. Ctrl+C to leave or input a PID to kill:`.green);
cmd = `lsof -i tcp:${ port }`;
step4().then(step6).then(( pid ) => cmd = `kill ${ pid }`).then(step4).catch(( err ) => {
console.log(err.toString().red);

@@ -35,3 +37,5 @@ }).then(start);

if (process.argv[3] && process.argv[3] == 'js') {
step3().then(step9).then(step10).then(( option ) => cmd += option).then(step1).then(step4).then(() => {
step3().then(step7).then(step8).then(( option ) => cmd += option).then(step1).then(step4).then(() => {
cmd += ' --uglify';
}).then(step4).then(() => {
console.log('build complete!'.green);

@@ -118,4 +122,4 @@ }).catch((err) => {

/**
* [step4] shell.exec -- Run webpack
* @return {Promise} run_webpack_success
* [step4] shell.exec -- Exec command
* @return {Promise} exec_command_success
*/

@@ -153,3 +157,3 @@ let step4 = () => new Promise(( resolve, reject ) => {

let url = match.substring(0, match.length - 1).substring(4);
if (/^http(s?):\/\/|data:image/.test(url)) {
if (/^http(s?):\/\/|^data:image/.test(url)) {
return match;

@@ -178,20 +182,6 @@ } else {

/**
* [step6] shell.exec -- List open files
* @return {Promise} list_files_success
* [step6] inquirer.prompt -- Get PID
* @return {Promise} get_pid_success
*/
let step6 = () => new Promise(( resolve, reject ) => {
console.log(`\n${ port } is aleary in use. Ctrl+C to leave or input a PID to kill:`.green);
let result = shell.exec(`lsof -i tcp:${ port }`);
if (result.code === 0) {
resolve();
} else {
reject(result.stderr);
}
});
/**
* [step7] inquirer.prompt -- Get PID
* @return {Promise} get_pid_success
*/
let step7 = () => new Promise(( resolve, reject ) => {
inquirer.prompt([{

@@ -209,19 +199,6 @@ type : 'input',

/**
* [step8] shell.exec -- Kill PID
* @return {Promise} kill_pid_success
*/
let step8 = ( pid ) => new Promise(( resolve, reject ) => {
let result = shell.exec(`kill ${ pid }`);
if (result.code === 0) {
resolve();
} else {
reject(result.stderr);
}
});
/**
* [step9] inquirer.prompt -- Get js file
* [step7] inquirer.prompt -- Get js file
* @return {Promise} get_js_success
*/
let step9 = ( entry ) => new Promise(( resolve, reject ) => {
let step7 = ( entry ) => new Promise(( resolve, reject ) => {
let choices = Object.keys(entry);

@@ -257,6 +234,6 @@ if (choices.length) {

/**
* [step10] fs.readFile -- Get js webpack config
* [step8] fs.readFile -- Get js webpack config
* @return {Promise} get_config_success
*/
let step10 = ( filepath ) => new Promise(( resolve, reject ) => {
let step8 = ( filepath ) => new Promise(( resolve, reject ) => {
fs.readFile(filepath, (err, buffer) => {

@@ -263,0 +240,0 @@ if (err) {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc