Socket
Socket
Sign inDemoInstall

string-extended

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-extended - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

53

index.js
(function () {
"use strict";
function defineString(extended, is, date) {
function defineString(extended, is, date, arr) {

@@ -584,3 +584,28 @@ var stringify;

function escape(str, except) {
return str.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, function (ch) {
if (except && arr.indexOf(except, ch) !== -1) {
return ch;
}
return "\\" + ch;
});
}
function trim(str) {
return str.replace(/^\s*|\s*$/g, "");
}
function trimLeft(str) {
return str.replace(/^\s*/, "");
}
function trimRight(str) {
return str.replace(/\s*$/, "");
}
function isEmpty(str) {
return str.length === 0;
}
var string = {

@@ -592,14 +617,10 @@ toArray: toArray,

format: format,
style: style
style: style,
escape: escape,
trim: trim,
trimLeft: trimLeft,
trimRight: trimRight,
isEmpty: isEmpty
};
var i, ret = extended.define(is.isString, string).define(is.isArray, {style: style});
for (i in string) {
if (string.hasOwnProperty(i)) {
ret[i] = string[i];
}
}
ret.characters = characters;
return ret;
return extended.define(is.isString, string).define(is.isArray, {style: style}).expose(string).expose({characters: characters});
}

@@ -609,11 +630,11 @@

if ("undefined" !== typeof module && module.exports) {
module.exports = defineString(require("extended"), require("is-extended"), require("date-extended"));
module.exports = defineString(require("extended"), require("is-extended"), require("date-extended"), require("array-extended"));
}
} else if ("function" === typeof define) {
define(["extended", "is-extended", "date-extended"], function (extended, is, date) {
return defineString(extended, is, date);
define(["extended", "is-extended", "date-extended", "array-extended"], function (extended, is, date, arr) {
return defineString(extended, is, date, arr);
});
} else {
this.stringExtended = defineString(this.extended, this.isExtended, this.dateExtended);
this.stringExtended = defineString(this.extended, this.isExtended, this.dateExtended, this.arrayExtended);
}

@@ -620,0 +641,0 @@

{
"name": "string-extended",
"version": "0.0.4",
"description": "Additional string extensions with a chainable api",
"main": "index.js",
"scripts": {
"test": "it -r dot"
},
"repository": {
"type": "git",
"url": "git:git@github.com:doug-martin/string-extended.git"
},
"keywords": [
"String",
"extender",
"utilities"
],
"testling": {
"files": "test/browserling.js",
"browsers": [
"ie/8..latest",
"chrome/20..latest",
"firefox/14..latest",
"safari/latest",
"iphone/6", "ipad/6"
]
},
"author": "Doug Martin",
"license": "MIT",
"dependencies": {
"extended": "~0.0.3",
"is-extended": "~0.0.3",
"date-extended": "~0.0.3",
"grunt": "~0.4.1"
},
"devDependencies": {
"it": "~0.2.0",
"grunt-it": "~0.3.0",
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-jshint": "~0.4.3"
}
"name": "string-extended",
"version": "0.0.5",
"description": "Additional string extensions with a chainable api",
"main": "index.js",
"scripts": {
"test": "it -r dot"
},
"repository": {
"type": "git",
"url": "git:git@github.com:doug-martin/string-extended.git"
},
"keywords": [
"String",
"extender",
"utilities"
],
"testling": {
"files": "test/browserling.js",
"browsers": [
"ie/8..latest",
"chrome/20..latest",
"firefox/14..latest",
"safari/latest",
"iphone/6",
"ipad/6"
]
},
"author": "Doug Martin",
"license": "MIT",
"dependencies": {
"extended": "~0.0.3",
"is-extended": "~0.0.3",
"date-extended": "~0.0.3",
"grunt": "~0.4.1",
"array-extended": "0.0.5"
},
"devDependencies": {
"it": "~0.2.0",
"grunt-it": "~0.3.0",
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-jshint": "~0.4.3"
}
}

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

[![Build Status](https://travis-ci.org/doug-martin/string-extended.png?branch=master)](undefined)
[![Build Status](https://travis-ci.org/doug-martin/string-extended.png?branch=master)](https://travis-ci.org/doug-martin/string-extended)
[![browser support](https://ci.testling.com/doug-martin/string-extended.png)](https://ci.testling.com/doug-martin/string-extended)
[![browser support](https://ci.testling.com/doug-martin/string-extended.png)](http://ci.testling.com/doug-martin/string-extended)

@@ -69,3 +69,3 @@ # string-extended

Returns a string duplicated n times;
Returns a string duplicated n times

@@ -76,2 +76,49 @@ ```javascript

**`escape`**
Escapes a string so that it can safely be used in a RegExp.
```javascript
stringExtended.escape(".$?*|{}()[]\/+^"); "//\.\$\?\*\|\{\}\(\)\[\]\/\+\^"
stringExtended(".$?*|{}()[]\/+^").escape().value(); "//\.\$\?\*\|\{\}\(\)\[\]\/\+\^"
```
You can also specify an optional array of characters to ignore when escaping.
```javascript
stringExtended.escape(".$?*|{}()[]\/+^", [".", "?", "{", "["]); //".\$?\*\|{\}\(\)[\]\/\+\^"
stringExtended(".$?*|{}()[]\/+^").escape([".", "?", "{", "["]).value(); //".\$?\*\|{\}\(\)[\]\/\+\^"
```
**`trim`**
Trims white space characters from the beginning and end of a string.
```javascript
stringExtended.trim(" Hello World "); //"Hello World"
stringExtended(" Hello World ").trim().value(); //"Hello World"
```
**`trimLeft`**
Trims white space characters from the beginning of a string.
```javascript
stringExtended.trimLeft(" Hello World "); //"Hello World "
stringExtended(" Hello World ").trimLeft().value(); //"Hello World "
```
**`trimRight`**
Trims white space characters from the end of a string.
```javascript
stringExtended.trimLeft(" Hello World "); //" Hello World"
stringExtended(" Hello World ").trimLeft().value(); //" Hello World"
```
**`format`**

@@ -78,0 +125,0 @@

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

/*! string-extended - v0.0.4 - 2013-04-16
/*! string-extended - v0.0.5 - 2013-05-19
* Copyright (c) 2013 Doug Martin; Licensed MIT */
(function(){"use strict";function E(E,_,e){function r(E,_){var e=E;if(N.test(_)){var r=_.match(N),t=r[1],n=r[3],O=r[4];O&&(O=parseInt(O,10),e=O>e.length?T(e,O,n,t):L(e,O))}return e}function t(E,e){var r;if(!_.isNumber(E))throw Error("stringExtended.format : when using %d the parameter must be a number!");if(r=""+E,N.test(e)){var t=e.match(N),n=t[1],O=t[2],A=t[3],i=t[4];O&&(r=(E>0?"+":"")+r),i&&(i=parseInt(i,10),r=i>r.length?T(r,i,A||"0",n):L(r,i))}return r}function n(E,_){var e,r=_.match(U),t=0;r&&(t=parseInt(r[0],10),isNaN(t)&&(t=0));try{e=R(E,null,t)}catch(n){throw Error("stringExtended.format : Unable to parse json from ",E)}return e}function T(E,_,e,r){E=""+E,e=e||" ";for(var t=E.length;_>t;)r?E+=e:E=e+E,t++;return E}function L(E,e,r){var t=E;if(_.isString(t)){if(E.length>e)if(r){var n=E.length;t=E.substring(n-e,n)}else t=E.substring(0,e)}else t=L(""+t,e);return t}function O(E,T){if(T instanceof Array){var L=0,A=T.length;return E.replace(a,function(E,_,O){var i,I;if(!(A>L))return E;if(i=T[L++],"%s"===E||"%d"===E||"%D"===E)I=i+"";else if("%Z"===E)I=i.toUTCString();else if("%j"===E)try{I=R(i)}catch(u){throw Error("stringExtended.format : Unable to parse json from ",i)}else switch(_=_.replace(/^\[|\]$/g,""),O){case"s":I=r(i,_);break;case"d":I=t(i,_);break;case"j":I=n(i,_);break;case"D":I=e.format(i,_);break;case"Z":I=e.format(i,_,!0)}return I})}if(o(T))return E.replace(s,function(E,L,O){if(O=T[O],!_.isUndefined(O)){if(!L)return""+O;if(_.isString(O))return r(O,L);if(_.isNumber(O))return t(O,L);if(_.isDate(O))return e.format(O,L);if(_.isObject(O))return n(O,L)}return E});var i=f.call(arguments).slice(1);return O(E,i)}function A(E,_){var e=[];return E&&(E.indexOf(_)>0?e=E.replace(/\s+/g,"").split(_):e.push(E)),e}function i(E,_){var e=[];if(_)for(var r=0;_>r;r++)e.push(E);return e.join("")}function I(E,e){var r,t,n;if(e)if(_.isArray(E))for(r=[],t=0,n=E.length;n>t;t++)r.push(I(E[t],e));else if(e instanceof Array)for(r=E,t=0,n=e.length;n>t;t++)r=I(r,e[t]);else e in M&&(r="["+M[e]+"m"+E+"");return r}var R;"undefined"==typeof JSON?function(){function E(E){return 10>E?"0"+E:E}function e(e){return _.isDate(e)?isFinite(e.valueOf())?e.getUTCFullYear()+"-"+E(e.getUTCMonth()+1)+"-"+E(e.getUTCDate())+"T"+E(e.getUTCHours())+":"+E(e.getUTCMinutes())+":"+E(e.getUTCSeconds())+"Z":null:O(e)?e.valueOf():e}function r(E){return A.lastIndex=0,A.test(E)?'"'+E.replace(A,function(E){var _=i[E];return"string"==typeof _?_:"\\u"+("0000"+E.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+E+'"'}function t(E,_){var O,A,i,I,R,u=n,o=_[E];switch(o&&(o=e(o)),"function"==typeof L&&(o=L.call(_,E,o)),typeof o){case"string":return r(o);case"number":return isFinite(o)?o+"":"null";case"boolean":case"null":return o+"";case"object":if(!o)return"null";if(n+=T,R=[],"[object Array]"===Object.prototype.toString.apply(o)){for(I=o.length,O=0;I>O;O+=1)R[O]=t(O,o)||"null";return i=0===R.length?"[]":n?"[\n"+n+R.join(",\n"+n)+"\n"+u+"]":"["+R.join(",")+"]",n=u,i}if(L&&"object"==typeof L)for(I=L.length,O=0;I>O;O+=1)"string"==typeof L[O]&&(A=L[O],i=t(A,o),i&&R.push(r(A)+(n?": ":":")+i));else for(A in o)Object.prototype.hasOwnProperty.call(o,A)&&(i=t(A,o),i&&R.push(r(A)+(n?": ":":")+i));return i=0===R.length?"{}":n?"{\n"+n+R.join(",\n"+n)+"\n"+u+"}":"{"+R.join(",")+"}",n=u,i}}var n,T,L,O=_.tester().isString().isNumber().isBoolean().tester(),A=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,i={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};R=function(E,_,e){var r;if(n="",T="","number"==typeof e)for(r=0;e>r;r+=1)T+=" ";else"string"==typeof e&&(T=e);if(L=_,_&&"function"!=typeof _&&("object"!=typeof _||"number"!=typeof _.length))throw Error("JSON.stringify");return t("",{"":E})}}():R=JSON.stringify;var u,o=_.isHash,f=Array.prototype.slice,a=/%((?:-?\+?.?\d*)?|(?:\[[^\[|\]]*\]))?([sjdDZ])/g,s=/\{(?:\[([^\[|\]]*)\])?(\w+)\}/g,N=/(-?)(\+?)([A-Z|a-z|\W]?)([1-9][0-9]*)?$/,U=/([1-9][0-9]*)$/g,M={bold:1,bright:1,italic:3,underline:4,blink:5,inverse:7,crossedOut:9,red:31,green:32,yellow:33,blue:34,magenta:35,cyan:36,white:37,redBackground:41,greenBackground:42,yellowBackground:43,blueBackground:44,magentaBackground:45,cyanBackground:46,whiteBackground:47,encircled:52,overlined:53,grey:90,black:90},C={SMILEY:"☺",SOLID_SMILEY:"☻",HEART:"♥",DIAMOND:"♦",CLOVE:"♣",SPADE:"♠",DOT:"•",SQUARE_CIRCLE:"◘",CIRCLE:"○",FILLED_SQUARE_CIRCLE:"◙",MALE:"♂",FEMALE:"♀",EIGHT_NOTE:"♪",DOUBLE_EIGHTH_NOTE:"♫",SUN:"☼",PLAY:"►",REWIND:"◄",UP_DOWN:"↕",PILCROW:"¶",SECTION:"§",THICK_MINUS:"▬",SMALL_UP_DOWN:"↨",UP_ARROW:"↑",DOWN_ARROW:"↓",RIGHT_ARROW:"→",LEFT_ARROW:"←",RIGHT_ANGLE:"∟",LEFT_RIGHT_ARROW:"↔",TRIANGLE:"▲",DOWN_TRIANGLE:"▼",HOUSE:"⌂",C_CEDILLA:"Ç",U_UMLAUT:"ü",E_ACCENT:"é",A_LOWER_CIRCUMFLEX:"â",A_LOWER_UMLAUT:"ä",A_LOWER_GRAVE_ACCENT:"à",A_LOWER_CIRCLE_OVER:"å",C_LOWER_CIRCUMFLEX:"ç",E_LOWER_CIRCUMFLEX:"ê",E_LOWER_UMLAUT:"ë",E_LOWER_GRAVE_ACCENT:"è",I_LOWER_UMLAUT:"ï",I_LOWER_CIRCUMFLEX:"î",I_LOWER_GRAVE_ACCENT:"ì",A_UPPER_UMLAUT:"Ä",A_UPPER_CIRCLE:"Å",E_UPPER_ACCENT:"É",A_E_LOWER:"æ",A_E_UPPER:"Æ",O_LOWER_CIRCUMFLEX:"ô",O_LOWER_UMLAUT:"ö",O_LOWER_GRAVE_ACCENT:"ò",U_LOWER_CIRCUMFLEX:"û",U_LOWER_GRAVE_ACCENT:"ù",Y_LOWER_UMLAUT:"ÿ",O_UPPER_UMLAUT:"Ö",U_UPPER_UMLAUT:"Ü",CENTS:"¢",POUND:"£",YEN:"¥",CURRENCY:"¤",PTS:"₧",FUNCTION:"ƒ",A_LOWER_ACCENT:"á",I_LOWER_ACCENT:"í",O_LOWER_ACCENT:"ó",U_LOWER_ACCENT:"ú",N_LOWER_TILDE:"ñ",N_UPPER_TILDE:"Ñ",A_SUPER:"ª",O_SUPER:"º",UPSIDEDOWN_QUESTION:"¿",SIDEWAYS_L:"⌐",NEGATION:"¬",ONE_HALF:"½",ONE_FOURTH:"¼",UPSIDEDOWN_EXCLAMATION:"¡",DOUBLE_LEFT:"«",DOUBLE_RIGHT:"»",LIGHT_SHADED_BOX:"░",MEDIUM_SHADED_BOX:"▒",DARK_SHADED_BOX:"▓",VERTICAL_LINE:"│",MAZE__SINGLE_RIGHT_T:"┤",MAZE_SINGLE_RIGHT_TOP:"┐",MAZE_SINGLE_RIGHT_BOTTOM_SMALL:"┘",MAZE_SINGLE_LEFT_TOP_SMALL:"┌",MAZE_SINGLE_LEFT_BOTTOM_SMALL:"└",MAZE_SINGLE_LEFT_T:"├",MAZE_SINGLE_BOTTOM_T:"┴",MAZE_SINGLE_TOP_T:"┬",MAZE_SINGLE_CENTER:"┼",MAZE_SINGLE_HORIZONTAL_LINE:"─",MAZE_SINGLE_RIGHT_DOUBLECENTER_T:"╡",MAZE_SINGLE_RIGHT_DOUBLE_BL:"╛",MAZE_SINGLE_RIGHT_DOUBLE_T:"╢",MAZE_SINGLE_RIGHT_DOUBLEBOTTOM_TOP:"╖",MAZE_SINGLE_RIGHT_DOUBLELEFT_TOP:"╕",MAZE_SINGLE_LEFT_DOUBLE_T:"╞",MAZE_SINGLE_BOTTOM_DOUBLE_T:"╧",MAZE_SINGLE_TOP_DOUBLE_T:"╤",MAZE_SINGLE_TOP_DOUBLECENTER_T:"╥",MAZE_SINGLE_BOTTOM_DOUBLECENTER_T:"╨",MAZE_SINGLE_LEFT_DOUBLERIGHT_BOTTOM:"╘",MAZE_SINGLE_LEFT_DOUBLERIGHT_TOP:"╒",MAZE_SINGLE_LEFT_DOUBLEBOTTOM_TOP:"╓",MAZE_SINGLE_LEFT_DOUBLETOP_BOTTOM:"╙",MAZE_SINGLE_LEFT_TOP:"Γ",MAZE_SINGLE_RIGHT_BOTTOM:"╜",MAZE_SINGLE_LEFT_CENTER:"╟",MAZE_SINGLE_DOUBLECENTER_CENTER:"╫",MAZE_SINGLE_DOUBLECROSS_CENTER:"╪",MAZE_DOUBLE_LEFT_CENTER:"╣",MAZE_DOUBLE_VERTICAL:"║",MAZE_DOUBLE_RIGHT_TOP:"╗",MAZE_DOUBLE_RIGHT_BOTTOM:"╝",MAZE_DOUBLE_LEFT_BOTTOM:"╚",MAZE_DOUBLE_LEFT_TOP:"╔",MAZE_DOUBLE_BOTTOM_T:"╩",MAZE_DOUBLE_TOP_T:"╦",MAZE_DOUBLE_LEFT_T:"╠",MAZE_DOUBLE_HORIZONTAL:"═",MAZE_DOUBLE_CROSS:"╬",SOLID_RECTANGLE:"█",THICK_LEFT_VERTICAL:"▌",THICK_RIGHT_VERTICAL:"▐",SOLID_SMALL_RECTANGLE_BOTTOM:"▄",SOLID_SMALL_RECTANGLE_TOP:"▀",PHI_UPPER:"Φ",INFINITY:"∞",INTERSECTION:"∩",DEFINITION:"≡",PLUS_MINUS:"±",GT_EQ:"≥",LT_EQ:"≤",THEREFORE:"⌠",SINCE:"∵",DOESNOT_EXIST:"∄",EXISTS:"∃",FOR_ALL:"∀",EXCLUSIVE_OR:"⊕",BECAUSE:"⌡",DIVIDE:"÷",APPROX:"≈",DEGREE:"°",BOLD_DOT:"∙",DOT_SMALL:"·",CHECK:"√",ITALIC_X:"✗",SUPER_N:"ⁿ",SQUARED:"²",CUBED:"³",SOLID_BOX:"■",PERMILE:"‰",REGISTERED_TM:"®",COPYRIGHT:"©",TRADEMARK:"™",BETA:"β",GAMMA:"γ",ZETA:"ζ",ETA:"η",IOTA:"ι",KAPPA:"κ",LAMBDA:"λ",NU:"ν",XI:"ξ",OMICRON:"ο",RHO:"ρ",UPSILON:"υ",CHI_LOWER:"φ",CHI_UPPER:"χ",PSI:"ψ",ALPHA:"α",ESZETT:"ß",PI:"π",SIGMA_UPPER:"Σ",SIGMA_LOWER:"σ",MU:"µ",TAU:"τ",THETA:"Θ",OMEGA:"Ω",DELTA:"δ",PHI_LOWER:"φ",EPSILON:"ε"},S={toArray:A,pad:T,truncate:L,multiply:i,format:O,style:I},c=E.define(_.isString,S).define(_.isArray,{style:I});for(u in S)S.hasOwnProperty(u)&&(c[u]=S[u]);return c.characters=C,c}"undefined"!=typeof exports?"undefined"!=typeof module&&module.exports&&(module.exports=E(require("extended"),require("is-extended"),require("date-extended"))):"function"==typeof define?define(["extended","is-extended","date-extended"],function(_,e,r){return E(_,e,r)}):this.stringExtended=E(this.extended,this.isExtended,this.dateExtended)}).call(this);
(function(){"use strict";function E(E,e,_,r){function t(E,e){var _=E;if(S.test(e)){var r=e.match(S),t=r[1],n=r[3],L=r[4];L&&(L=parseInt(L,10),_=L>_.length?T(_,L,n,t):O(_,L))}return _}function n(E,_){var r;if(!e.isNumber(E))throw Error("stringExtended.format : when using %d the parameter must be a number!");if(r=""+E,S.test(_)){var t=_.match(S),n=t[1],L=t[2],i=t[3],A=t[4];L&&(r=(E>0?"+":"")+r),A&&(A=parseInt(A,10),r=A>r.length?T(r,A,i||"0",n):O(r,A))}return r}function L(E,e){var _,r=e.match(l),t=0;r&&(t=parseInt(r[0],10),isNaN(t)&&(t=0));try{_=N(E,null,t)}catch(n){throw Error("stringExtended.format : Unable to parse json from ",E)}return _}function T(E,e,_,r){E=""+E,_=_||" ";for(var t=E.length;e>t;)r?E+=_:E=_+E,t++;return E}function O(E,_,r){var t=E;if(e.isString(t)){if(E.length>_)if(r){var n=E.length;t=E.substring(n-_,n)}else t=E.substring(0,_)}else t=O(""+t,_);return t}function i(E,r){if(r instanceof Array){var T=0,O=r.length;return E.replace(c,function(E,e,i){var A,I;if(!(O>T))return E;if(A=r[T++],"%s"===E||"%d"===E||"%D"===E)I=A+"";else if("%Z"===E)I=A.toUTCString();else if("%j"===E)try{I=N(A)}catch(u){throw Error("stringExtended.format : Unable to parse json from ",A)}else switch(e=e.replace(/^\[|\]$/g,""),i){case"s":I=t(A,e);break;case"d":I=n(A,e);break;case"j":I=L(A,e);break;case"D":I=_.format(A,e);break;case"Z":I=_.format(A,e,!0)}return I})}if(U(r))return E.replace(C,function(E,T,O){if(O=r[O],!e.isUndefined(O)){if(!T)return""+O;if(e.isString(O))return t(O,T);if(e.isNumber(O))return n(O,T);if(e.isDate(O))return _.format(O,T);if(e.isObject(O))return L(O,T)}return E});var A=M.call(arguments).slice(1);return i(E,A)}function A(E,e){var _=[];return E&&(E.indexOf(e)>0?_=E.replace(/\s+/g,"").split(e):_.push(E)),_}function I(E,e){var _=[];if(e)for(var r=0;e>r;r++)_.push(E);return _.join("")}function u(E,_){var r,t,n;if(_)if(e.isArray(E))for(r=[],t=0,n=E.length;n>t;t++)r.push(u(E[t],_));else if(_ instanceof Array)for(r=E,t=0,n=_.length;n>t;t++)r=u(r,_[t]);else _ in D&&(r="["+D[_]+"m"+E+"");return r}function R(E,e){return E.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,function(E){return e&&-1!==r.indexOf(e,E)?E:"\\"+E})}function a(E){return E.replace(/^\s*|\s*$/g,"")}function f(E){return E.replace(/^\s*/,"")}function o(E){return E.replace(/\s*$/,"")}function s(E){return 0===E.length}var N;"undefined"==typeof JSON?function(){function E(E){return 10>E?"0"+E:E}function _(_){return e.isDate(_)?isFinite(_.valueOf())?_.getUTCFullYear()+"-"+E(_.getUTCMonth()+1)+"-"+E(_.getUTCDate())+"T"+E(_.getUTCHours())+":"+E(_.getUTCMinutes())+":"+E(_.getUTCSeconds())+"Z":null:O(_)?_.valueOf():_}function r(E){return i.lastIndex=0,i.test(E)?'"'+E.replace(i,function(E){var e=A[E];return"string"==typeof e?e:"\\u"+("0000"+E.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+E+'"'}function t(E,e){var O,i,A,I,u,R=n,a=e[E];switch(a&&(a=_(a)),"function"==typeof T&&(a=T.call(e,E,a)),typeof a){case"string":return r(a);case"number":return isFinite(a)?a+"":"null";case"boolean":case"null":return a+"";case"object":if(!a)return"null";if(n+=L,u=[],"[object Array]"===Object.prototype.toString.apply(a)){for(I=a.length,O=0;I>O;O+=1)u[O]=t(O,a)||"null";return A=0===u.length?"[]":n?"[\n"+n+u.join(",\n"+n)+"\n"+R+"]":"["+u.join(",")+"]",n=R,A}if(T&&"object"==typeof T)for(I=T.length,O=0;I>O;O+=1)"string"==typeof T[O]&&(i=T[O],A=t(i,a),A&&u.push(r(i)+(n?": ":":")+A));else for(i in a)Object.prototype.hasOwnProperty.call(a,i)&&(A=t(i,a),A&&u.push(r(i)+(n?": ":":")+A));return A=0===u.length?"{}":n?"{\n"+n+u.join(",\n"+n)+"\n"+R+"}":"{"+u.join(",")+"}",n=R,A}}var n,L,T,O=e.tester().isString().isNumber().isBoolean().tester(),i=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,A={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};N=function(E,e,_){var r;if(n="",L="","number"==typeof _)for(r=0;_>r;r+=1)L+=" ";else"string"==typeof _&&(L=_);if(T=e,e&&"function"!=typeof e&&("object"!=typeof e||"number"!=typeof e.length))throw Error("JSON.stringify");return t("",{"":E})}}():N=JSON.stringify;var U=e.isHash,M=Array.prototype.slice,c=/%((?:-?\+?.?\d*)?|(?:\[[^\[|\]]*\]))?([sjdDZ])/g,C=/\{(?:\[([^\[|\]]*)\])?(\w+)\}/g,S=/(-?)(\+?)([A-Z|a-z|\W]?)([1-9][0-9]*)?$/,l=/([1-9][0-9]*)$/g,D={bold:1,bright:1,italic:3,underline:4,blink:5,inverse:7,crossedOut:9,red:31,green:32,yellow:33,blue:34,magenta:35,cyan:36,white:37,redBackground:41,greenBackground:42,yellowBackground:43,blueBackground:44,magentaBackground:45,cyanBackground:46,whiteBackground:47,encircled:52,overlined:53,grey:90,black:90},d={SMILEY:"☺",SOLID_SMILEY:"☻",HEART:"♥",DIAMOND:"♦",CLOVE:"♣",SPADE:"♠",DOT:"•",SQUARE_CIRCLE:"◘",CIRCLE:"○",FILLED_SQUARE_CIRCLE:"◙",MALE:"♂",FEMALE:"♀",EIGHT_NOTE:"♪",DOUBLE_EIGHTH_NOTE:"♫",SUN:"☼",PLAY:"►",REWIND:"◄",UP_DOWN:"↕",PILCROW:"¶",SECTION:"§",THICK_MINUS:"▬",SMALL_UP_DOWN:"↨",UP_ARROW:"↑",DOWN_ARROW:"↓",RIGHT_ARROW:"→",LEFT_ARROW:"←",RIGHT_ANGLE:"∟",LEFT_RIGHT_ARROW:"↔",TRIANGLE:"▲",DOWN_TRIANGLE:"▼",HOUSE:"⌂",C_CEDILLA:"Ç",U_UMLAUT:"ü",E_ACCENT:"é",A_LOWER_CIRCUMFLEX:"â",A_LOWER_UMLAUT:"ä",A_LOWER_GRAVE_ACCENT:"à",A_LOWER_CIRCLE_OVER:"å",C_LOWER_CIRCUMFLEX:"ç",E_LOWER_CIRCUMFLEX:"ê",E_LOWER_UMLAUT:"ë",E_LOWER_GRAVE_ACCENT:"è",I_LOWER_UMLAUT:"ï",I_LOWER_CIRCUMFLEX:"î",I_LOWER_GRAVE_ACCENT:"ì",A_UPPER_UMLAUT:"Ä",A_UPPER_CIRCLE:"Å",E_UPPER_ACCENT:"É",A_E_LOWER:"æ",A_E_UPPER:"Æ",O_LOWER_CIRCUMFLEX:"ô",O_LOWER_UMLAUT:"ö",O_LOWER_GRAVE_ACCENT:"ò",U_LOWER_CIRCUMFLEX:"û",U_LOWER_GRAVE_ACCENT:"ù",Y_LOWER_UMLAUT:"ÿ",O_UPPER_UMLAUT:"Ö",U_UPPER_UMLAUT:"Ü",CENTS:"¢",POUND:"£",YEN:"¥",CURRENCY:"¤",PTS:"₧",FUNCTION:"ƒ",A_LOWER_ACCENT:"á",I_LOWER_ACCENT:"í",O_LOWER_ACCENT:"ó",U_LOWER_ACCENT:"ú",N_LOWER_TILDE:"ñ",N_UPPER_TILDE:"Ñ",A_SUPER:"ª",O_SUPER:"º",UPSIDEDOWN_QUESTION:"¿",SIDEWAYS_L:"⌐",NEGATION:"¬",ONE_HALF:"½",ONE_FOURTH:"¼",UPSIDEDOWN_EXCLAMATION:"¡",DOUBLE_LEFT:"«",DOUBLE_RIGHT:"»",LIGHT_SHADED_BOX:"░",MEDIUM_SHADED_BOX:"▒",DARK_SHADED_BOX:"▓",VERTICAL_LINE:"│",MAZE__SINGLE_RIGHT_T:"┤",MAZE_SINGLE_RIGHT_TOP:"┐",MAZE_SINGLE_RIGHT_BOTTOM_SMALL:"┘",MAZE_SINGLE_LEFT_TOP_SMALL:"┌",MAZE_SINGLE_LEFT_BOTTOM_SMALL:"└",MAZE_SINGLE_LEFT_T:"├",MAZE_SINGLE_BOTTOM_T:"┴",MAZE_SINGLE_TOP_T:"┬",MAZE_SINGLE_CENTER:"┼",MAZE_SINGLE_HORIZONTAL_LINE:"─",MAZE_SINGLE_RIGHT_DOUBLECENTER_T:"╡",MAZE_SINGLE_RIGHT_DOUBLE_BL:"╛",MAZE_SINGLE_RIGHT_DOUBLE_T:"╢",MAZE_SINGLE_RIGHT_DOUBLEBOTTOM_TOP:"╖",MAZE_SINGLE_RIGHT_DOUBLELEFT_TOP:"╕",MAZE_SINGLE_LEFT_DOUBLE_T:"╞",MAZE_SINGLE_BOTTOM_DOUBLE_T:"╧",MAZE_SINGLE_TOP_DOUBLE_T:"╤",MAZE_SINGLE_TOP_DOUBLECENTER_T:"╥",MAZE_SINGLE_BOTTOM_DOUBLECENTER_T:"╨",MAZE_SINGLE_LEFT_DOUBLERIGHT_BOTTOM:"╘",MAZE_SINGLE_LEFT_DOUBLERIGHT_TOP:"╒",MAZE_SINGLE_LEFT_DOUBLEBOTTOM_TOP:"╓",MAZE_SINGLE_LEFT_DOUBLETOP_BOTTOM:"╙",MAZE_SINGLE_LEFT_TOP:"Γ",MAZE_SINGLE_RIGHT_BOTTOM:"╜",MAZE_SINGLE_LEFT_CENTER:"╟",MAZE_SINGLE_DOUBLECENTER_CENTER:"╫",MAZE_SINGLE_DOUBLECROSS_CENTER:"╪",MAZE_DOUBLE_LEFT_CENTER:"╣",MAZE_DOUBLE_VERTICAL:"║",MAZE_DOUBLE_RIGHT_TOP:"╗",MAZE_DOUBLE_RIGHT_BOTTOM:"╝",MAZE_DOUBLE_LEFT_BOTTOM:"╚",MAZE_DOUBLE_LEFT_TOP:"╔",MAZE_DOUBLE_BOTTOM_T:"╩",MAZE_DOUBLE_TOP_T:"╦",MAZE_DOUBLE_LEFT_T:"╠",MAZE_DOUBLE_HORIZONTAL:"═",MAZE_DOUBLE_CROSS:"╬",SOLID_RECTANGLE:"█",THICK_LEFT_VERTICAL:"▌",THICK_RIGHT_VERTICAL:"▐",SOLID_SMALL_RECTANGLE_BOTTOM:"▄",SOLID_SMALL_RECTANGLE_TOP:"▀",PHI_UPPER:"Φ",INFINITY:"∞",INTERSECTION:"∩",DEFINITION:"≡",PLUS_MINUS:"±",GT_EQ:"≥",LT_EQ:"≤",THEREFORE:"⌠",SINCE:"∵",DOESNOT_EXIST:"∄",EXISTS:"∃",FOR_ALL:"∀",EXCLUSIVE_OR:"⊕",BECAUSE:"⌡",DIVIDE:"÷",APPROX:"≈",DEGREE:"°",BOLD_DOT:"∙",DOT_SMALL:"·",CHECK:"√",ITALIC_X:"✗",SUPER_N:"ⁿ",SQUARED:"²",CUBED:"³",SOLID_BOX:"■",PERMILE:"‰",REGISTERED_TM:"®",COPYRIGHT:"©",TRADEMARK:"™",BETA:"β",GAMMA:"γ",ZETA:"ζ",ETA:"η",IOTA:"ι",KAPPA:"κ",LAMBDA:"λ",NU:"ν",XI:"ξ",OMICRON:"ο",RHO:"ρ",UPSILON:"υ",CHI_LOWER:"φ",CHI_UPPER:"χ",PSI:"ψ",ALPHA:"α",ESZETT:"ß",PI:"π",SIGMA_UPPER:"Σ",SIGMA_LOWER:"σ",MU:"µ",TAU:"τ",THETA:"Θ",OMEGA:"Ω",DELTA:"δ",PHI_LOWER:"φ",EPSILON:"ε"},G={toArray:A,pad:T,truncate:O,multiply:I,format:i,style:u,escape:R,trim:a,trimLeft:f,trimRight:o,isEmpty:s};return E.define(e.isString,G).define(e.isArray,{style:u}).expose(G).expose({characters:d})}"undefined"!=typeof exports?"undefined"!=typeof module&&module.exports&&(module.exports=E(require("extended"),require("is-extended"),require("date-extended"),require("array-extended"))):"function"==typeof define?define(["extended","is-extended","date-extended","array-extended"],function(e,_,r,t){return E(e,_,r,t)}):this.stringExtended=E(this.extended,this.isExtended,this.dateExtended,this.arrayExtended)}).call(this);

@@ -5,2 +5,3 @@ "use strict";

stringExtended = require("../"),
arrayExtended = require("array-extended"),
dateExtended = require("date-extended");

@@ -22,100 +23,142 @@

it.describe("pad", function (it) {
it.should("pad correctly", function () {
assert.equal(stringExtended.pad("STR", 5, " "), " STR");
assert.equal(stringExtended.pad("STR", 5, " ", true), "STR ");
assert.equal(stringExtended.pad("STR", 5, "$"), "$$STR");
assert.equal(stringExtended.pad("STR", 5, "$", true), "STR$$");
it.describe("as a monad", function (it) {
assert.equal(stringExtended("STR").pad(5, " ").value(), " STR");
assert.equal(stringExtended("STR").pad(5, " ", true).value(), "STR ");
assert.equal(stringExtended("STR").pad(5, "$").value(), "$$STR");
assert.equal(stringExtended("STR").pad(5, "$", true).value(), "STR$$");
it.should("pad correctly", function () {
assert.equal(stringExtended("STR").pad(5, " ").value(), " STR");
assert.equal(stringExtended("STR").pad(5, " ", true).value(), "STR ");
assert.equal(stringExtended("STR").pad(5, "$").value(), "$$STR");
assert.equal(stringExtended("STR").pad(5, "$", true).value(), "STR$$");
});
});
it.describe("as a function", function (it) {
it.should("pad correctly", function () {
assert.equal(stringExtended.pad("STR", 5, " "), " STR");
assert.equal(stringExtended.pad("STR", 5, " ", true), "STR ");
assert.equal(stringExtended.pad("STR", 5, "$"), "$$STR");
assert.equal(stringExtended.pad("STR", 5, "$", true), "STR$$");
});
});
});
it.describe("format", function (it) {
it.should("format strings properly", function () {
assert.equal(stringExtended.format("{apple}, {orange}, {notthere} and {number}", {apple: "apple", orange: "orange", number: 10}), "apple, orange, {notthere} and 10");
assert.equal(stringExtended.format("{[-s10]apple}, {[%#10]orange}, {[10]banana} and {[-10]watermelons}", {apple: "apple", orange: "orange", banana: "bananas", watermelons: "watermelons"}), "applesssss, ####orange, bananas and watermelon");
assert.equal(stringExtended.format("{[- 10]number}, {[yyyy]date}, and {[4]object}", {number: 1, date: new Date(1970, 1, 1), object: {a: "b"}}), '1 , 1970, and {\n "a": "b"\n}');
assert.equal(stringExtended.format("%s and %s", ["apple", "orange"]), "apple and orange");
assert.equal(stringExtended.format("%s and %s and %s", ["apple", "orange"]), "apple and orange and %s");
assert.equal(stringExtended.format("%s and %s", "apple", "orange"), "apple and orange");
assert.equal(stringExtended.format("%-s10s, %#10s, %10s and %-10s", "apple", "orange", "bananas", "watermelons"), "applesssss, ####orange, bananas and watermelon");
assert.equal(stringExtended.format("%d and %d", 1, 2), "1 and 2");
assert.throws(function () {
stringExtended.format("%-10d", "a");
it.describe("as a monad", function (it) {
it.should("format strings properly", function () {
assert.equal(stringExtended("{apple}, {orange}, {notthere} and {number}").format({apple: "apple", orange: "orange", number: 10}).value(), "apple, orange, {notthere} and 10");
assert.equal(stringExtended("{[-s10]apple}, {[%#10]orange}, {[10]banana} and {[-10]watermelons}").format({apple: "apple", orange: "orange", banana: "bananas", watermelons: "watermelons"}).value(), "applesssss, ####orange, bananas and watermelon");
assert.equal(stringExtended("{[- 10]number}, {[yyyy]date}, and {[4]object}").format({number: 1, date: new Date(1970, 1, 1), object: {a: "b"}}).value(), '1 , 1970, and {\n "a": "b"\n}');
assert.equal(stringExtended("%s and %s").format(["apple", "orange"]).value(), "apple and orange");
assert.equal(stringExtended("%s and %s and %s").format(["apple", "orange"]).value(), "apple and orange and %s");
assert.equal(stringExtended("%s and %s").format("apple", "orange").value(), "apple and orange");
assert.equal(stringExtended("%-s10s, %#10s, %10s and %-10s").format("apple", "orange", "bananas", "watermelons").value(), "applesssss, ####orange, bananas and watermelon");
assert.equal(stringExtended("%d and %d").format(1, 2).value(), "1 and 2");
assert.throws(function () {
stringExtended("%-10d").format("a");
});
assert.equal(stringExtended("%+d, %+d, %10d, %-10d, %-+#10d, %10d").format(1, -2, 1, 2, 3, 100000000000).value(), "+1, -2, 0000000001, 2000000000, +3########, 1000000000");
assert.equal(stringExtended("%j").format([
{a: "b"}
]).value(), '{"a":"b"}');
var test = {};
test.test = test;
assert.throws(function () {
stringExtended("%j").format([test]);
});
assert.throws(function () {
stringExtended("%4j").format([test]);
});
var tzInfo = getTimeZoneOffset(new Date(-1));
assert.equal(stringExtended("%D").format([new Date(-1)]).value(), new Date(-1).toString());
var date = new Date(2006, 7, 11, 0, 55, 12, 345);
assert.equal(stringExtended("%[yyyy]D %[EEEE, MMMM dd, yyyy]D %[M/dd/yy]D %[H:m:s.SS]D").format([date, date, date, date]).value(), '2006 Friday, August 11, 2006 8/11/06 0:55:12.35');
assert.equal(stringExtended("%[yyyy]Z %[EEEE, MMMM dd, yyyy]Z %[M/dd/yy]Z %[H:m:s.SS]Z").format([date, date, date, date]).value(), '2006 Friday, August 11, 2006 8/11/06 ' + date.getUTCHours() + ':55:12.35');
assert.equal(stringExtended("%Z").format([new Date(-1)]).value(), new Date(-1).toUTCString());
assert.equal(stringExtended("%1j,\n%4j").format([
{a: "b"},
{a: "b"}
]).value(), '{\n "a": "b"\n},\n{\n "a": "b"\n}');
});
});
assert.equal(stringExtended.format("%+d, %+d, %10d, %-10d, %-+#10d, %10d", 1, -2, 1, 2, 3, 100000000000), "+1, -2, 0000000001, 2000000000, +3########, 1000000000");
assert.equal(stringExtended.format("%j", [
{a: "b"}
]), '{"a":"b"}');
var test = {};
assert.throws(function () {
stringExtended.format("%j", [comb.merge(test, {a: test})]);
it.describe("as a function", function (it) {
it.should("format strings properly", function () {
assert.equal(stringExtended.format("{apple}, {orange}, {notthere} and {number}", {apple: "apple", orange: "orange", number: 10}), "apple, orange, {notthere} and 10");
assert.equal(stringExtended.format("{[-s10]apple}, {[%#10]orange}, {[10]banana} and {[-10]watermelons}", {apple: "apple", orange: "orange", banana: "bananas", watermelons: "watermelons"}), "applesssss, ####orange, bananas and watermelon");
assert.equal(stringExtended.format("{[- 10]number}, {[yyyy]date}, and {[4]object}", {number: 1, date: new Date(1970, 1, 1), object: {a: "b"}}), '1 , 1970, and {\n "a": "b"\n}');
assert.equal(stringExtended.format("%s and %s", ["apple", "orange"]), "apple and orange");
assert.equal(stringExtended.format("%s and %s and %s", ["apple", "orange"]), "apple and orange and %s");
assert.equal(stringExtended.format("%s and %s", "apple", "orange"), "apple and orange");
assert.equal(stringExtended.format("%-s10s, %#10s, %10s and %-10s", "apple", "orange", "bananas", "watermelons"), "applesssss, ####orange, bananas and watermelon");
assert.equal(stringExtended.format("%d and %d", 1, 2), "1 and 2");
assert.throws(function () {
stringExtended.format("%-10d", "a");
});
assert.equal(stringExtended.format("%+d, %+d, %10d, %-10d, %-+#10d, %10d", 1, -2, 1, 2, 3, 100000000000), "+1, -2, 0000000001, 2000000000, +3########, 1000000000");
assert.equal(stringExtended.format("%j", [
{a: "b"}
]), '{"a":"b"}');
var test = {};
test.test = test;
assert.throws(function () {
stringExtended.format("%j", [test]);
});
assert.throws(function () {
stringExtended.format("%4j", [test]);
});
var tzInfo = getTimeZoneOffset(new Date(-1));
assert.equal(stringExtended.format("%D", [new Date(-1)]), new Date(-1).toString());
var date = new Date(2006, 7, 11, 0, 55, 12, 345), tzInfo = getTimeZoneOffset(date);
assert.equal(stringExtended.format("%[yyyy]D %[EEEE, MMMM dd, yyyy]D %[M/dd/yy]D %[H:m:s.SS]D", [date, date, date, date]), '2006 Friday, August 11, 2006 8/11/06 0:55:12.35');
assert.equal(stringExtended.format("%[yyyy]Z %[EEEE, MMMM dd, yyyy]Z %[M/dd/yy]Z %[H:m:s.SS]Z", [date, date, date, date]), '2006 Friday, August 11, 2006 8/11/06 ' + date.getUTCHours() + ':55:12.35');
assert.equal(stringExtended.format("%Z", [new Date(-1)]), new Date(-1).toUTCString());
assert.equal(stringExtended.format("%1j,\n%4j", [
{a: "b"},
{a: "b"}
]), '{\n "a": "b"\n},\n{\n "a": "b"\n}');
});
});
assert.throws(function () {
stringExtended.format("%4j", [comb.merge(test, {a: test})]);
});
var tzInfo = getTimeZoneOffset(new Date(-1));
assert.equal(stringExtended.format("%D", [new Date(-1)]), new Date(-1).toString());
var date = new Date(2006, 7, 11, 0, 55, 12, 345), tzInfo = getTimeZoneOffset(date);
assert.equal(stringExtended.format("%[yyyy]D %[EEEE, MMMM dd, yyyy]D %[M/dd/yy]D %[H:m:s.SS]D", [date, date, date, date]), '2006 Friday, August 11, 2006 8/11/06 0:55:12.35');
assert.equal(stringExtended.format("%[yyyy]Z %[EEEE, MMMM dd, yyyy]Z %[M/dd/yy]Z %[H:m:s.SS]Z", [date, date, date, date]), '2006 Friday, August 11, 2006 8/11/06 ' + date.getUTCHours() + ':55:12.35');
assert.equal(stringExtended.format("%Z", [new Date(-1)]), new Date(-1).toUTCString());
assert.equal(stringExtended.format("%1j,\n%4j", [
{a: "b"},
{a: "b"}
]), '{\n "a": "b"\n},\n{\n "a": "b"\n}');
});
assert.equal(stringExtended("{apple}, {orange}, {notthere} and {number}").format({apple: "apple", orange: "orange", number: 10}).value(), "apple, orange, {notthere} and 10");
assert.equal(stringExtended("{[-s10]apple}, {[%#10]orange}, {[10]banana} and {[-10]watermelons}").format({apple: "apple", orange: "orange", banana: "bananas", watermelons: "watermelons"}).value(), "applesssss, ####orange, bananas and watermelon");
assert.equal(stringExtended("{[- 10]number}, {[yyyy]date}, and {[4]object}").format({number: 1, date: new Date(1970, 1, 1), object: {a: "b"}}).value(), '1 , 1970, and {\n "a": "b"\n}');
assert.equal(stringExtended("%s and %s").format(["apple", "orange"]).value(), "apple and orange");
assert.equal(stringExtended("%s and %s and %s").format(["apple", "orange"]).value(), "apple and orange and %s");
assert.equal(stringExtended("%s and %s").format("apple", "orange").value(), "apple and orange");
assert.equal(stringExtended("%-s10s, %#10s, %10s and %-10s").format("apple", "orange", "bananas", "watermelons").value(), "applesssss, ####orange, bananas and watermelon");
assert.equal(stringExtended("%d and %d").format(1, 2).value(), "1 and 2");
assert.throws(function () {
stringExtended("%-10d").format("a");
it.describe("toArray", function (it) {
it.describe("as a monad", function (it) {
it.should("convert strings to arrays", function () {
assert.deepEqual(stringExtended("a|b|c|d").toArray("|").value(), ["a", "b", "c", "d"]);
assert.deepEqual(stringExtended("a").toArray("|").value(), ["a"]);
assert.deepEqual(stringExtended("").toArray("|").value(), []);
});
});
assert.equal(stringExtended("%+d, %+d, %10d, %-10d, %-+#10d, %10d").format(1, -2, 1, 2, 3, 100000000000).value(), "+1, -2, 0000000001, 2000000000, +3########, 1000000000");
assert.equal(stringExtended("%j").format([
{a: "b"}
]).value(), '{"a":"b"}');
var test = {};
test.test = test;
assert.throws(function () {
stringExtended("%j").format([test]);
it.describe("as a function", function (it) {
it.should("convert strings to arrays", function () {
assert.deepEqual(stringExtended.toArray("a|b|c|d", "|"), ["a", "b", "c", "d"]);
assert.deepEqual(stringExtended.toArray("a", "|"), ["a"]);
assert.deepEqual(stringExtended.toArray("", "|"), []);
});
});
assert.throws(function () {
stringExtended("%4j").format([test]);
});
var tzInfo = getTimeZoneOffset(new Date(-1));
assert.equal(stringExtended("%D").format([new Date(-1)]).value(), new Date(-1).toString());
var date = new Date(2006, 7, 11, 0, 55, 12, 345);
assert.equal(stringExtended("%[yyyy]D %[EEEE, MMMM dd, yyyy]D %[M/dd/yy]D %[H:m:s.SS]D").format([date, date, date, date]).value(), '2006 Friday, August 11, 2006 8/11/06 0:55:12.35');
assert.equal(stringExtended("%[yyyy]Z %[EEEE, MMMM dd, yyyy]Z %[M/dd/yy]Z %[H:m:s.SS]Z").format([date, date, date, date]).value(), '2006 Friday, August 11, 2006 8/11/06 ' + date.getUTCHours() + ':55:12.35');
assert.equal(stringExtended("%Z").format([new Date(-1)]).value(), new Date(-1).toUTCString());
assert.equal(stringExtended("%1j,\n%4j").format([
{a: "b"},
{a: "b"}
]).value(), '{\n "a": "b"\n},\n{\n "a": "b"\n}');
});
it.should("convert strings to arrays", function () {
assert.deepEqual(stringExtended.toArray("a|b|c|d", "|"), ["a", "b", "c", "d"]);
assert.deepEqual(stringExtended.toArray("a", "|"), ["a"]);
assert.deepEqual(stringExtended.toArray("", "|"), []);
it.describe("style", function (it) {
assert.deepEqual(stringExtended("a|b|c|d").toArray("|").value(), ["a", "b", "c", "d"]);
assert.deepEqual(stringExtended("a").toArray("|").value(), ["a"]);
assert.deepEqual(stringExtended("").toArray("|").value(), []);
});
it.should("style strings properly", function () {
var styles = {

@@ -149,49 +192,180 @@ bold: 1,

grey: 90,
black: 90 };
for (var i in styles) {
assert.equal(stringExtended.style(i, i), '\x1B[' + styles[i] + 'm' + i + '\x1B[0m');
assert.equal(stringExtended(i).style(i).value(), '\x1B[' + styles[i] + 'm' + i + '\x1B[0m');
}
assert.equal(stringExtended.style("string", ["bold", "red", "redBackground"]), '\x1B[41m\x1B[31m\x1B[1mstring\x1B[0m\x1B[0m\x1B[0m');
assert.equal(stringExtended("string").style(["bold", "red", "redBackground"]).value(), '\x1B[41m\x1B[31m\x1B[1mstring\x1B[0m\x1B[0m\x1B[0m');
assert.deepEqual(stringExtended.style(["string1", "string2", "string3"], ["bold", "red", "redBackground"]),
[
'\x1B[41m\x1B[31m\x1B[1mstring1\x1B[0m\x1B[0m\x1B[0m',
'\x1B[41m\x1B[31m\x1B[1mstring2\x1B[0m\x1B[0m\x1B[0m',
'\x1B[41m\x1B[31m\x1B[1mstring3\x1B[0m\x1B[0m\x1B[0m']
);
black: 90
};
assert.deepEqual(stringExtended(["string1", "string2", "string3"]).style(["bold", "red", "redBackground"]).value(),
[
'\x1B[41m\x1B[31m\x1B[1mstring1\x1B[0m\x1B[0m\x1B[0m',
'\x1B[41m\x1B[31m\x1B[1mstring2\x1B[0m\x1B[0m\x1B[0m',
'\x1B[41m\x1B[31m\x1B[1mstring3\x1B[0m\x1B[0m\x1B[0m']
);
it.describe("as a monad", function (it) {
it.should("style strings properly", function () {
for (var i in styles) {
assert.equal(stringExtended(i).style(i).value(), '\x1B[' + styles[i] + 'm' + i + '\x1B[0m');
}
assert.equal(stringExtended("string").style(["bold", "red", "redBackground"]).value(), '\x1B[41m\x1B[31m\x1B[1mstring\x1B[0m\x1B[0m\x1B[0m');
assert.deepEqual(stringExtended(["string1", "string2", "string3"]).style(["bold", "red", "redBackground"]).value(),
[
'\x1B[41m\x1B[31m\x1B[1mstring1\x1B[0m\x1B[0m\x1B[0m',
'\x1B[41m\x1B[31m\x1B[1mstring2\x1B[0m\x1B[0m\x1B[0m',
'\x1B[41m\x1B[31m\x1B[1mstring3\x1B[0m\x1B[0m\x1B[0m'
]
);
});
});
it.describe("as a function", function (it) {
it.should("style strings properly", function () {
for (var i in styles) {
assert.equal(stringExtended.style(i, i), '\x1B[' + styles[i] + 'm' + i + '\x1B[0m');
}
assert.equal(stringExtended.style("string", ["bold", "red", "redBackground"]), '\x1B[41m\x1B[31m\x1B[1mstring\x1B[0m\x1B[0m\x1B[0m');
assert.deepEqual(stringExtended.style(["string1", "string2", "string3"], ["bold", "red", "redBackground"]),
[
'\x1B[41m\x1B[31m\x1B[1mstring1\x1B[0m\x1B[0m\x1B[0m',
'\x1B[41m\x1B[31m\x1B[1mstring2\x1B[0m\x1B[0m\x1B[0m',
'\x1B[41m\x1B[31m\x1B[1mstring3\x1B[0m\x1B[0m\x1B[0m'
]
);
});
});
});
it.should("multiply strings properly", function () {
assert.equal(stringExtended.multiply("a"), "");
assert.equal(stringExtended.multiply("a", 1), "a");
assert.equal(stringExtended.multiply("a", 2), "aa");
assert.equal(stringExtended.multiply("a", 3), "aaa");
it.describe("multiply", function (it) {
assert.equal(stringExtended("a").multiply().value(), "");
assert.equal(stringExtended("a").multiply(1).value(), "a");
assert.equal(stringExtended("a").multiply(2).value(), "aa");
assert.equal(stringExtended("a").multiply(3).value(), "aaa");
it.describe("as a monad", function (it) {
it.should("multiply strings properly", function () {
assert.equal(stringExtended("a").multiply().value(), "");
assert.equal(stringExtended("a").multiply(1).value(), "a");
assert.equal(stringExtended("a").multiply(2).value(), "aa");
assert.equal(stringExtended("a").multiply(3).value(), "aaa");
});
});
it.describe("as a function", function (it) {
it.should("multiply strings properly", function () {
assert.equal(stringExtended.multiply("a"), "");
assert.equal(stringExtended.multiply("a", 1), "a");
assert.equal(stringExtended.multiply("a", 2), "aa");
assert.equal(stringExtended.multiply("a", 3), "aaa");
});
});
});
it.should("truncate strings properly", function () {
assert.equal(stringExtended.truncate("abcdefg", 3), "abc");
assert.equal(stringExtended.truncate("abcdefg", 3, true), "efg");
assert.equal(stringExtended.truncate(new Date(1970, 1, 1), 3), "Sun");
assert.equal(stringExtended.truncate(123, 1), "1");
it.describe("truncate", function (it) {
assert.equal(stringExtended("abcdefg").truncate(3).value(), "abc");
assert.equal(stringExtended("abcdefg").truncate(3, true).value(), "efg");
it.describe("as a monad", function (it) {
it.should("truncate strings properly", function () {
assert.equal(stringExtended("abcdefg").truncate(3).value(), "abc");
assert.equal(stringExtended("abcdefg").truncate(3, true).value(), "efg");
});
});
it.describe("as a function", function (it) {
it.should("truncate strings properly", function () {
assert.equal(stringExtended.truncate("abcdefg", 3), "abc");
assert.equal(stringExtended.truncate("abcdefg", 3, true), "efg");
assert.equal(stringExtended.truncate(new Date(1970, 1, 1), 3), "Sun");
assert.equal(stringExtended.truncate(123, 1), "1");
});
});
});
it.describe("escape", function (it) {
var chars = arrayExtended([".", "$", "?", "*", "|", "{", "}", "(", ")", "[", "]", "\\", "/", "+", "^"]);
it.describe("as a monad", function (it) {
it.should("escape it properly", function () {
chars.forEach(function (c) {
assert.equal(stringExtended(c).escape().value(), "\\" + c);
});
chars.forEach(function (c) {
assert.equal(stringExtended(c).escape([c]).value(), c);
});
});
});
it.describe("as a function", function (it) {
it.should("escape it properly", function () {
chars.forEach(function (c) {
assert.equal(stringExtended.escape(c), "\\" + c);
});
chars.forEach(function (c) {
assert.equal(stringExtended.escape(c, [c]), c);
});
});
});
});
it.describe("trim", function (it) {
it.describe("as a monad", function (it) {
it.should("trim properly", function () {
assert.equal(stringExtended(" Hello World ").trim().value(), "Hello World");
assert.equal(stringExtended("\t\t\tHello World\t\t\t").trim().value(), "Hello World");
});
});
it.describe("as a function", function (it) {
it.should("trim properly", function () {
assert.equal(stringExtended.trim(" Hello World "), "Hello World");
assert.equal(stringExtended.trim("\t\t\tHello World\t\t\t"), "Hello World");
});
});
});
it.describe("trimLeft", function (it) {
it.describe("as a monad", function (it) {
it.should("trimLeft properly", function () {
assert.equal(stringExtended(" Hello World ").trimLeft().value(), "Hello World ");
assert.equal(stringExtended("\t\t\tHello World\t\t\t").trimLeft().value(), "Hello World\t\t\t");
});
});
it.describe("as a function", function (it) {
it.should("trim properly", function () {
assert.equal(stringExtended.trimLeft(" Hello World "), "Hello World ");
assert.equal(stringExtended.trimLeft("\t\t\tHello World\t\t\t"), "Hello World\t\t\t");
});
});
});
it.describe("trimRight", function (it) {
it.describe("as a monad", function (it) {
it.should("trimRight properly", function () {
assert.equal(stringExtended(" Hello World ").trimRight().value(), " Hello World");
assert.equal(stringExtended("\t\t\tHello World\t\t\t").trimRight().value(), "\t\t\tHello World");
});
});
it.describe("as a function", function (it) {
it.should("trimRight properly", function () {
assert.equal(stringExtended.trimRight(" Hello World "), " Hello World");
assert.equal(stringExtended.trimRight("\t\t\tHello World\t\t\t"), "\t\t\tHello World");
});
});
});
}).as(module).run();

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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