ngx-string-helper
Advanced tools
Comparing version 2.0.9 to 2.0.10
@@ -85,3 +85,31 @@ (function (global, factory) { | ||
}; | ||
NgxStrHelper.prototype.replaceAll = function (str, find, replace, ignorecase) { | ||
var flags = (ignorecase === true) ? 'gi' : 'g'; | ||
var reg = new RegExp(find, flags); | ||
return str.replace(reg, replace); | ||
}; | ||
NgxStrHelper.prototype.isBlank = function (str) { | ||
return (/^\s*$/).test(str); | ||
}; | ||
NgxStrHelper.prototype.reverse = function (str) { | ||
return this.chars(str).reverse().join(''); | ||
}; | ||
NgxStrHelper.prototype.startsWith = function (str, starts, position) { | ||
starts = '' + starts; | ||
position = position == null ? 0 : Math.min(this.toPositive(position), str.length); | ||
return str.lastIndexOf(starts, position) === position; | ||
}; | ||
NgxStrHelper.prototype.endsWith = function (str, ends, position) { | ||
ends = '' + ends; | ||
if (typeof position == 'undefined') { | ||
position = str.length - ends.length; | ||
} | ||
else { | ||
position = Math.min(this.toPositive(position), str.length) - ends.length; | ||
} | ||
return position >= 0 && str.indexOf(ends, position) === position; | ||
}; | ||
NgxStrHelper.prototype.toPositive = function (num) { | ||
return num < 0 ? 0 : (+num || 0); | ||
}; | ||
return NgxStrHelper; | ||
@@ -88,0 +116,0 @@ }()); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core")):"function"==typeof define&&define.amd?define(["exports","@angular/core"],t):t(e["ngx-string-helper"]=e["ngx-string-helper"]||{},e.ng.core)}(this,function(e,t){"use strict";function r(){return new n}var n=function(){function e(){this.escapeChars={"¢":"cent","£":"pound","¥":"yen","€":"euro","©":"copy","®":"reg","<":"lt",">":"gt",'"':"quot","&":"amp","'":"#39"}}return e.prototype.isNullOrEmpty=function(e){return void 0===e||null===e||""===e},e.prototype.truncate=function(e,t){return e.substring(0,t)+"..."},e.prototype.contains=function(e,t){return e.indexOf(t)>=0},e.prototype.toSlug=function(e){return e.toLowerCase().replace(/ /g,"-").replace(/[^\w-]+/g,"")},e.prototype.decapitalize=function(e){return e.charAt(0).toLowerCase()+e.slice(1)},e.prototype.capitalize=function(e,t){var r=t?e.slice(1).toLowerCase():e.slice(1);return e.charAt(0).toUpperCase()+r},e.prototype.clean=function(e){return e.trim().replace(/\s\s+/g," ")},e.prototype.chars=function(e){return e.split("")},e.prototype.swapCase=function(e){return e.replace(/\S/g,function(e){return e===e.toUpperCase()?e.toLowerCase():e.toUpperCase()})},e.prototype.include=function(e,t){return""===t||-1!==e.indexOf(t)},e.prototype.count=function(e,t){return 0===e.length||0===t.length?0:e.split(t).length-1},e.prototype.escapeHTML=function(e){var t="[";for(var r in this.escapeChars)t+=r;t+="]";var n=new RegExp(t,"g");return e.replace(n,function(e){return"&"+this.escapeChars[e]+";"})},e.prototype.insert=function(e,t,r){return this.splice(e,t,0,r)},e.prototype.splice=function(e,t,r,n){var o=this.chars(e);return o.splice(~~t,~~r,n),o.join("")},e}();n.decorators=[{type:t.Injectable}],n.ctorParameters=function(){return[]};var o=function(){function e(){}return e}();o.decorators=[{type:t.NgModule,args:[{providers:[{provide:n,useFactory:r}]}]}],o.ctorParameters=function(){return[]},e.NgxStrHelperModule=o,e.NgxStrHelper=n,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core")):"function"==typeof define&&define.amd?define(["exports","@angular/core"],e):e(t["ngx-string-helper"]=t["ngx-string-helper"]||{},t.ng.core)}(this,function(t,e){"use strict";function r(){return new n}var n=function(){function t(){this.escapeChars={"¢":"cent","£":"pound","¥":"yen","€":"euro","©":"copy","®":"reg","<":"lt",">":"gt",'"':"quot","&":"amp","'":"#39"}}return t.prototype.isNullOrEmpty=function(t){return void 0===t||null===t||""===t},t.prototype.truncate=function(t,e){return t.substring(0,e)+"..."},t.prototype.contains=function(t,e){return t.indexOf(e)>=0},t.prototype.toSlug=function(t){return t.toLowerCase().replace(/ /g,"-").replace(/[^\w-]+/g,"")},t.prototype.decapitalize=function(t){return t.charAt(0).toLowerCase()+t.slice(1)},t.prototype.capitalize=function(t,e){var r=e?t.slice(1).toLowerCase():t.slice(1);return t.charAt(0).toUpperCase()+r},t.prototype.clean=function(t){return t.trim().replace(/\s\s+/g," ")},t.prototype.chars=function(t){return t.split("")},t.prototype.swapCase=function(t){return t.replace(/\S/g,function(t){return t===t.toUpperCase()?t.toLowerCase():t.toUpperCase()})},t.prototype.include=function(t,e){return""===e||-1!==t.indexOf(e)},t.prototype.count=function(t,e){return 0===t.length||0===e.length?0:t.split(e).length-1},t.prototype.escapeHTML=function(t){var e="[";for(var r in this.escapeChars)e+=r;e+="]";var n=new RegExp(e,"g");return t.replace(n,function(t){return"&"+this.escapeChars[t]+";"})},t.prototype.insert=function(t,e,r){return this.splice(t,e,0,r)},t.prototype.splice=function(t,e,r,n){var o=this.chars(t);return o.splice(~~e,~~r,n),o.join("")},t.prototype.replaceAll=function(t,e,r,n){var o=!0===n?"gi":"g",i=new RegExp(e,o);return t.replace(i,r)},t.prototype.isBlank=function(t){return/^\s*$/.test(t)},t.prototype.reverse=function(t){return this.chars(t).reverse().join("")},t.prototype.startsWith=function(t,e,r){return e=""+e,r=null==r?0:Math.min(this.toPositive(r),t.length),t.lastIndexOf(e,r)===r},t.prototype.endsWith=function(t,e,r){return e=""+e,(r=void 0===r?t.length-e.length:Math.min(this.toPositive(r),t.length)-e.length)>=0&&t.indexOf(e,r)===r},t.prototype.toPositive=function(t){return t<0?0:+t||0},t}();n.decorators=[{type:e.Injectable}],n.ctorParameters=function(){return[]};var o=function(){function t(){}return t}();o.decorators=[{type:e.NgModule,args:[{providers:[{provide:n,useFactory:r}]}]}],o.ctorParameters=function(){return[]},t.NgxStrHelperModule=o,t.NgxStrHelper=n,Object.defineProperty(t,"__esModule",{value:!0})}); |
{ | ||
"name": "ngx-string-helper", | ||
"version": "2.0.9", | ||
"description": "Just a simple lightweight Angular 2+ string helper.", | ||
"version": "2.0.10", | ||
"description": "Ngx lacks complete string manipulation operations. This is an attempt to fill that gap.", | ||
"main": "index.js", | ||
@@ -19,4 +19,8 @@ "scripts": { | ||
"angular2 string helper", | ||
"Angular", | ||
"NPM" | ||
"ng2 string helper", | ||
"ngx string helper", | ||
"angular string helper", | ||
"angular string utils", | ||
"angular", | ||
"npm" | ||
], | ||
@@ -23,0 +27,0 @@ "author": "Thuyet's", |
## Angular 2+ String Helper | ||
Just a simple lightweight Angular 2+ string helper | ||
Ngx lacks complete string manipulation operations. This is an attempt to fill that gap. | ||
@@ -55,2 +55,9 @@ ## Installation | ||
``` | ||
#### NgxStrHelper.isBlank(); | ||
```javascript | ||
isBlank(""); // => Outputs: true | ||
isBlank("\n"); // => Outputs: true | ||
isBlank(" "); // => Outputs: true | ||
isBlank("a"); // => Outputs: false | ||
``` | ||
#### NgxStrHelper.contains(); | ||
@@ -136,2 +143,29 @@ ```javascript | ||
``` | ||
#### NgxStrHelper.replaceAll(); | ||
```javascript | ||
ngxStrHelper.replaceAll("foo", "o", "a"); | ||
// => Outputs: "faa" | ||
``` | ||
#### NgxStrHelper.reverse(); | ||
Return reversed string | ||
```javascript | ||
ngxStrHelper.reverse("foobar"); | ||
// => Outputs: "raboof" | ||
``` | ||
#### NgxStrHelper.startsWith(); | ||
This method checks whether the string begins with starts at position (default: 0) | ||
```javascript | ||
ngxStrHelper.startsWith("image.gif", "image"); | ||
// => Outputs: true | ||
ngxStrHelper.startsWith(".vimrc", "vim", 1); | ||
// => Outputs: true | ||
``` | ||
#### NgxStrHelper.endsWith(); | ||
This method checks whether the string ends with ends at position (default: string.length). | ||
```javascript | ||
ngxStrHelper.endsWith("image.gif", "gif"); | ||
// => Outputs: true | ||
ngxStrHelper.("image.old.gif", "old", 9); | ||
// => Outputs: true | ||
``` | ||
#### Thanks and enjoy! |
@@ -18,2 +18,8 @@ export declare class NgxStrHelper { | ||
splice(str: string, i: number, howmany: number, substr: string): string; | ||
replaceAll(str: string, find: string, replace: string, ignorecase: boolean): string; | ||
isBlank(str: string): boolean; | ||
reverse(str: string): string; | ||
startsWith(str: string, starts: string, position: number): boolean; | ||
endsWith(str: string, ends: string, position: number): boolean; | ||
toPositive(num: number): number; | ||
} |
@@ -80,3 +80,31 @@ import { Injectable } from '@angular/core'; | ||
}; | ||
; | ||
NgxStrHelper.prototype.replaceAll = function (str, find, replace, ignorecase) { | ||
var flags = (ignorecase === true) ? 'gi' : 'g'; | ||
var reg = new RegExp(find, flags); | ||
return str.replace(reg, replace); | ||
}; | ||
NgxStrHelper.prototype.isBlank = function (str) { | ||
return (/^\s*$/).test(str); | ||
}; | ||
NgxStrHelper.prototype.reverse = function (str) { | ||
return this.chars(str).reverse().join(''); | ||
}; | ||
NgxStrHelper.prototype.startsWith = function (str, starts, position) { | ||
starts = '' + starts; | ||
position = position == null ? 0 : Math.min(this.toPositive(position), str.length); | ||
return str.lastIndexOf(starts, position) === position; | ||
}; | ||
NgxStrHelper.prototype.endsWith = function (str, ends, position) { | ||
ends = '' + ends; | ||
if (typeof position == 'undefined') { | ||
position = str.length - ends.length; | ||
} | ||
else { | ||
position = Math.min(this.toPositive(position), str.length) - ends.length; | ||
} | ||
return position >= 0 && str.indexOf(ends, position) === position; | ||
}; | ||
NgxStrHelper.prototype.toPositive = function (num) { | ||
return num < 0 ? 0 : (+num || 0); | ||
}; | ||
return NgxStrHelper; | ||
@@ -83,0 +111,0 @@ }()); |
@@ -1,1 +0,1 @@ | ||
[{"__symbolic":"module","version":3,"metadata":{"NgxStrHelper":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor"}],"isNullOrEmpty":[{"__symbolic":"method"}],"truncate":[{"__symbolic":"method"}],"contains":[{"__symbolic":"method"}],"toSlug":[{"__symbolic":"method"}],"decapitalize":[{"__symbolic":"method"}],"capitalize":[{"__symbolic":"method"}],"clean":[{"__symbolic":"method"}],"chars":[{"__symbolic":"method"}],"swapCase":[{"__symbolic":"method"}],"include":[{"__symbolic":"method"}],"count":[{"__symbolic":"method"}],"escapeHTML":[{"__symbolic":"method"}],"insert":[{"__symbolic":"method"}],"splice":[{"__symbolic":"method"}]}}}},{"__symbolic":"module","version":1,"metadata":{"NgxStrHelper":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor"}],"isNullOrEmpty":[{"__symbolic":"method"}],"truncate":[{"__symbolic":"method"}],"contains":[{"__symbolic":"method"}],"toSlug":[{"__symbolic":"method"}],"decapitalize":[{"__symbolic":"method"}],"capitalize":[{"__symbolic":"method"}],"clean":[{"__symbolic":"method"}],"chars":[{"__symbolic":"method"}],"swapCase":[{"__symbolic":"method"}],"include":[{"__symbolic":"method"}],"count":[{"__symbolic":"method"}],"escapeHTML":[{"__symbolic":"method"}],"insert":[{"__symbolic":"method"}],"splice":[{"__symbolic":"method"}]}}}}] | ||
[{"__symbolic":"module","version":3,"metadata":{"NgxStrHelper":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor"}],"isNullOrEmpty":[{"__symbolic":"method"}],"truncate":[{"__symbolic":"method"}],"contains":[{"__symbolic":"method"}],"toSlug":[{"__symbolic":"method"}],"decapitalize":[{"__symbolic":"method"}],"capitalize":[{"__symbolic":"method"}],"clean":[{"__symbolic":"method"}],"chars":[{"__symbolic":"method"}],"swapCase":[{"__symbolic":"method"}],"include":[{"__symbolic":"method"}],"count":[{"__symbolic":"method"}],"escapeHTML":[{"__symbolic":"method"}],"insert":[{"__symbolic":"method"}],"splice":[{"__symbolic":"method"}],"replaceAll":[{"__symbolic":"method"}],"isBlank":[{"__symbolic":"method"}],"reverse":[{"__symbolic":"method"}],"startsWith":[{"__symbolic":"method"}],"endsWith":[{"__symbolic":"method"}],"toPositive":[{"__symbolic":"method"}]}}}},{"__symbolic":"module","version":1,"metadata":{"NgxStrHelper":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor"}],"isNullOrEmpty":[{"__symbolic":"method"}],"truncate":[{"__symbolic":"method"}],"contains":[{"__symbolic":"method"}],"toSlug":[{"__symbolic":"method"}],"decapitalize":[{"__symbolic":"method"}],"capitalize":[{"__symbolic":"method"}],"clean":[{"__symbolic":"method"}],"chars":[{"__symbolic":"method"}],"swapCase":[{"__symbolic":"method"}],"include":[{"__symbolic":"method"}],"count":[{"__symbolic":"method"}],"escapeHTML":[{"__symbolic":"method"}],"insert":[{"__symbolic":"method"}],"splice":[{"__symbolic":"method"}],"replaceAll":[{"__symbolic":"method"}],"isBlank":[{"__symbolic":"method"}],"reverse":[{"__symbolic":"method"}],"startsWith":[{"__symbolic":"method"}],"endsWith":[{"__symbolic":"method"}],"toPositive":[{"__symbolic":"method"}]}}}}] |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35407
317
170