add bower components to third party

This commit is contained in:
Patrick
2015-04-13 16:55:01 -07:00
parent 72fed9a2f3
commit 9da746e163
722 changed files with 178812 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
{
"name": "string-format-js",
"main": "format.js",
"version": "0.1.2",
"homepage": "https://github.com/tmaeda1981jp/string-format-js",
"authors": [
"tmaeda1981jp <tmaeda1981jp@gmail.com>"
],
"description": "String format function for javascript",
"keywords": [
"string",
"format"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"libs",
"test",
"tests"
],
"_release": "0.1.2",
"_resolution": {
"type": "version",
"tag": "v0.1.2",
"commit": "52882d494f39ec556dd73b75f4e45e4f78f1f7bb"
},
"_source": "git://github.com/tmaeda1981jp/string-format-js.git",
"_target": "~0.1.2",
"_originalSource": "string-format-js"
}

View File

@@ -0,0 +1,62 @@
/*jslint white: true, nomen: true, maxlen: 120, plusplus: true, */
/*global _:false, $:false, define:false, require:false, */
module.exports = function(grunt) {
'use strict';
// Add the grunt-mocha-test tasks.
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-mocha-phantomjs');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
my_target: {
options: {
mangle: true,
compress: true,
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %> */'
},
files: {
'format.min.js': ['format.js']
}
}
},
mochaTest: {
test: {
options: {
// grep: '%b',
reporter: 'spec'
},
src: ['test/format.spec.js']
}
},
mocha_phantomjs: {
options: {
reporter: 'spec'
},
all: ['test/**/*.html']
},
watch: {
mochaTest: {
files: ['format.js', 'test/format.spec.js'],
tasks: ['mochaTest']
},
browserTest: {
files: ['format.js', 'test/format.spec.js'],
tasks: ['mocha_phantomjs']
}
}
});
grunt.registerTask('default', 'mochaTest');
grunt.registerTask('browserTest', 'mocha_phantomjs');
};

View File

@@ -0,0 +1,20 @@
Copyright (c) 2014 tmaeda1981jp
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.

View File

