diff --git a/bower.json b/bower.json index e69ff4d6..8ffa3b5e 100644 --- a/bower.json +++ b/bower.json @@ -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" } } diff --git a/client/client.js b/client/client.js index bf7012c1..fb96a651 100644 --- a/client/client.js +++ b/client/client.js @@ -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() { diff --git a/client/cloudcmd.js b/client/cloudcmd.js index 93221998..dbccfaa2 100644 --- a/client/cloudcmd.js +++ b/client/cloudcmd.js @@ -36,6 +36,7 @@ var CloudCmd; libDir('jonny'), libDist('emitify'), libDist('currify'), + libDist('itype'), ].filter(function(name) { return name; }).map(function(name) { diff --git a/client/dom.js b/client/dom.js index 2980f426..ad50ff80 100644 --- a/client/dom.js +++ b/client/dom.js @@ -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; diff --git a/client/events.js b/client/events.js index 2411bab1..ff24ca3a 100644 --- a/client/events.js +++ b/client/events.js @@ -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, diff --git a/client/files.js b/client/files.js index 4510e07e..02983525 100644 --- a/client/files.js +++ b/client/files.js @@ -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); diff --git a/client/load.js b/client/load.js index d071aa76..b680f0a7 100644 --- a/client/load.js +++ b/client/load.js @@ -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(); diff --git a/client/polyfill.js b/client/polyfill.js index f2416b03..750cc350 100644 --- a/client/polyfill.js +++ b/client/polyfill.js @@ -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 diff --git a/client/rest.js b/client/rest.js index 33156679..37a9dea2 100644 --- a/client/rest.js +++ b/client/rest.js @@ -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; diff --git a/client/storage.js b/client/storage.js index cafb429c..564d7cba 100644 --- a/client/storage.js +++ b/client/storage.js @@ -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); diff --git a/client/view.js b/client/view.js index e2d6296a..89bd67b1 100644 --- a/client/view.js +++ b/client/view.js @@ -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]; diff --git a/common/util.js b/common/util.js index 1ff20f49..93f6e2e9 100644 --- a/common/util.js +++ b/common/util.js @@ -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('.'); diff --git a/modules/currify/.bower.json b/modules/currify/.bower.json index c4036151..fc019608 100644 --- a/modules/currify/.bower.json +++ b/modules/currify/.bower.json @@ -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" } \ No newline at end of file diff --git a/modules/itype/.bower.json b/modules/itype/.bower.json new file mode 100644 index 00000000..9bc44c1f --- /dev/null +++ b/modules/itype/.bower.json @@ -0,0 +1,35 @@ +{ + "name": "itype", + "description": "Improved type check", + "main": "dist/itype.js", + "authors": [ + "coderaiser (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" +} \ No newline at end of file diff --git a/modules/itype/ChangeLog b/modules/itype/ChangeLog new file mode 100644 index 00000000..688cb754 --- /dev/null +++ b/modules/itype/ChangeLog @@ -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 + diff --git a/modules/itype/LICENSE b/modules/itype/LICENSE new file mode 100644 index 00000000..2c5ecaa0 --- /dev/null +++ b/modules/itype/LICENSE @@ -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. \ No newline at end of file diff --git a/modules/itype/README.md b/modules/itype/README.md new file mode 100644 index 00000000..a4d02c6e --- /dev/null +++ b/modules/itype/README.md @@ -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 + diff --git a/modules/itype/bower.json b/modules/itype/bower.json new file mode 100644 index 00000000..b301800d --- /dev/null +++ b/modules/itype/bower.json @@ -0,0 +1,25 @@ +{ + "name": "itype", + "description": "Improved type check", + "main": "dist/itype.js", + "authors": [ + "coderaiser (https://github.com/coderaiser)" + ], + "license": "MIT", + "keywords": [ + "type", + "string", + "array", + "object", + "boolean", + "null", + "undefined", + "check" + ], + "homepage": "https://github.com/coderaiser/itype", + "ignore": [ + ".*", + "test", + "lib" + ] +} diff --git a/modules/itype/dist/itype.js b/modules/itype/dist/itype.js new file mode 100644 index 00000000..d81277f8 --- /dev/null +++ b/modules/itype/dist/itype.js @@ -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 (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" + } +}