From 0231b8350538a8f6cf2a4adfacaee6225eb5ba18 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 18 Feb 2015 09:18:52 -0500 Subject: [PATCH] feature(bower) add format-io --- bower.json | 3 +- lib/client/cloudcmd.js | 11 ++++-- modules/format-io/.bower.json | 37 ++++++++++++++++++ modules/format-io/ChangeLog | 6 +++ modules/format-io/LICENSE | 21 ++++++++++ modules/format-io/README.md | 49 ++++++++++++++++++++++++ modules/format-io/bower.json | 27 +++++++++++++ {lib => modules/format-io/lib}/format.js | 40 +++++++++---------- modules/format-io/package.json | 22 +++++++++++ 9 files changed, 191 insertions(+), 25 deletions(-) create mode 100644 modules/format-io/.bower.json create mode 100644 modules/format-io/ChangeLog create mode 100644 modules/format-io/LICENSE create mode 100644 modules/format-io/README.md create mode 100644 modules/format-io/bower.json rename {lib => modules/format-io/lib}/format.js (86%) create mode 100644 modules/format-io/package.json diff --git a/bower.json b/bower.json index 60ab621b..ac1fb54f 100644 --- a/bower.json +++ b/bower.json @@ -23,6 +23,7 @@ "fancybox": "~2.1.5", "jquery": "~2.1.3", "menu": "~0.7.7", - "promise-polyfill": "~2.0.0" + "promise-polyfill": "~2.0.0", + "format-io": "~0.9.6" } } diff --git a/lib/client/cloudcmd.js b/lib/client/cloudcmd.js index a212a539..a38d7773 100644 --- a/lib/client/cloudcmd.js +++ b/lib/client/cloudcmd.js @@ -7,12 +7,12 @@ var CloudCmd; function load(prefix) { var urlFiles, + modules = '/modules/', lib = 'lib/', client = 'client/', files = [ 'util', 'join', - 'format', 'cloudfunc', client + 'dom', client + 'events', @@ -26,10 +26,15 @@ var CloudCmd; client + 'listeners', client + 'key' ].map(function(name) { - return lib + name + '.js'; + return lib + name; }); - files.unshift('/modules/promise-polyfill/Promise.js'); + files.unshift(modules + 'promise-polyfill/Promise'); + files.unshift(modules + 'format-io/lib/format'); + + files = files.map(function(name) { + return name + '.js'; + }); urlFiles = getJoinURL(files); diff --git a/modules/format-io/.bower.json b/modules/format-io/.bower.json new file mode 100644 index 00000000..4078a8af --- /dev/null +++ b/modules/format-io/.bower.json @@ -0,0 +1,37 @@ +{ + "name": "format-io", + "version": "0.9.6", + "homepage": "https://github.com/coderaiser/format-io", + "authors": [ + "coderaiser " + ], + "description": "Format size, permissions, etc", + "main": "lib/format.js", + "moduleType": [ + "globals", + "node" + ], + "keywords": [ + "format", + "size", + "permissions" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ], + "_release": "0.9.6", + "_resolution": { + "type": "version", + "tag": "v0.9.6", + "commit": "3381e500de22cc60a25a4049589c377198f8cc57" + }, + "_source": "git://github.com/coderaiser/format-io.git", + "_target": "~0.9.6", + "_originalSource": "format-io", + "_direct": true +} \ No newline at end of file diff --git a/modules/format-io/ChangeLog b/modules/format-io/ChangeLog new file mode 100644 index 00000000..00c56124 --- /dev/null +++ b/modules/format-io/ChangeLog @@ -0,0 +1,6 @@ +2015.02.18, v0.9.6 + +feature: +- (bower) add +- (format) scope -> global + diff --git a/modules/format-io/LICENSE b/modules/format-io/LICENSE new file mode 100644 index 00000000..2c5ecaa0 --- /dev/null +++ b/modules/format-io/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/format-io/README.md b/modules/format-io/README.md new file mode 100644 index 00000000..40972930 --- /dev/null +++ b/modules/format-io/README.md @@ -0,0 +1,49 @@ +# Format + +Library for format size, permissions, etc. + +# How to use? + +Format could be used in browser or node. + +In browser: + +```js + +``` + +In node: + +```js +var Format = require('format-io'); +``` + +# API + +## size + +```js + var size = 1024 * 1024 * 5, + sizeStr = Format.size(size); + //'5.00mb' +``` + +## permissions.symbolic + +```js + var perm = '00777', + permStr = Format.permissions.symbolic(perm); + //'rwx rwx rwx +``` + +## permissions.numeric + +```js + var perm = 'rwx rwx rwx', + permNum = Format.permissions.numeric(perm); + //'00777' +``` + +# License + +MIT diff --git a/modules/format-io/bower.json b/modules/format-io/bower.json new file mode 100644 index 00000000..967aa75a --- /dev/null +++ b/modules/format-io/bower.json @@ -0,0 +1,27 @@ +{ + "name": "format-io", + "version": "0.9.6", + "homepage": "https://github.com/coderaiser/format-io", + "authors": [ + "coderaiser " + ], + "description": "Format size, permissions, etc", + "main": "lib/format.js", + "moduleType": [ + "globals", + "node" + ], + "keywords": [ + "format", + "size", + "permissions" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ] +} diff --git a/lib/format.js b/modules/format-io/lib/format.js similarity index 86% rename from lib/format.js rename to modules/format-io/lib/format.js index 44958d70..d13ba705 100644 --- a/lib/format.js +++ b/modules/format-io/lib/format.js @@ -1,12 +1,10 @@ -(function(scope) { +(function(global) { 'use strict'; - var Scope = scope.window ? window : global; - if (typeof module === 'object' && module.exports) module.exports = new FormatProto(); else - Scope.Format = new FormatProto(); + global.Format = new FormatProto(); function FormatProto() { this.addSlashToEnd = function(path) { @@ -38,18 +36,18 @@ if (isNumber) { if (size < l1KB) size = size + 'b'; - else if (size < l1MB) size = (size/l1KB).toFixed(2) + 'kb'; - else if (size < l1GB) size = (size/l1MB).toFixed(2) + 'mb'; - else if (size < l1TB) size = (size/l1GB).toFixed(2) + 'gb'; - else if (size < l1PB) size = (size/l1TB).toFixed(2) + 'tb'; - else size = (size/l1PB).toFixed(2) + 'pb'; + else if (size < l1MB) size = (size / l1KB).toFixed(2) + 'kb'; + else if (size < l1GB) size = (size / l1MB).toFixed(2) + 'mb'; + else if (size < l1TB) size = (size / l1GB).toFixed(2) + 'gb'; + else if (size < l1PB) size = (size / l1TB).toFixed(2) + 'tb'; + else size = (size / l1PB).toFixed(2) + 'pb'; } return size; }; - + /** - * Функция переводит права из цыфрового вида в символьный + * Функция переводит права из цыфрового вида в символьный * @param perms - строка с правами доступа * к файлу в 8-миричной системе */ @@ -78,16 +76,16 @@ switch (type - 0) { case 1: /* обычный файл */ - type='-'; + type = '-'; break; case 2: /* байт-ориентированное (символьное) устройство*/ - type='c'; + type = 'c'; break; case 4: /* каталог */ - type='d'; + type = 'd'; break; default: - type='-'; + type = '-'; } /* оставляем последние 3 символа*/ @@ -99,12 +97,12 @@ /* Рекомендации гугла советуют вместо string[3] * использовать string.charAt(3) */ - /* + /* http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml?showone=Standards_features#Standards_features Always preferred over non-standards featuresFor - maximum portability and compatibility, always - prefer standards features over non-standards + maximum portability and compatibility, always + prefer standards features over non-standards features (e.g., string.charAt(3) over string[3] and element access with DOM functions instead of using an application-specific shorthand). @@ -124,9 +122,9 @@ (group[1] - 0 > 0 ? 'w' : '-') + (group[2] - 0 > 0 ? 'x' : '-') + ' ' + - (all[0]- 0 > 0 ? 'r' : '-') + - (all[1]- 0 > 0 ? 'w' : '-') + - (all[2]- 0 > 0 ? 'x' : '-'); + (all[0] - 0 > 0 ? 'r' : '-') + + (all[1] - 0 > 0 ? 'w' : '-') + + (all[2] - 0 > 0 ? 'x' : '-'); } return permissions; diff --git a/modules/format-io/package.json b/modules/format-io/package.json new file mode 100644 index 00000000..eba72224 --- /dev/null +++ b/modules/format-io/package.json @@ -0,0 +1,22 @@ +{ + "name": "format-io", + "version": "0.9.6", + "author": "coderaiser (https://github.com/coderaiser)", + "description": "Format size, permissions, etc", + "homepage": "http://github.com/coderaiser/format-io", + "repository": { + "type": "git", + "url": "git://github.com/coderaiser/format-io.git" + }, + "keywords": [ + "format", + "size", + "permissions" + ], + "dependencies": {}, + "license": "MIT", + "engines": { + "node": ">=0.4.x" + }, + "main": "lib/format.js" +}