feature(util) Util.type -> itype

This commit is contained in:
coderaiser 2016-12-28 17:26:30 +02:00
parent fc058fcfa7
commit f35585b3ac
21 changed files with 332 additions and 100 deletions

View file

@ -42,6 +42,7 @@
"promise-polyfill": "6.0.2",
"smalltalk": "2.1.3",
"jquery": "3.1.1",
"currify": "2.0.3"
"currify": "2.0.3",
"itype": "2.0.3"
}
}

View file

@ -1,3 +1,5 @@
/* global itype */
var Util, DOM, CloudFunc, join;
(function(scope, Util, DOM, CloudFunc) {
@ -19,8 +21,7 @@ var Util, DOM, CloudFunc, join;
Images = DOM.Images,
Info = DOM.CurrentInfo,
CloudCmd = this,
Storage = DOM.Storage,
type = Util.type;
Storage = DOM.Storage;
this.log = log;
this.PREFIX = '';
@ -124,7 +125,7 @@ var Util, DOM, CloudFunc, join;
function(error) {
var Proto = CloudCmd[name];
if (!error && type.function(Proto))
if (!error && itype.function(Proto))
CloudCmd[name] = applyConstructor(Proto, args);
});
};
@ -286,7 +287,7 @@ var Util, DOM, CloudFunc, join;
modules = [];
modules.forEach(function(module) {
var isStr = type.string(module);
var isStr = itype.string(module);
if (isStr)
load(null, module, doBefore[module]);
@ -340,7 +341,7 @@ var Util, DOM, CloudFunc, join;
this.execFromModule = function(moduleName, funcName) {
var args = [].slice.call(arguments, 2),
obj = CloudCmd[moduleName],
isObj = Util.type.object(obj);
isObj = itype.object(obj);
Util.exec.if(isObj,
function() {

View file

@ -36,6 +36,7 @@ var CloudCmd;
libDir('jonny'),
libDist('emitify'),
libDist('currify'),
libDist('itype'),
].filter(function(name) {
return name;
}).map(function(name) {

View file

@ -4,6 +4,7 @@ var CloudCmd, Util, DOM, CloudFunc;
'use strict';
/* global rendy */
/* global itype */
var DOMFunc = function() {},
DOMProto,
@ -301,7 +302,7 @@ var CloudCmd, Util, DOM, CloudFunc;
remoteObj = Util.findObjByNameInArr(modules, 'remote'),
module = Util.findObjByNameInArr(remoteObj, name),
isArray = Util.type.array(module.local),
isArray = itype.array(module.local),
version = module.version,
funcON = function() {
@ -724,7 +725,7 @@ var CloudCmd, Util, DOM, CloudFunc;
ONE_MEGABYTE = 1024 * 1024 * 1024;
if (!error) {
if (Util.type.object(data))
if (itype.object(data))
data = Util.json.stringify(data);
length = data.length;

View file

@ -1,5 +1,7 @@
var Util, DOM;
/* global itype */
(function(Util, DOM) {
'use strict';
@ -9,7 +11,7 @@ var Util, DOM;
function EventsProto() {
var Events = this;
var Type = Util.type;
var Type = itype;
function parseArgs(eventName, element, listener, callback) {
var isFunc, isElement, error,

View file

@ -1,7 +1,6 @@
/* load and store templates data */
/*global Promise */
/*global Util, DOM, CloudCmd */
/* global Promise */
/* global itype */
/* global Util, DOM, CloudCmd */
(function(Util, DOM) {
'use strict';
@ -24,7 +23,7 @@
timeout = getTimeoutOnce(2000);
this.get = function(name, callback) {
var type = Util.type(name);
var type = itype(name);
check(name, callback);

View file

@ -1,6 +1,7 @@
/* global Util */
/* global DOM */
/* global Emitify */
/* global itype */
(function (Util, DOM) {
'use strict';
@ -101,7 +102,7 @@
}
if (p.attribute) {
type = Util.type(p.attribute);
type = itype(p.attribute);
switch(type) {
case 'string':
@ -140,7 +141,7 @@
*/
load.getIdBySrc = function(src) {
var num, sub, id,
isStr = Util.type.string(src);
isStr = itype.string(src);
if (isStr) {
if (~src.indexOf(':'))
@ -165,9 +166,9 @@
load.ajax = function(params) {
var data,
p = params,
isObject = Util.type.object(p.data),
isArray = Util.type.array(p.data),
isArrayBuf = Util.type(p.data) === 'arraybuffer',
isObject = itype.object(p.data),
isArray = itype.array(p.data),
isArrayBuf = itype(p.data) === 'arraybuffer',
type = p.type || p.method || 'GET',
headers = p.headers || {},
xhr = new XMLHttpRequest();

View file

@ -1,9 +1,11 @@
/* global itype */
var Util, DOM, jQuery;
(function(window, document, Util, DOM, $) {
'use strict';
var type = Util.type;
var type = itype;
if (!window.XMLHttpRequest || !document.head)
DOM.load.ajax = $.ajax;
@ -35,13 +37,6 @@ var Util, DOM, jQuery;
return type(arr) === 'array';
};
/*
* typeof callback === "function" should not be used,
* as older browsers may report objects to be a function,
* which they are not
*/
Util.type.function = $.isFunction;
if (!document.addEventListener)
/**
* safe add event listener on ie

View file

@ -1,3 +1,5 @@
/* global itype */
var Util, DOM, CloudFunc, CloudCmd;
(function(Util, DOM, CloudFunc) {
@ -14,7 +16,7 @@ var Util, DOM, CloudFunc, CloudCmd;
var Images = DOM.Images;
this.delete = function(url, data, callback) {
var isFunc = Util.type.function(data);
var isFunc = itype.function(data);
if (!callback && isFunc) {
callback = data;
@ -31,7 +33,7 @@ var Util, DOM, CloudFunc, CloudCmd;
};
this.patch = function(url, data, callback) {
var isFunc = Util.type.function(data);
var isFunc = itype.function(data);
if (!callback && isFunc) {
callback = data;
@ -48,7 +50,7 @@ var Util, DOM, CloudFunc, CloudCmd;
};
this.write = function(url, data, callback) {
var isFunc = Util.type.function(data);
var isFunc = itype.function(data);
if (!callback && isFunc) {
callback = data;
@ -69,7 +71,7 @@ var Util, DOM, CloudFunc, CloudCmd;
isBeautify = /\?beautify$/.test(url),
isMinify = /\?minify$/.test(url),
notLog = !isQuery || isBeautify || isMinify,
isFunc = Util.type.function(dataType);
isFunc = itype.function(dataType);
if (!callback && isFunc) {
callback = dataType;

View file

@ -1,7 +1,8 @@
/* global Util */
/* global DOM */
/* global itype */
(function(Util, DOM, localStorage, exec, json, type) {
(function(Util, DOM, localStorage, exec, json, itype) {
'use strict';
var Storage = Util.extendProto(StorageProto),
@ -62,7 +63,7 @@
this.set = function(name, data, callback) {
var str, error;
if (type.object(data))
if (itype.object(data))
str = json.stringify(data);
if (Allowed && name)
@ -99,4 +100,4 @@
return this;
};
}
})(Util, DOM, localStorage, Util.exec, Util.json, Util.type);
})(Util, DOM, localStorage, Util.exec, Util.json, itype);

View file

@ -1,3 +1,5 @@
/* global itype */
var CloudCmd, Util, DOM, CloudFunc, $, exec;
(function(CloudCmd, Util, DOM, CloudFunc) {
@ -168,7 +170,7 @@ var CloudCmd, Util, DOM, CloudFunc, $, exec;
Object.keys(options).forEach(function(name) {
var isConfig = !!config[name];
var item = options[name];
var isFunc = Util.type.function(item);
var isFunc = itype.function(item);
if (!isFunc || !isConfig) {
config[name] = options[name];

View file

@ -1,10 +1,10 @@
(function(scope) {
'use strict';
var exec,
rendy,
jonny,
Scope = scope.window ? window : global;
var exec;
var rendy;
var jonny;
var Scope = scope.window ? window : global;
if (typeof module === 'object' && module.exports) {
exec = require('execon');
@ -50,20 +50,19 @@
* @target
* @objFrom
*/
this.extend = function(target, objFrom) {
var obj,
keys,
proto,
isFunc = Util.type.function(objFrom),
isArray = Util.type.array(objFrom),
isObj = Util.type.object(target),
ret = isObj ? target : {};
this.extend = function(target, objFrom) {
var obj;
var keys;
var proto;
var isFunc = typeof objFrom === 'function';
var isArray = Array.isArray(objFrom);
var isObj = typeof target === 'object';
var ret = isObj ? target : {};
if (isArray)
objFrom.forEach(function(item) {
ret = Util.extend(target, item);
});
else if (objFrom) {
obj = isFunc ? new objFrom() : objFrom;
@ -98,7 +97,7 @@
this.json = jonny;
this.escapeRegExp = function(str) {
var isStr = Util.type.string(str);
var isStr = typeof str === 'string';
if (isStr)
str = str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
@ -127,50 +126,7 @@
return regExp;
};
this.type = new TypeProto();
function TypeProto() {
/**
* get type of variable
*
* @param variable
*/
function type(variable) {
var regExp = /\s([a-zA-Z]+)/,
str = {}.toString.call(variable),
typeBig = str.match(regExp)[1],
result = typeBig.toLowerCase();
return result;
}
/**
* functions check is variable is type of name
*
* @param variable
*/
function typeOf(name, variable) {
return type(variable) === name;
}
function typeOfSimple(name, variable) {
return typeof variable === name;
}
['null', 'arrayBuffer', 'file', 'array', 'object']
.forEach(function(name) {
type[name] = typeOf.bind(null, name);
});
['string', 'undefined', 'boolean', 'number', 'function']
.forEach(function(name) {
type[name] = typeOfSimple.bind(null, name);
});
return type;
}
this.exec = exec;
this.exec = exec;
/**
* function gets file extension
@ -178,10 +134,10 @@
* @param pFileName
* @return Ext
*/
this.getExt = function(name) {
var ret = '',
dot,
isStr = Util.type.string(name);
this.getExt = function(name) {
var ret = '';
var dot;
var isStr = typeof name === 'string'
if (isStr) {
dot = name.lastIndexOf('.');

View file

@ -27,7 +27,6 @@
"commit": "be9ab0b0f7b8e685da89321df384ac902fa3c587"
},
"_source": "https://github.com/coderaiser/currify.git",
"_target": "^2.0.3",
"_originalSource": "currify",
"_direct": true
"_target": "2.0.3",
"_originalSource": "currify"
}

35
modules/itype/.bower.json Normal file
View file

@ -0,0 +1,35 @@
{
"name": "itype",
"description": "Improved type check",
"main": "dist/itype.js",
"authors": [
"coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)"
],
"license": "MIT",
"keywords": [
"type",
"string",
"array",
"object",
"boolean",
"null",
"undefined",
"check"
],
"homepage": "https://github.com/coderaiser/itype",
"ignore": [
".*",
"test",
"lib"
],
"version": "2.0.3",
"_release": "2.0.3",
"_resolution": {
"type": "version",
"tag": "v2.0.3",
"commit": "ec7f35bfdc6f9078d4e4792dd347bf98dd2f8ccc"
},
"_source": "https://github.com/coderaiser/itype.git",
"_target": "2.0.3",
"_originalSource": "itype"
}

35
modules/itype/ChangeLog Normal file
View file

@ -0,0 +1,35 @@
2016.12.28, v2.0.3
fix:
- (bower) main
2016.12.28, v2.0.2
feature:
- (bower) ignore: add ".*"
2016.12.28, v2.0.1
feature:
- (bower) add
2016.12.28, v2.0.0
feature:
- (itype) add browser support
2015.01.30, v1.0.2
feature:
- (type) change format of regexp
2014.12.22, v1.0.1
feature:
- (itype) add null

21
modules/itype/LICENSE Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 coderaiser
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

52
modules/itype/README.md Normal file
View file

@ -0,0 +1,52 @@
# iType [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]
Improved type check.
## Install
```
npm i itype --save
```
## How to use?
```js
var itype = require('itype');
console.og(itype.string('hello'))
// returns
true
console.log(itype('world'));
// returns
'string'
console.log(itype.array([1, 2]));
// returns
true
```
## Environments
In old `node.js` environments that not fully supports `es2015`, `itype` could be used with:
```js
var itype = require('itype/legacy');
```
## License
MIT
[NPMIMGURL]: https://img.shields.io/npm/v/itype.svg?style=flat
[BuildStatusIMGURL]: https://img.shields.io/travis/coderaiser/itype/master.svg?style=flat
[DependencyStatusIMGURL]: https://img.shields.io/gemnasium/coderaiser/itype.svg?style=flat
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
[NPMURL]: https://npmjs.org/package/itype "npm"
[BuildStatusURL]: https://travis-ci.org/coderaiser/itype "Build Status"
[DependencyStatusURL]: https://gemnasium.com/coderaiser/itype "Dependency Status"
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
[CoverageURL]: https://coveralls.io/github/coderaiser/itype?branch=master
[CoverageIMGURL]: https://coveralls.io/repos/coderaiser/itype/badge.svg?branch=master&service=github

25
modules/itype/bower.json Normal file
View file

@ -0,0 +1,25 @@
{
"name": "itype",
"description": "Improved type check",
"main": "dist/itype.js",
"authors": [
"coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)"
],
"license": "MIT",
"keywords": [
"type",
"string",
"array",
"object",
"boolean",
"null",
"undefined",
"check"
],
"homepage": "https://github.com/coderaiser/itype",
"ignore": [
".*",
"test",
"lib"
]
}

49
modules/itype/dist/itype.js vendored Normal file
View file

@ -0,0 +1,49 @@
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.itype = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"itype":[function(require,module,exports){
'use strict';
module.exports = new TypeProto();
function TypeProto() {
/**
* get type of variable
*
* @param variable
*/
function type(variable) {
var regExp = /\s([a-zA-Z]+)/;
var str = {}.toString.call(variable);
var typeBig = str.match(regExp)[1];
var result = typeBig.toLowerCase();
return result;
}
/**
* functions check is variable is type of name
*
* @param variable
*/
function typeOf(name, variable) {
return type(variable) === name;
}
function typeOfSimple(name, variable) {
return typeof variable === name;
}
['arrayBuffer', 'file', 'array', 'object']
.forEach(function (name) {
type[name] = typeOf.bind(null, name);
});
['null', 'string', 'undefined', 'boolean', 'number', 'function']
.forEach(function (name) {
type[name] = typeOfSimple.bind(null, name);
});
return type;
}
},{}]},{},["itype"])("itype")
});

1
modules/itype/dist/itype.min.js vendored Normal file
View file

@ -0,0 +1 @@
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.itype=e()}}(function(){return function e(n,r,t){function o(i,u){if(!r[i]){if(!n[i]){var c="function"==typeof require&&require;if(!u&&c)return c(i,!0);if(f)return f(i,!0);var l=new Error("Cannot find module '"+i+"'");throw l.code="MODULE_NOT_FOUND",l}var a=r[i]={exports:{}};n[i][0].call(a.exports,function(e){var r=n[i][1][e];return o(r?r:e)},a,a.exports,e,n,r,t)}return r[i].exports}for(var f="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}({itype:[function(e,n,r){"use strict";function t(){function e(e){var n=/\s([a-zA-Z]+)/,r={}.toString.call(e),t=r.match(n)[1],o=t.toLowerCase();return o}function n(n,r){return e(r)===n}function r(e,n){return typeof n===e}return["arrayBuffer","file","array","object"].forEach(function(r){e[r]=n.bind(null,r)}),["null","string","undefined","boolean","number","function"].forEach(function(n){e[n]=r.bind(null,n)}),e}n.exports=new t},{}]},{},["itype"])("itype")});

View file

@ -0,0 +1,53 @@
{
"name": "itype",
"version": "2.0.3",
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
"description": "Improved type check",
"main": "lib/itype.js",
"repository": {
"type": "git",
"url": "git://github.com/coderaiser/itype.git"
},
"keywords": [
"type",
"string",
"array",
"object",
"boolean",
"null",
"undefined",
"check"
],
"scripts": {
"test": "tape test/*.js",
"watcher": "nodemon -w test -w lib --exec",
"watch:test": "npm run watcher -- npm test",
"watch:coverage": "npm run watcher -- npm run coverage",
"lint": "eslint lib test",
"build": "redrun clean init 6to5 legacy:* bundle minify",
"init": "mkdirp dist legacy",
"minify": "minify dist/itype.js > dist/itype.min.js",
"wisdom": "npm run build",
"clean": "rimraf legacy dist",
"bundle:base": "browserify -s itype --ng false",
"bundle": "npm run bundle:base -- -r ./legacy/lib/itype.js:itype ./legacy/lib/itype.js -o dist/itype.js",
"coverage": "nyc npm test",
"report": "nyc report --reporter=text-lcov | coveralls",
"6to5": "buble lib -o legacy/lib",
"legacy:index": "echo \"module.exports = require('./lib/itype');\" > legacy/index.js"
},
"dependencies": {},
"license": "MIT",
"devDependencies": {
"browserify": "^13.0.0",
"buble": "^0.15.1",
"coveralls": "^2.11.9",
"eslint": "^3.10.2",
"minify": "^2.0.5",
"mkdirp": "^0.5.1",
"nodemon": "^1.11.0",
"nyc": "^10.0.0",
"redrun": "^5.0.1",
"tape": "^4.5.1"
}
}