-
Notifications
You must be signed in to change notification settings - Fork 0
/
strdash.min.js
7 lines (7 loc) · 1.38 KB
/
strdash.min.js
1
2
3
4
5
6
7
/* @license
strdash
v0.1.0
https://github.com/bunlong/strdash
License: MIT
*/
!function(t,r){"function"==typeof define&&define.amd?define([],r):"object"==typeof module&&"undefined"!=typeof exports?module.exports=r():t.str=r()}(this,function(){"use strict";function r(t){var r;t=t,(r=this).str__=null==t||"string"==typeof t?t:t.toString(),null!=(r.orig__=t)?r.__defineGetter__?r.__defineGetter__("length",function(){return r.str__.length}):r.length__=t.length:r.length__=-1}return r.prototype={isEmpty:function(){return null===this.str__||void 0===this.str__||/^[\s\xa0]*$/.test(this.str__)},isNumeric:function(){return!/[^0-9]/.test(this.str__)},isAlpha:function(){return!/[^0-9a-z\xDF-\xFF]/.test(this.str__.toLowerCase())},isAlphaNumeric:function(){return!/[^0-9a-z\xDF-\xFF]/.test(this.str__.toLowerCase())},isLowerCase:function(){return this.isAlpha()&&this.str__.toLowerCase()===this.str__},isUpperCase:function(){return this.isAlpha()&&this.str__.toUpperCase()===this.str__},toBoolean:function(){if("string"!=typeof this.orig__)return!0===this.orig__||1===this.orig__;var t=this.str__.toLowerCase();return"true"===t||"yes"===t||"on"===t||"1"===t},toInt:function(){return/^\s*-?0x/i.test(this.str__)?parseInt(this.str__,16):parseInt(this.str__,10)},toFloat:function(t){var r=parseFloat(this.str__);return t?parseFloat(r.toFixed(t)):r},toString:function(){return this.str__}},function(t){return new r(t)}});