@@ -0,0 +1,139 @@
# string-format-js
[![Build Status](https://travis-ci.org/tmaeda1981jp/string-format-js.png?branch=master)](https://travis-ci.org/tmaeda1981jp/string-format-js)
## Synopsis
String format function for javascript.
## Code Example
### %d
```javascript
'%d'.format(10) === '10'
'%d, %d'.format(5, 10) === '5, 10'
'%d, %d and %d'.format(5, 10, 15) === '5, 10 and 15'
'%05d'.format(123) === '00123'
'%03d, %05d'.format(1, 123) === '001, 00123'
'[%5d]'.format(123) === '[ 123]'
'[%10d]'.format(123) === '[ 123]'
'[%-5d]'.format(123) === '[123 ]'
'[%-10d]'.format(123) === '[123 ]'
```
### %s
```javascript
'This is a %s'.format('pen') === 'This is a pen'
'This %s %s %s'.format('is', 'a', 'pen') === 'This is a pen'
'[%5s]'.format('abc') === '[ abc]'
'[%-5s]'.format('abc') === '[abc ]'
'[%.4s]'.format('abcde') === '[abcd]'
'[%5.4s]'.format('abcde') === '[ abcd]'
'[%-5.4s]'.format('abcde') === '[abcd ]'
'[%-5.4s]'.format('あいうえお') === '[あいうえ ]'
```
### %o
```javascript
'123 => %o'.format(123) === '123 => 173'
'0x7b => %o'.format(0x7b) === '0x7b => 173'
```
### %b
```javascript
'123 => %b'.format(123) === '123 => 1111011'
'0x7b => %b'.format(0x7b) === '0x7b => 1111011'
```
### %x
```javascript
'123 => %x'.format(123) === '123 => 7b'
```
### %X
```javascript
'123 => %X'.format(123) === '123 => 7B'
```
### %u
```javascript
'%u'.format(0x12345678 ^ 0xFFFFFFFF) === '3989547399'
'%u'.format(-1) === '4294967295'
```
### %c
```javascript
'%c'.format(97) === 'a'
'%c'.format(0x61) === 'a'
```
### %f
```javascript
'%f'.format(1.0) === '1.000000'
'%.2f'.format(1.0) === '1.00'
'[%10f]'.format(1.0) === '[1.00000000]'
'[%10.2f]'.format(1.0) === '[ 1.00]'
'[%10.2f]'.format(1.2345) === '[ 1.23]'
'[%-10.2f]'.format(1.0) === '[1.00 ]'
```
### %e
```javascript
'%e'.format(123) === '1.23e+2'
'%e'.format(123.45) === '1.2345e+2'
'%.5e'.format(123.45) === '1.23450e+2'
'[%15e]'.format(123.45) === '[1.2345000000e+2]'
'[%20e]'.format(12345678901.45) === '[1.23456789014500e+10]'
'[%15.2e]'.format(123.45) === '[ 1.23e+2]'
'[%7.2e]'.format(123.45) === '[1.23e+2]'
'[%-15.2e]'.format(123.45) === '[1.23e+2 ]'
```
### hash
```javascript
'#{name}'.format({name:'Takashi Maeda'}) === 'Takashi Maeda'
'#{first} #{last}'.format({first:'Takashi', last:'Maeda'}) === 'Takashi Maeda'
'#{a} #{b}, #{c} #{d}'.format(a:'Easy', b:'come', c:'easy', d:'go'}) === 'Easy come, easy go'
```
## Installation
### node
```bash
$ npm install string-format-js
```
### bower
```bash
$ bower install string-format-js
```
## Tests
### node
```bash
$ grunt mochaTest
```
### browser
```bash
$ grunt browserTest
```
## License
This software is released under the MIT License, see LICENSE.txt.

View File

@@ -0,0 +1,23 @@
{
"name": "string-format-js",
"main": "format.js",
"version": "0.1.2",
"homepage": "https://github.com/tmaeda1981jp/string-format-js",
"authors": [
"tmaeda1981jp <tmaeda1981jp@gmail.com>"
],
"description": "String format function for javascript",
"keywords": [
"string",
"format"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"libs",
"test",
"tests"
]
}

View File

@@ -0,0 +1,250 @@
/*jslint white: true, nomen: true, maxlen: 120, plusplus: true, */
/*global _:false, $:false, define:false, require:false, */
(function(global, undefined) {
'use strict';
var string = global.String;
if (!string.prototype.format) {
string.prototype.format = function() {
var i,
result = this,
isNumber = function(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
},
Formatter = (function() {
var Constr = function(identifier) {
var array = function(len){ return new Array(len); };
switch(true) {
case /^#\{(\w+)\}*$/.test(identifier):
this.formatter = function(line, param) {
return line.replace('#{' + RegExp.$1 + '}', param[RegExp.$1]);
};
break;
case /^([ds])$/.test(identifier):
this.formatter = function(line, param) {
if (RegExp.$1 === 'd' && !isNumber(param)) {
throw new TypeError();
}
return line.replace("%" + identifier, param);
};
break;
// Octet
case /^(o)$/.test(identifier):
this.formatter = function(line, param) {
if (!isNumber(param)) { throw new TypeError(); }
return line.replace(
"%" + identifier,
parseInt(param).toString(8));
};
break;
// Binary
case /^(b)$/.test(identifier):
this.formatter = function(line, param) {
if (!isNumber(param)) { throw new TypeError(); }
return line.replace(
"%" + identifier,
parseInt(param).toString(2));
};
break;
// Hex
case /^([xX])$/.test(identifier):
this.formatter = function(line, param) {
if (!isNumber(param)) { throw new TypeError(); }
var hex = parseInt(param).toString(16);
if (identifier === 'X') { hex = hex.toUpperCase(); }
return line.replace("%" + identifier, hex);
};
break;
case /^(c)$/.test(identifier):
this.formatter = function(line, param) {
if (!isNumber(param)) { throw new TypeError(); }
return line.replace("%" + identifier, String.fromCharCode(param));
};
break;
case /^(u)$/.test(identifier):
this.formatter = function(line, param) {
if (!isNumber(param)) { throw new TypeError(); }
return line.replace("%" + identifier, parseInt(param, 10) >>> 0);
};
break;
case /^(-?)(\d*).?(\d?)(e)$/.test(identifier):
this.formatter = function(line, param) {
if (!isNumber(param)) { throw new TypeError(); }
var lpad = RegExp.$1 === '-',
width = RegExp.$2,
decimal = RegExp.$3 !== '' ? RegExp.$3: undefined,
val = param.toExponential(decimal),
mantissa, exponent, padLength
;
if (width !== '') {
if (decimal !== undefined) {
padLength = width - val.length;
if (padLength >= 0){
val = lpad ?
val + array(padLength + 1).join(" "):
array(padLength + 1).join(" ") + val;
}
else {
// TODO throw ?
}
}
else {
mantissa = val.split('e')[0];
exponent = 'e' + val.split('e')[1];
padLength = width - (mantissa.length + exponent.length);
val = padLength >= 0 ?
mantissa + (array(padLength + 1)).join("0") + exponent :
mantissa.slice(0, padLength) + exponent;
}
}
return line.replace("%" + identifier, val);
};
break;
case /^(-?)(\d*).?(\d?)(f)$/.test(identifier):
this.formatter = function(line, param) {
if (!isNumber(param)) { throw new TypeError(); }
var lpad = RegExp.$1 === '-',
width = RegExp.$2,
decimal = RegExp.$3,
DOT_LENGTH = '.'.length,
integralPart = param > 0 ? Math.floor(param) : Math.ceil(param),
val = parseFloat(param).toFixed(decimal !== '' ? decimal : 6),
numberPartWidth, spaceWidth;
if (width !== '') {
if (decimal !== '') {
numberPartWidth =
integralPart.toString().length + DOT_LENGTH + parseInt(decimal, 10);
spaceWidth = width - numberPartWidth;
val = lpad ?
parseFloat(param).toFixed(decimal) + (array(spaceWidth + 1).join(" ")) :
(array(spaceWidth + 1).join(" ")) + parseFloat(param).toFixed(decimal);
}
else {
val = parseFloat(param).toFixed(
width - (integralPart.toString().length + DOT_LENGTH));
}
}
return line.replace("%" + identifier, val);
};
break;
// Decimal
case /^([0\-]?)(\d+)d$/.test(identifier):
this.formatter = function(line, param) {
if (!isNumber(param)) { throw new TypeError(); }
var len = RegExp.$2 - param.toString().length,
replaceString = '',
result;
if (len < 0) { len = 0; }
switch(RegExp.$1) {
case "": // rpad
replaceString = (array(len + 1).join(" ") + param).slice(-RegExp.$2);
break;
case "-": // lpad
replaceString = (param + array(len + 1).join(" ")).slice(-RegExp.$2);
break;
case "0": // 0pad
replaceString = (array(len + 1).join("0") + param).slice(-RegExp.$2);
break;
}
return line.replace("%" + identifier, replaceString);
};
break;
// String
case /^(-?)(\d)s$/.test(identifier):
this.formatter = function(line, param) {
var len = RegExp.$2 - param.toString().length,
replaceString = '',
result;
if (len < 0) { len = 0; }
switch(RegExp.$1) {
case "": // rpad
replaceString = (array(len + 1).join(" ") + param).slice(-RegExp.$2);
break;
case "-": // lpad
replaceString = (param + array(len + 1).join(" ")).slice(-RegExp.$2);
break;
default:
// TODO throw ?
}
return line.replace("%" + identifier, replaceString);
};
break;
// String with max length
case /^(-?\d?)\.(\d)s$/.test(identifier):
this.formatter = function(line, param) {
var replaceString = '',
max, spacelen;
// %.4s
if (RegExp.$1 === '') {
replaceString = param.slice(0, RegExp.$2);
}
// %5.4s %-5.4s
else {
param = param.slice(0, RegExp.$2);
max = Math.abs(RegExp.$1);
spacelen = max - param.toString().length;
replaceString = RegExp.$1.indexOf('-') !== -1 ?
(param + array(spacelen + 1).join(" ")).slice(-max): // lpad
(array(spacelen + 1).join(" ") + param).slice(-max); // rpad
}
return line.replace("%" + identifier, replaceString);
};
break;
default:
this.formatter = function(line, param) {
return line;
};
}
};
Constr.prototype = {
format: function(line, param) {
return this.formatter.call(this, line, param);
}
};
return Constr;
}()),
args = Array.prototype.slice.call(arguments)
;
if (args.length === 1 && typeof args[0] === 'object') {
for (i=0; i < Object.keys(args[0]).length; i+=1) {
if (result.match(/(#\{\w+\})/)) {
result = new Formatter(RegExp.$1).format(result, args[0]);
}
}
}
else {
for (i=0; i <args.length; i+=1) {
if (result.match(/%([.#0-9\-]*[bcdefosuxX])/)) {
result = new Formatter(RegExp.$1).format(result, args[i]);
}
}
}
return result;
};
}
}('undefined' !== typeof global ? global : window));

View File

@@ -0,0 +1 @@
/*! formatjs - v0.0.1 - 2014-01-12 */!function(a,b){"use strict";var c=a.String;c.prototype.format||(c.prototype.format=function(){var a,c=this,d=function(a){return!isNaN(parseFloat(a))&&isFinite(a)},e=function(){var a=function(a){var c=function(a){return new Array(a)};switch(!0){case/^#\{(\w+)\}*$/.test(a):this.formatter=function(a,b){return a.replace("#{"+RegExp.$1+"}",b[RegExp.$1])};break;case/^([ds])$/.test(a):this.formatter=function(b,c){if("d"===RegExp.$1&&!d(c))throw new TypeError;return b.replace("%"+a,c)};break;case/^(o)$/.test(a):this.formatter=function(b,c){if(!d(c))throw new TypeError;return b.replace("%"+a,parseInt(c).toString(8))};break;case/^(b)$/.test(a):this.formatter=function(b,c){if(!d(c))throw new TypeError;return b.replace("%"+a,parseInt(c).toString(2))};break;case/^([xX])$/.test(a):this.formatter=function(b,c){if(!d(c))throw new TypeError;var e=parseInt(c).toString(16);return"X"===a&&(e=e.toUpperCase()),b.replace("%"+a,e)};break;case/^(c)$/.test(a):this.formatter=function(b,c){if(!d(c))throw new TypeError;return b.replace("%"+a,String.fromCharCode(c))};break;case/^(u)$/.test(a):this.formatter=function(b,c){if(!d(c))throw new TypeError;return b.replace("%"+a,parseInt(c,10)>>>0)};break;case/^(-?)(\d*).?(\d?)(e)$/.test(a):this.formatter=function(e,f){if(!d(f))throw new TypeError;var g,h,i,j="-"===RegExp.$1,k=RegExp.$2,l=""!==RegExp.$3?RegExp.$3:b,m=f.toExponential(l);return""!==k&&(l!==b?(i=k-m.length,i>=0&&(m=j?m+c(i+1).join(" "):c(i+1).join(" ")+m)):(g=m.split("e")[0],h="e"+m.split("e")[1],i=k-(g.length+h.length),m=i>=0?g+c(i+1).join("0")+h:g.slice(0,i)+h)),e.replace("%"+a,m)};break;case/^(-?)(\d*).?(\d?)(f)$/.test(a):this.formatter=function(b,e){if(!d(e))throw new TypeError;var f,g,h="-"===RegExp.$1,i=RegExp.$2,j=RegExp.$3,k=".".length,l=e>0?Math.floor(e):Math.ceil(e),m=parseFloat(e).toFixed(""!==j?j:6);return""!==i&&(""!==j?(f=l.toString().length+k+parseInt(j,10),g=i-f,m=h?parseFloat(e).toFixed(j)+c(g+1).join(" "):c(g+1).join(" ")+parseFloat(e).toFixed(j)):m=parseFloat(e).toFixed(i-(l.toString().length+k))),b.replace("%"+a,m)};break;case/^([0\-]?)(\d+)d$/.test(a):this.formatter=function(b,e){if(!d(e))throw new TypeError;var f=RegExp.$2-e.toString().length,g="";switch(0>f&&(f=0),RegExp.$1){case"":g=(c(f+1).join(" ")+e).slice(-RegExp.$2);break;case"-":g=(e+c(f+1).join(" ")).slice(-RegExp.$2);break;case"0":g=(c(f+1).join("0")+e).slice(-RegExp.$2)}return b.replace("%"+a,g)};break;case/^(-?)(\d)s$/.test(a):this.formatter=function(b,d){var e=RegExp.$2-d.toString().length,f="";switch(0>e&&(e=0),RegExp.$1){case"":f=(c(e+1).join(" ")+d).slice(-RegExp.$2);break;case"-":f=(d+c(e+1).join(" ")).slice(-RegExp.$2)}return b.replace("%"+a,f)};break;case/^(-?\d?)\.(\d)s$/.test(a):this.formatter=function(b,d){var e,f,g="";return""===RegExp.$1?g=d.slice(0,RegExp.$2):(d=d.slice(0,RegExp.$2),e=Math.abs(RegExp.$1),f=e-d.toString().length,g=-1!==RegExp.$1.indexOf("-")?(d+c(f+1).join(" ")).slice(-e):(c(f+1).join(" ")+d).slice(-e)),b.replace("%"+a,g)};break;default:this.formatter=function(a){return a}}};return a.prototype={format:function(a,b){return this.formatter.call(this,a,b)}},a}(),f=Array.prototype.slice.call(arguments);if(1===f.length&&"object"==typeof f[0])for(a=0;a<Object.keys(f[0]).length;a+=1)c.match(/(#\{\w+\})/)&&(c=new e(RegExp.$1).format(c,f[0]));else for(a=0;a<f.length;a+=1)c.match(/%([.#0-9\-]*[bcdefosuxX])/)&&(c=new e(RegExp.$1).format(c,f[a]));return c})}("undefined"!=typeof global?global:window);

View File

@@ -0,0 +1,28 @@
{
"name": "string-format-js",
"version": "0.1.2",
"description": "String format function for javascript",
"main": "format.js",
"keywords": [
"string",
"format"
],
"scripts": {
"test": "grunt mochaTest",
"browserTest": "grunt browserTest"
},
"author": "tmaeda1981jp",
"homepage": "https://github.com/tmaeda1981jp/string-format-js",
"license": "MIT",
"devDependencies": {
"mocha": "~1.21.4",
"grunt": "~0.4.5",
"grunt-mocha-test": "~0.11.0",
"grunt-contrib-watch": "~0.6.1",
"expect.js": "~0.3.1",
"mocha-phantomjs": "~3.5.0",
"grunt-exec": "~0.4.6",
"grunt-contrib-uglify": "~0.5.1",
"grunt-mocha-phantomjs": "~0.6.0"
}
}