Comparing version 0.4.0 to 0.4.2
{ | ||
"name": "words.js", | ||
"version": "0.4.0", | ||
"version": "0.4.2", | ||
"description": "A library/toolbox for working with words and strings.", | ||
"main": "words.min.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"uglify": "uglifyjs words.js -c -m -o words.min.js", | ||
"build": "coffee -c --transpile words.coffee && npm run uglify", | ||
"test": "jasmine" | ||
}, | ||
@@ -29,4 +31,10 @@ "repository": { | ||
"homepage": "https://github.com/phazelift/words.js", | ||
"dependencies": {}, | ||
"devDependencies": {} | ||
"dependencies": { | ||
"strings.js": "latest" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "latest", | ||
"@babel/preset-env": "latest", | ||
"jasmine": "latest" | ||
} | ||
} |
123
README.md
words.js | ||
======== | ||
**words.js** is a library/toolbox for working with strings and words. Great for handling command-line or text input, | ||
educational tools, word-games, text filters, password generators, etc.. | ||
**words.js** is a library/toolbox for working with strings and words. Great for handling command-line or text input, educational tools, word-games, text filters, password generators, etc.. | ||
<br/> | ||
@@ -11,3 +10,6 @@ ___ | ||
```javascript | ||
var words= new Words('pick the words you need with indices'); | ||
import Words from 'words.js'; | ||
const words = new Words('pick the words you need with indices'); | ||
console.log( words.get(1, 3, -2, 3) ); | ||
@@ -39,3 +41,3 @@ // pick words with words | ||
words.set('Words.startsWith searches for starting words, not characters!'); | ||
words.set('.startsWith searches for the first(delimiting) space after the first word'); | ||
console.log( words.startsWith('Words.') ); | ||
@@ -49,52 +51,15 @@ // false | ||
___ | ||
**Dependencies and loading** | ||
words.js includes types.js and strings.js. | ||
words.js depends on strings.js. | ||
- types.js is a tiny, but essential type-checker/enforcer. It's API can be found at: https://github.com/phazelift/types.js | ||
- strings.js is a flexible string manipulation library. It's API can be found at: https://github.com/phazelift/strings.js | ||
In the browser you can access them via the following global variables: | ||
- Types | ||
- Strings | ||
- Words | ||
**node.js** | ||
You can use `npm install words.js` when you're on node.js. | ||
In npm, words.js, types.js and strings.js can be accessed in the following way: | ||
```javascript | ||
var Words = require('words.js'); | ||
var Types = require('words.js').Types; | ||
// to have the non-overloaded strings.js | ||
var Strings = require('words.js').Strings; | ||
``` | ||
**AMD** | ||
When using AMD, you can load types.js like so: | ||
```javascript | ||
require.config({ | ||
paths: { | ||
'types', [ 'path/to/types.min(.js)' ] | ||
} | ||
}); | ||
require( ['types'], function( Types ){ | ||
console.log( Types.isNumber(0) ); | ||
// true | ||
}); | ||
``` | ||
___ | ||
Most methods overload strings.js methods, only to focus on words rather than characters. | ||
Where in strings.js you use shuffle to randomly reorder the characters in a string, in words.js the overloaded | ||
shuffle function randomly reorders the words in a string, or you can shuffle the characters of a specific word in | ||
a string, and much more. See the API for some sweet examples. | ||
Where in strings.js you use shuffle to randomly reorder the characters in a string, in words.js the overloaded shuffle function randomly reorders the words in a string, or you can shuffle the characters of a specific word in a string, and much more. See the API for examples. | ||
<br/><br/> | ||
All indexes in words.js are 1 based. Negative indexes can be used in most functions. -1 references the last | ||
word in the internal words array, 1 references the first word. | ||
All indexes in words.js are 1 based. Negative indexes can be used in most functions. -1 references the last word in the internal words array, 1 references the first word. | ||
@@ -104,7 +69,4 @@ words.js is made for chaining operations on words in strings, most of it's methods return their | ||
___ | ||
All input and output is type save; you can throw in any type and still get a string if the expected output is of | ||
type `<string>`. If any method receives an argument of a type it cannot process, the argument will simply be ignored. | ||
All input and output is type save; you can throw in any type and still get a string if the expected output is of type `<string>`. If any method receives an argument of a type it cannot process, the argument will simply be ignored. | ||
All examples are to be found in the API below. | ||
___ | ||
@@ -114,23 +76,9 @@ API | ||
If you see `<string>/<number>`, it means you can either enter a String or Number argument, both will be parsed | ||
correctly. | ||
If you see `<string>/<number>`, it means you can either enter a String or Number argument, both will be parsed correctly. | ||
___ | ||
**Words.flexArgs** | ||
> `Words.flexArgs( arg1, ..., argN )` | ||
***- DEPRECATED!! -*** | ||
Use .intoArray instead of .flexArgs. | ||
.flexArgs has been renamed to 'intoArray' and is now part of the included types.js. .intoArray is 100% compatible, | ||
it shouldn't break any code. .flexArgs still works, but it will be removed from words.js eventually. | ||
See types.js .intoArray for a description. | ||
___ | ||
**Words.prototype.words** | ||
> `<array> words` | ||
> The internal array were all (space seperated) words are stored. Better not use directly to avoid bugs, instead | ||
> use .set() to set, and .get(), .$ and .string to fetch. | ||
> The internal array were all (space seperated) words are stored. Better not use directly to avoid bugs, instead use .set() to set, and .get(), .$ and .string to fetch. | ||
@@ -164,4 +112,3 @@ **Words.prototype.constructor** | ||
> Set this.words with string(s). The strings can be given in the 3 (types.js) .intoArray forms, see .intoArray | ||
description in types.js. | ||
> Set this.words with string(s). The strings can be given in the 3 (types.js) .intoArray forms, see .intoArray description in types.js. | ||
@@ -206,8 +153,5 @@ > Use any combination of arguments to form a string. All invalid arguments will be ignored. | ||
> Access every index/word of this.words and apply the result of callback to it. After a call to xs, this.words | ||
> will be changed to the results of the callback. | ||
> Access every index/word of this.words and apply the result of callback to it. After a call to xs, this.words will be changed to the results of the callback. | ||
> If the callback returns true, word is applied, but you could also return word which has effectively the same result. | ||
> If the callback returns false or undefined, word will be skipped. Any character, String or Number returned by callback | ||
> will be applied to index in this.words. | ||
> If the callback returns true, word is applied, but you could also return word which has effectively the same result. If the callback returns false or undefined, word will be skipped. Any character, String or Number returned by callback will be applied to index in this.words. | ||
@@ -239,6 +183,3 @@ ```javascript | ||
> Change words or characters to uppercase. If no arguments are given, all words are changed to uppercase. | ||
> If index is set to 0, all character positions denoted by position, in all words, are changed to uppercase | ||
> (if alpha of course). If indices is not set to 0, the words found on indices are changed to uppercase. valueN can | ||
> also be a word, and words can be mixed with indices. | ||
> Change words or characters to uppercase. If no arguments are given, all words are changed to uppercase. If index is set to 0, all character positions denoted by position, in all words, are changed to uppercase (if alpha of course). If indices is not set to 0, the words found on indices are changed to uppercase. valueN can also be a word, and words can be mixed with indices. | ||
@@ -267,6 +208,3 @@ ```javascript | ||
> Without arguments this.words is reversed; not the characters, like with Strings.reverse(), but the words | ||
> positions in this.words are reversed. If index is 0, every word is reversed, but will remain on it's original/current index, | ||
> every additional argument is then ignored. With index or indices given, the characters in the words | ||
> denoted by indices are reversed. | ||
> Without arguments this.words is reversed; not the characters, like with Strings.reverse(), but the words positions in this.words are reversed. If index is 0, every word is reversed, but will remain on it's original/current index, every additional argument is then ignored. With index or indices given, the characters in the words denoted by indices are reversed. | ||
@@ -290,5 +228,3 @@ ```javascript | ||
> Shuffles the word on index, if index is given. If index is/are strings, the matching words will be shuffled. | ||
> If index is 0, every word is shuffled, but will remain on it's current index, following arguments are ignored. | ||
> Without arguments, all indices are shuffled. | ||
> Shuffles the word on index, if index is given. If index is/are strings, the matching words will be shuffled. If index is 0, every word is shuffled, but will remain on it's current index, following arguments are ignored. Without arguments, all indices are shuffled. | ||
@@ -319,4 +255,3 @@ ```javascript | ||
> Removes any combination of indices or words from this.words. Without arguments remove does nothing. | ||
> Invalid arguments are ignored | ||
> Removes any combination of indices or words from this.words. Without arguments remove does nothing. Invalid arguments are ignored | ||
@@ -332,4 +267,3 @@ ```javascript | ||
> Removes the last word from this.words if no arguments are given. If amount is valid, amount words will be removed from | ||
> this.words, starting from the last word going backwards. | ||
> Removes the last word from this.words if no arguments are given. If amount is valid, amount words will be removed from this.words, starting from the last word going backwards. | ||
@@ -361,4 +295,3 @@ > A string of all words 'popped' in reverse order, will be returned. | ||
> Removes the first word from this.words if no arguments are given. If amount is valid, amount words will | ||
> be removed from this.words, starting from the first word going forwards. | ||
> Removes the first word from this.words if no arguments are given. If amount is valid, amount words will be removed from this.words, starting from the first word going forwards. | ||
@@ -442,2 +375,11 @@ ```javascript | ||
========== | ||
**0.4.1** | ||
replaced deprecated code with strings.js dependency | ||
adds babel transpile stage for higher quality bundle code (improved compatibility) | ||
upgraded jasmin testing setup | ||
cleaned up the readme | ||
--- | ||
**0.4.0** | ||
@@ -453,4 +395,3 @@ | ||
Deprecated .flexArgs. .flexArgs is now included (in the included) types.js and has been renamed to .intoArray. | ||
So, use .intoArray instead of .flexArgs which will be removed at some point in time. | ||
Deprecated .flexArgs. .flexArgs is now included (in the included) types.js and has been renamed to .intoArray. Use .intoArray instead of .flexArgs which will be removed at some point in time. | ||
___ | ||
@@ -457,0 +398,0 @@ **0.3.8** |
1821
words.js
@@ -1,1555 +0,611 @@ | ||
(function() { | ||
"use strict"; | ||
var Chars, LITERALS, Strings, Strings_, TYPES, Types, Words, Words_, breakIfEqual, createForce, instanceOf, mapStringToNumber, testValues, typeOf, _, | ||
__slice = [].slice, | ||
__hasProp = {}.hasOwnProperty, | ||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
"use strict"; | ||
instanceOf = function(type, value) { | ||
return value instanceof type; | ||
}; | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
typeOf = function(value, type) { | ||
if (type == null) { | ||
type = 'object'; | ||
} | ||
return typeof value === type; | ||
}; | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
LITERALS = { | ||
'Boolean': false, | ||
'String': '', | ||
'Object': {}, | ||
'Array': [], | ||
'Function': function() {}, | ||
'Number': (function() { | ||
var number; | ||
number = new Number; | ||
number["void"] = true; | ||
return number; | ||
})() | ||
}; | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
TYPES = { | ||
'Undefined': function(value) { | ||
return value === void 0; | ||
}, | ||
'Null': function(value) { | ||
return value === null; | ||
}, | ||
'Function': function(value) { | ||
return typeOf(value, 'function'); | ||
}, | ||
'Boolean': function(value) { | ||
return typeOf(value, 'boolean'); | ||
}, | ||
'String': function(value) { | ||
return typeOf(value, 'string'); | ||
}, | ||
'Array': function(value) { | ||
return typeOf(value) && instanceOf(Array, value); | ||
}, | ||
'RegExp': function(value) { | ||
return typeOf(value) && instanceOf(RegExp, value); | ||
}, | ||
'Date': function(value) { | ||
return typeOf(value) && instanceOf(Date, value); | ||
}, | ||
'Number': function(value) { | ||
return typeOf(value, 'number') && (value === value) || (typeOf(value) && instanceOf(Number, value)); | ||
}, | ||
'Object': function(value) { | ||
return typeOf(value) && (value !== null) && !instanceOf(Boolean, value) && !instanceOf(Number, value) && !instanceOf(Array, value) && !instanceOf(RegExp, value) && !instanceOf(Date, value); | ||
}, | ||
'NaN': function(value) { | ||
return typeOf(value, 'number') && (value !== value); | ||
}, | ||
'Defined': function(value) { | ||
return value !== void 0; | ||
} | ||
}; | ||
function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
TYPES.StringOrNumber = function(value) { | ||
return TYPES.String(value) || TYPES.Number(value); | ||
}; | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
Types = _ = { | ||
parseIntBase: 10 | ||
}; | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
createForce = function(type) { | ||
var convertType; | ||
convertType = function(value) { | ||
switch (type) { | ||
case 'Number': | ||
if ((_.isNumber(value = parseInt(value, _.parseIntBase))) && !value["void"]) { | ||
return value; | ||
} | ||
break; | ||
case 'String': | ||
if (_.isStringOrNumber(value)) { | ||
return value + ''; | ||
} | ||
break; | ||
default: | ||
if (Types['is' + type](value)) { | ||
return value; | ||
} | ||
} | ||
}; | ||
return function(value, replacement) { | ||
if ((value != null) && void 0 !== (value = convertType(value))) { | ||
return value; | ||
} | ||
if ((replacement != null) && void 0 !== (replacement = convertType(replacement))) { | ||
return replacement; | ||
} | ||
return LITERALS[type]; | ||
}; | ||
}; | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } | ||
testValues = function(predicate, breakState, values) { | ||
var value, _i, _len; | ||
if (values == null) { | ||
values = []; | ||
} | ||
if (values.length < 1) { | ||
return predicate === TYPES.Undefined; | ||
} | ||
for (_i = 0, _len = values.length; _i < _len; _i++) { | ||
value = values[_i]; | ||
if (predicate(value) === breakState) { | ||
return breakState; | ||
} | ||
} | ||
return !breakState; | ||
}; | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
breakIfEqual = true; | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
(function() { | ||
var name, predicate, _results; | ||
_results = []; | ||
for (name in TYPES) { | ||
predicate = TYPES[name]; | ||
_results.push((function(name, predicate) { | ||
Types['is' + name] = predicate; | ||
Types['not' + name] = function(value) { | ||
return !predicate(value); | ||
}; | ||
Types['has' + name] = function() { | ||
return testValues(predicate, breakIfEqual, arguments); | ||
}; | ||
Types['all' + name] = function() { | ||
return testValues(predicate, !breakIfEqual, arguments); | ||
}; | ||
if (name in LITERALS) { | ||
return Types['force' + name] = createForce(name); | ||
} | ||
})(name, predicate)); | ||
} | ||
return _results; | ||
})(); | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
Types.intoArray = function() { | ||
var args; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
if (args.length < 2) { | ||
if (_.isString(args[0])) { | ||
args = args.join('').replace(/^\s+|\s+$/g, '').replace(/\s+/g, ' ').split(' '); | ||
} else if (_.isArray(args[0])) { | ||
args = args[0]; | ||
} | ||
} | ||
return args; | ||
}; | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
Types["typeof"] = function(value) { | ||
var name, predicate; | ||
for (name in TYPES) { | ||
predicate = TYPES[name]; | ||
if (predicate(value) === true) { | ||
return name.toLowerCase(); | ||
} | ||
} | ||
}; | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); } | ||
mapStringToNumber = function(array) { | ||
var index, nr, value, _i, _len; | ||
if (_.notArray(array)) { | ||
return 0; | ||
} | ||
for (index = _i = 0, _len = array.length; _i < _len; index = ++_i) { | ||
value = array[index]; | ||
nr = _.forceNumber(value); | ||
if (nr["void"]) { | ||
return index; | ||
} | ||
array[index] = nr; | ||
} | ||
return array.length; | ||
}; | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
_ = (function(_super) { | ||
__extends(_, _super); | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _() { | ||
return _.__super__.constructor.apply(this, arguments); | ||
} | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
_.inRange = function(nr, range) { | ||
if ((_.isNaN(nr = parseInt(nr, 10))) || (mapStringToNumber(range) < 2)) { | ||
return false; | ||
} | ||
return (nr >= range[0]) && (nr <= range[1]); | ||
}; | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
_.limitNumber = function(nr, range) { | ||
nr = _.forceNumber(nr, 0); | ||
if (mapStringToNumber(range) < 2) { | ||
return nr; | ||
} | ||
if (nr < range[0]) { | ||
return range[0]; | ||
} | ||
if (nr > range[1]) { | ||
return range[1]; | ||
} | ||
return nr; | ||
}; | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
_.randomNumber = function(min, max) { | ||
if (mapStringToNumber([min, max]) < 2) { | ||
return 0; | ||
} | ||
if (max < min) { | ||
return min; | ||
} | ||
max = (max - min) + 1; | ||
return Math.floor((Math.random() * max) + min); | ||
}; | ||
// Generated by CoffeeScript 2.5.1 | ||
(function () { | ||
// words.coffee - A Javascript word-string manipulation library, written in Coffeescript. | ||
// MIT License | ||
// Copyright (c) 2014 Dennis Raymondo van der Sluis | ||
// 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. | ||
"use strict"; | ||
_.shuffleArray = function(array) { | ||
var i, length, rand, temp, _i; | ||
if (_.notArray(array) || array.length < 1) { | ||
return []; | ||
} | ||
length = array.length - 1; | ||
for (i = _i = length; length <= 0 ? _i <= 0 : _i >= 0; i = length <= 0 ? ++_i : --_i) { | ||
rand = _.randomNumber(0, i); | ||
temp = array[i]; | ||
array[i] = array[rand]; | ||
array[rand] = temp; | ||
} | ||
return array; | ||
}; | ||
var Chars, Strings, Words, Words_, _, types; | ||
_.positiveIndex = function(index, max) { | ||
if (0 === (index = _.forceNumber(index, 0))) { | ||
return false; | ||
} | ||
max = Math.abs(_.forceNumber(max)); | ||
if (Math.abs(index) <= max) { | ||
if (index > 0) { | ||
return index - 1; | ||
} | ||
return max + index; | ||
} | ||
return false; | ||
}; | ||
Strings = _ = require("strings.js"); | ||
types = Strings.Types; | ||
Chars = Strings.Chars; | ||
_.insertSort = function(array) { | ||
var current, index, length, prev, _i; | ||
length = array.length - 1; | ||
for (index = _i = 1; 1 <= length ? _i <= length : _i >= length; index = 1 <= length ? ++_i : --_i) { | ||
current = array[index]; | ||
prev = index - 1; | ||
while ((prev >= 0) && (array[prev] > current)) { | ||
array[prev + 1] = array[prev]; | ||
--prev; | ||
} | ||
array[+prev + 1] = current; | ||
Words_ = function () { | ||
var Words_ = /*#__PURE__*/function () { | ||
function Words_() { | ||
_classCallCheck(this, Words_); | ||
} | ||
return array; | ||
}; | ||
_.noDupAndReverse = function(array) { | ||
var index, length, newArr, _i; | ||
length = array.length - 1; | ||
newArr = []; | ||
for (index = _i = length; length <= 0 ? _i <= 0 : _i >= 0; index = length <= 0 ? ++_i : --_i) { | ||
if (newArr[newArr.length - 1] !== array[index]) { | ||
newArr.push(array[index]); | ||
} | ||
} | ||
return newArr; | ||
}; | ||
_createClass(Words_, null, [{ | ||
key: "stringsFromArray", | ||
value: function stringsFromArray(array) { | ||
var i, len, ref, strings, value; | ||
strings = []; | ||
ref = _.forceArray(array); | ||
_.sortNoDupAndReverse = function(array, maxLength) { | ||
var index, processed, value, _i, _len; | ||
processed = []; | ||
for (index = _i = 0, _len = array.length; _i < _len; index = ++_i) { | ||
value = array[index]; | ||
value = _.forceNumber(value); | ||
if (value["void"]) { | ||
continue; | ||
} | ||
if (value <= maxLength) { | ||
value = _.positiveIndex(value, maxLength); | ||
} | ||
processed.push(_.forceNumber(value, 0)); | ||
} | ||
return _.noDupAndReverse(_.insertSort(processed)); | ||
}; | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
value = ref[i]; | ||
return _; | ||
if (_.isString(value)) { | ||
strings.push(value); | ||
} | ||
} | ||
})(Types); | ||
return strings; | ||
} | ||
}, { | ||
key: "numbersFromArray", | ||
value: function numbersFromArray(array) { | ||
var i, len, numbers, ref, value; | ||
numbers = []; | ||
ref = _.forceArray(array); | ||
Chars = (function(_super) { | ||
__extends(Chars, _super); | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
value = ref[i]; | ||
function Chars() { | ||
return Chars.__super__.constructor.apply(this, arguments); | ||
} | ||
if (_.isNumber(value)) { | ||
numbers.push(value + 0); | ||
} | ||
} | ||
Chars.ASCII_RANGE_UPPERCASE = [65, 90]; | ||
return numbers; | ||
} // call with context! | ||
Chars.ASCII_RANGE_LOWERCASE = [97, 122]; | ||
}, { | ||
key: "changeCase", | ||
value: function changeCase(method, args) { | ||
var i, index, indices, j, len, len1, pos, ref, results, results1, words; | ||
words = Words_.stringsFromArray(args); | ||
indices = Words_.numbersFromArray(args); | ||
Chars.ASCII_RANGE_NUMBERS = [48, 57]; | ||
if (words.length > 0) { | ||
var _Strings; | ||
Chars.ASCII_RANGE_SPECIAL_1 = [32, 47]; | ||
this.set((_Strings = Strings)[method].apply(_Strings, [this.string].concat(_toConsumableArray(words)))); // strings | ||
} | ||
Chars.ASCII_RANGE_SPECIAL_2 = [58, 64]; | ||
if (indices[0] === 0) { | ||
// words[indices] (characters) | ||
results = []; | ||
Chars.ASCII_RANGE_SPECIAL_3 = [91, 96]; | ||
for (i = 0, len = indices.length; i < len; i++) { | ||
pos = indices[i]; | ||
results.push(function () { | ||
var j, ref, results1; | ||
results1 = []; | ||
Chars.ASCII_RANGE_SPECIAL_4 = [123, 126]; | ||
for (index = j = 0, ref = this.count - 1; 0 <= ref ? j <= ref : j >= ref; index = 0 <= ref ? ++j : --j) { | ||
results1.push(this.words[index] = Strings[method](this.words[index], pos)); | ||
} | ||
Chars.ASCII_RANGE_ALL = [32, 126]; | ||
return results1; | ||
}.call(this)); | ||
} | ||
Chars.REGEXP_SPECIAL_CHARS = ['?', '\\', '[', ']', '(', ')', '*', '+', '.', '/', '|', '^', '$', '<', '>', '-', '&']; | ||
return results; | ||
} else { | ||
if (args.length < 1) { | ||
// words | ||
indices = function () { | ||
var results1 = []; | ||
Chars.ascii = function(ordinal) { | ||
return String.fromCharCode(_.forceNumber(ordinal)); | ||
}; | ||
for (var j = 0, ref = this.count; 0 <= ref ? j <= ref : j >= ref; 0 <= ref ? j++ : j--) { | ||
results1.push(j); | ||
} | ||
Chars.ordinal = function(char) { | ||
return _.forceNumber(_.forceString(char).charCodeAt(), 0); | ||
}; | ||
return results1; | ||
}.apply(this); | ||
} | ||
Chars.random = function(range) { | ||
var max, min; | ||
range = _.forceArray(range, Chars.ASCII_RANGE_ALL); | ||
min = _.limitNumber(range[0], range); | ||
max = _.limitNumber(range[1], range); | ||
return Chars.ascii(_.randomNumber(min, max)); | ||
}; | ||
results1 = []; | ||
return Chars; | ||
for (j = 0, len1 = indices.length; j < len1; j++) { | ||
index = indices[j]; | ||
index = _.positiveIndex(index, this.count); | ||
results1.push(this.words[index] = Strings[method](this.words[index])); | ||
} | ||
})(_); | ||
return results1; | ||
} | ||
} | ||
}, { | ||
key: "applyToValidIndex", | ||
value: function applyToValidIndex(orgIndex, limit, callback) { | ||
var index; | ||
Strings_ = (function() { | ||
function Strings_() {} | ||
Strings_.changeCase = function() { | ||
var arg, args, caseMethod, pos, string, _i, _j, _len, _len1; | ||
string = arguments[0], caseMethod = arguments[1], args = 3 <= arguments.length ? __slice.call(arguments, 2) : []; | ||
if (string == null) { | ||
string = ''; | ||
} | ||
if ('' === (string = _.forceString(string))) { | ||
return string; | ||
} | ||
if ((args.length < 1) || args[0] === void 0) { | ||
return string[caseMethod](); | ||
} else if (_.isNumber(args[0])) { | ||
for (_i = 0, _len = args.length; _i < _len; _i++) { | ||
arg = args[_i]; | ||
pos = _.positiveIndex(arg, string.length); | ||
string = Strings.xs(string, function(char, index) { | ||
if (index === pos) { | ||
return char[caseMethod](); | ||
} | ||
return char; | ||
}); | ||
if (false !== (index = _.positiveIndex(orgIndex, limit))) { | ||
return callback(index); | ||
} | ||
} | ||
} else if (_.isString(args[0])) { | ||
for (_j = 0, _len1 = args.length; _j < _len1; _j++) { | ||
arg = args[_j]; | ||
string = Strings.replace(string, arg, arg[caseMethod](), 'gi'); | ||
} | ||
} | ||
return string; | ||
}; | ||
}]); | ||
return Strings_; | ||
return Words_; | ||
}(); | ||
})(); | ||
; | ||
Words_.delimiter = ' '; | ||
return Words_; | ||
}.call(this); | ||
Strings = (function(_super) { | ||
__extends(Strings, _super); | ||
Words = /*#__PURE__*/function (_Strings2) { | ||
_inherits(Words, _Strings2); | ||
Strings.create = function() { | ||
var arg, string, _i, _len; | ||
string = ''; | ||
for (_i = 0, _len = arguments.length; _i < _len; _i++) { | ||
arg = arguments[_i]; | ||
string += _.forceString(arg); | ||
} | ||
return string; | ||
}; | ||
var _super = _createSuper(Words); | ||
Strings.get = function() { | ||
var argsLength, length, pos, positions, result, string, _i; | ||
string = arguments[0], positions = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
if (arguments.length < 2) { | ||
return ''; | ||
function Words() { | ||
var _this; | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
string = _.forceString(string); | ||
length = string.length; | ||
result = ''; | ||
argsLength = arguments.length; | ||
for (pos = _i = 1; 1 <= argsLength ? _i <= argsLength : _i >= argsLength; pos = 1 <= argsLength ? ++_i : --_i) { | ||
pos = _.positiveIndex(arguments[pos], length); | ||
if (pos !== false) { | ||
result += string[pos]; | ||
} | ||
} | ||
return result; | ||
}; | ||
Strings.sort = function(string) { | ||
string = _.forceString(string).trim().split(''); | ||
return _.insertSort(string).join(''); | ||
}; | ||
_classCallCheck(this, Words); | ||
Strings.random = function(amount, charSet) { | ||
var i, string, _i; | ||
amount = _.forceNumber(amount, 1); | ||
string = ''; | ||
for (i = _i = 1; 1 <= amount ? _i <= amount : _i >= amount; i = 1 <= amount ? ++_i : --_i) { | ||
string += Chars.random(charSet); | ||
} | ||
return string; | ||
}; | ||
_this = _super.call(this); | ||
Strings.times = function(string, amount) { | ||
var multi; | ||
if ('' === (string = _.forceString(string))) { | ||
return ''; | ||
} | ||
amount = _.forceNumber(amount, 1); | ||
multi = ''; | ||
while (amount-- > 0) { | ||
multi += string; | ||
} | ||
return multi; | ||
}; | ||
_this.set.apply(_assertThisInitialized(_this), arguments); | ||
Strings.regEscape = function(string) { | ||
if ('' === (string = _.forceString(string))) { | ||
return string; | ||
} | ||
return Strings.xs(string, function(char) { | ||
if (__indexOf.call(Chars.REGEXP_SPECIAL_CHARS, char) >= 0) { | ||
return '\\' + char; | ||
return _this; | ||
} | ||
_createClass(Words, [{ | ||
key: "set", | ||
value: function set() { | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
return true; | ||
}); | ||
}; | ||
Strings.empty = function(string) { | ||
if (_.notString(string) || (string.length > 0)) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
var arg, i, j, len, len1, ref, str; | ||
this.words = []; | ||
args = _.intoArray.apply(this, args); | ||
Strings.isAlpha = function(string) { | ||
if ('' === (string = _.forceString(string))) { | ||
return false; | ||
} | ||
return /^[a-z]*$/ig.test(string); | ||
}; | ||
if (args.length < 1) { | ||
return this; | ||
} | ||
Strings.isNumeric = function(string) { | ||
if ('' === (string = _.forceString(string))) { | ||
return false; | ||
} | ||
return /^[0-9]*$/g.test(string); | ||
}; | ||
for (i = 0, len = args.length; i < len; i++) { | ||
arg = args[i]; | ||
ref = Strings.split(Strings.create(arg), Words_.delimiter); | ||
Strings.isAlphaNumeric = function(string) { | ||
if ('' === (string = _.forceString(string))) { | ||
return false; | ||
} | ||
return /^[0-9|a-z]*$/ig.test(string); | ||
}; | ||
for (j = 0, len1 = ref.length; j < len1; j++) { | ||
str = ref[j]; | ||
this.words.push(str); | ||
} | ||
} | ||
Strings.isSpecial = function(string) { | ||
if ('' === (string = _.forceString(string))) { | ||
return false; | ||
return this; | ||
} | ||
return /^[^0-9|a-z]*$/ig.test(string); | ||
}; | ||
}, { | ||
key: "get", | ||
value: function get() { | ||
var i, index, len, string; | ||
Strings.isSpace = function(string) { | ||
return /^[ \t]+$/g.test(string); | ||
}; | ||
if (arguments.length < 1) { | ||
return this.words.join(Words_.delimiter); | ||
} | ||
Strings.hasUpper = function(string) { | ||
return /[A-Z]+/g.test(string); | ||
}; | ||
string = ''; | ||
Strings.isUpper = function(string) { | ||
return /^[A-Z]+$/g.test(string); | ||
}; | ||
for (i = 0, len = arguments.length; i < len; i++) { | ||
index = arguments[i]; | ||
index = _.positiveIndex(index, this.count); | ||
Strings.isLower = function(string) { | ||
return /^[a-z]+$/g.test(string); | ||
}; | ||
Strings.xs = function(string, callback) { | ||
var index, length, response, result, _i; | ||
if (string == null) { | ||
string = ''; | ||
} | ||
string = _.forceString(string); | ||
if (-1 === (length = string.length - 1)) { | ||
return ''; | ||
} | ||
callback = _.forceFunction(callback, function(char) { | ||
return char; | ||
}); | ||
result = ''; | ||
for (index = _i = 0; 0 <= length ? _i <= length : _i >= length; index = 0 <= length ? ++_i : --_i) { | ||
if (response = callback(string[index], index)) { | ||
if (response === true) { | ||
result += string[index]; | ||
} else if (_.isStringOrNumber(response)) { | ||
result += response; | ||
if (index !== false) { | ||
string += this.words[index] + Words_.delimiter; | ||
} | ||
} | ||
} | ||
return result; | ||
}; | ||
Strings.copy = function(string, offset, amount) { | ||
offset = _.forceNumber(offset); | ||
if (('' === (string = _.forceString(string))) || (Math.abs(offset) > string.length)) { | ||
return ''; | ||
return Strings.trim(string); | ||
} | ||
if (offset > 0) { | ||
offset -= 1; | ||
} | ||
return string.substr(offset, _.forceNumber(amount, string.length)); | ||
}; | ||
}, { | ||
key: "xs", | ||
value: function xs() { | ||
var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () { | ||
return true; | ||
}; | ||
var i, index, len, ref, response, result, word; | ||
Strings.replace = function(string, toReplace, replacement, flags) { | ||
var _ref; | ||
if (string == null) { | ||
string = ''; | ||
} | ||
if (toReplace == null) { | ||
toReplace = ''; | ||
} | ||
if (replacement == null) { | ||
replacement = ''; | ||
} | ||
if (flags == null) { | ||
flags = 'g'; | ||
} | ||
if (!(_.isStringOrNumber(string) && ((_ref = _["typeof"](toReplace)) === 'string' || _ref === 'number' || _ref === 'regexp'))) { | ||
return _.forceString(string); | ||
} | ||
if (_.notRegExp(toReplace)) { | ||
toReplace = Strings.regEscape(toReplace + ''); | ||
toReplace = new RegExp(toReplace, flags); | ||
} | ||
return (string + '').replace(toReplace, replacement); | ||
}; | ||
if (_.notFunction(callback) || this.count < 1) { | ||
return this; | ||
} | ||
Strings.trim = function(string) { | ||
return Strings.replace(string, /^\s+|\s+$/g); | ||
}; | ||
result = []; | ||
ref = this.words; | ||
Strings.trimLeft = function(string) { | ||
return Strings.replace(string, /^\s+/g); | ||
}; | ||
for (index = i = 0, len = ref.length; i < len; index = ++i) { | ||
word = ref[index]; | ||
Strings.trimRight = function(string) { | ||
return Strings.replace(string, /\s+$/g); | ||
}; | ||
if (response = callback(word, index)) { | ||
if (response === true) { | ||
result.push(word); | ||
} else if (_.isStringOrNumber(response)) { | ||
result.push(response + ''); | ||
} | ||
} | ||
} | ||
Strings.oneSpace = function(string) { | ||
return Strings.replace(string, /\s+/g, ' '); | ||
}; | ||
this.words = result; | ||
return this; | ||
} | ||
}, { | ||
key: "find", | ||
value: function find(string) { | ||
var indices; | ||
indices = []; | ||
Strings.oneSpaceAndTrim = function(string) { | ||
return Strings.oneSpace(Strings.trim(string)); | ||
}; | ||
if ('' !== (string = _.forceString(string))) { | ||
this.xs(function (word, index) { | ||
if (word === string) { | ||
indices.push(index + 1); | ||
} | ||
Strings.toCamel = function(string, char) { | ||
var match; | ||
string = _.forceString(string); | ||
char = _.forceString(char, '-'); | ||
match = new RegExp(Strings.regEscape(char) + '([a-z])', 'ig'); | ||
return Strings.replace(string, match, function(all, found) { | ||
return found.toUpperCase(); | ||
}); | ||
}; | ||
return true; | ||
}); | ||
} | ||
Strings.unCamel = function(string, insertion) { | ||
string = _.forceString(string); | ||
insertion = _.forceString(insertion, '-'); | ||
return Strings.replace(string, /([A-Z])/g, insertion + '$1').toLowerCase(); | ||
}; | ||
Strings.shuffle = function(string) { | ||
string = _.forceString(string); | ||
return _.shuffleArray((string + '').split('')).join(''); | ||
}; | ||
Strings.find = function(string, toFind, flags) { | ||
var indices, result; | ||
indices = []; | ||
if ('' === (string = _.forceString(string))) { | ||
return indices; | ||
} | ||
flags = _.forceString(flags, 'g'); | ||
if (_.isStringOrNumber(toFind)) { | ||
toFind = new RegExp(Strings.regEscape(toFind + ''), flags); | ||
} else if (_.isRegExp(toFind)) { | ||
toFind = new RegExp(toFind.source, flags); | ||
} else { | ||
return indices; | ||
}, { | ||
key: "upper", | ||
value: function upper() { | ||
Words_.changeCase.call(this, 'upper', Array.prototype.slice.call(arguments)); | ||
return this; | ||
} | ||
if (toFind.global) { | ||
while (result = toFind.exec(string)) { | ||
indices.push(result.index + 1); | ||
} | ||
} else { | ||
if (result = toFind.exec(string)) { | ||
indices.push(result.index + 1); | ||
} | ||
}, { | ||
key: "lower", | ||
value: function lower() { | ||
Words_.changeCase.call(this, 'lower', Array.prototype.slice.call(arguments)); | ||
return this; | ||
} | ||
return indices; | ||
}; | ||
}, { | ||
key: "reverse", | ||
value: function reverse() { | ||
var _this2 = this; | ||
Strings.count = function(string, toFind) { | ||
return Strings.find(string, toFind).length; | ||
}; | ||
var arg, i, len; | ||
Strings.contains = function(string, substring) { | ||
return Strings.count(string, substring) > 0; | ||
}; | ||
if ((arguments != null ? arguments[0] : void 0) === 0) { | ||
this.xs(function (word) { | ||
return Strings.reverse(word); | ||
}); | ||
} else if (arguments.length > 0) { | ||
for (i = 0, len = arguments.length; i < len; i++) { | ||
arg = arguments[i]; | ||
Words_.applyToValidIndex(arg, this.count, function (index) { | ||
return _this2.words[index] = Strings.reverse(_this2.words[index]); | ||
}); | ||
} | ||
} else { | ||
this.xs(function (word, index) { | ||
return _this2.get(_this2.count - index); | ||
}); | ||
} | ||
Strings.between = function(string, before, after) { | ||
var reg, _ref; | ||
if (!_.allStringOrNumber(string, before, after)) { | ||
return ''; | ||
return this; | ||
} | ||
before = Strings.regEscape(before + ''); | ||
after = Strings.regEscape(after + ''); | ||
reg = new RegExp(before + '(.+)' + after); | ||
return ((_ref = reg.exec(string + '')) != null ? _ref[1] : void 0) || ''; | ||
}; | ||
}, { | ||
key: "shuffle", | ||
value: function shuffle(selection) { | ||
var _this3 = this; | ||
Strings.slice = function(string, start, size) { | ||
string = _.forceString(string); | ||
start = _.forceNumber(start || 1); | ||
if (false !== (start = _.positiveIndex(start, string.length))) { | ||
size = _.forceNumber(size); | ||
return string.slice(start, start + size); | ||
} | ||
return ''; | ||
}; | ||
var arg, i, j, len, len1; | ||
Strings.truncate = function(string, length, appendix) { | ||
string = _.forceString(string); | ||
length = _.forceNumber(length, string.length); | ||
string = Strings.slice(string, 1, length); | ||
return string + _.forceString(appendix); | ||
}; | ||
if (selection != null) { | ||
if (_.isString(selection)) { | ||
for (i = 0, len = arguments.length; i < len; i++) { | ||
arg = arguments[i]; | ||
this.xs(function (word, index) { | ||
if (word === arg) { | ||
return Strings.shuffle(word); | ||
} | ||
Strings.pop = function(string, amount) { | ||
string = _.forceString(string); | ||
amount = _.forceNumber(amount, 1); | ||
return string.slice(0, -Math.abs(amount)); | ||
}; | ||
Strings.split = function(string, delimiter) { | ||
var array, result, word, _i, _len; | ||
string = Strings.oneSpaceAndTrim(string); | ||
result = []; | ||
if (string.length < 1) { | ||
return result; | ||
} | ||
delimiter = _.forceString(delimiter, ' '); | ||
array = string.split(delimiter[0] || ''); | ||
for (_i = 0, _len = array.length; _i < _len; _i++) { | ||
word = array[_i]; | ||
if (word.match(/^\s$/)) { | ||
continue; | ||
return true; | ||
}); | ||
} | ||
} else if (selection === 0) { | ||
this.xs(function (word) { | ||
return Strings.shuffle(word); | ||
}); | ||
} else { | ||
for (j = 0, len1 = arguments.length; j < len1; j++) { | ||
arg = arguments[j]; | ||
Words_.applyToValidIndex(arg, this.count, function (index) { | ||
return _this3.words[index] = Strings.shuffle(_this3.words[index]); | ||
}); | ||
} | ||
} | ||
} else { | ||
this.words = _.shuffleArray(this.words); | ||
} | ||
result.push(Strings.trim(word)); | ||
} | ||
return result; | ||
}; | ||
Strings.reverse = function(string) { | ||
var ch, length, reversed, _i; | ||
if (string == null) { | ||
string = ''; | ||
return this; | ||
} | ||
string = _.forceString(string); | ||
if ((length = string.length - 1) < 1) { | ||
return string; | ||
}, { | ||
key: "clear", | ||
value: function clear() { | ||
this.words = []; | ||
return this; | ||
} | ||
reversed = ''; | ||
for (ch = _i = length; length <= 0 ? _i <= 0 : _i >= 0; ch = length <= 0 ? ++_i : --_i) { | ||
reversed += string[ch]; | ||
} | ||
return reversed; | ||
}; | ||
}, { | ||
key: "remove", | ||
value: function remove() { | ||
var arg, args, i, index, j, len, len1; | ||
Strings.upper = function() { | ||
var args, string; | ||
string = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
return Strings_.changeCase.apply(Strings_, [string, 'toUpperCase'].concat(__slice.call(args))); | ||
}; | ||
Strings.lower = function() { | ||
var args, string; | ||
string = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
return Strings_.changeCase.apply(Strings_, [string, 'toLowerCase'].concat(__slice.call(args))); | ||
}; | ||
Strings.insert = function() { | ||
var index, insertion, posCount, positions, string, _i; | ||
string = arguments[0], insertion = arguments[1], positions = 3 <= arguments.length ? __slice.call(arguments, 2) : []; | ||
if (('' === (string = _.forceString(string))) || ('' === (insertion = _.forceString(insertion)))) { | ||
return string; | ||
} | ||
positions = _.sortNoDupAndReverse(positions, string.length); | ||
posCount = mapStringToNumber(positions) - 1; | ||
if (0 > posCount) { | ||
return string; | ||
} | ||
for (index = _i = 0; 0 <= posCount ? _i <= posCount : _i >= posCount; index = 0 <= posCount ? ++_i : --_i) { | ||
index = positions[index]; | ||
if (index > string.length) { | ||
string = string + insertion; | ||
continue; | ||
if (arguments.length < 1) { | ||
return this; | ||
} | ||
string = string.substr(0, index) + insertion + string.substr(index); | ||
} | ||
return string; | ||
}; | ||
Strings.removeRange = function(string, offset, amount) { | ||
var endpoint; | ||
string = _.forceString(string); | ||
if ((string === '') || (false === (offset = _.positiveIndex(offset, string.length))) || (0 > (amount = _.forceNumber(amount, 1)))) { | ||
return string; | ||
} | ||
endpoint = offset + amount; | ||
return Strings.xs(string, function(char, index) { | ||
if ((index < offset) || (index >= endpoint)) { | ||
return true; | ||
} | ||
}); | ||
}; | ||
args = []; | ||
Strings.removePos = function() { | ||
var pos, positions, string; | ||
string = arguments[0], positions = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
if ('' === (string = _.forceString(string))) { | ||
return ''; | ||
} | ||
pos = positions.map(function(value, index) { | ||
return _.positiveIndex(value, string.length); | ||
}); | ||
return Strings.xs(string, function(char, index) { | ||
if (!(__indexOf.call(pos, index) >= 0)) { | ||
return true; | ||
} | ||
}); | ||
}; | ||
for (i = 0, len = arguments.length; i < len; i++) { | ||
arg = arguments[i]; | ||
Strings.remove = function() { | ||
var remove, string, toRemove, _i, _len; | ||
string = arguments[0], toRemove = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
if (string == null) { | ||
string = ''; | ||
} | ||
if (('' === (string = _.forceString(string))) || (toRemove.length < 1)) { | ||
return string; | ||
} | ||
for (_i = 0, _len = toRemove.length; _i < _len; _i++) { | ||
remove = toRemove[_i]; | ||
string = Strings.replace(string, remove); | ||
} | ||
return string; | ||
}; | ||
Strings.startsWith = function(string, start) { | ||
if (('' === (string = _.forceString(string))) || ('' === (start = _.forceString(start)))) { | ||
return false; | ||
} | ||
start = new RegExp('^' + Strings.regEscape(start)); | ||
return start.test(string); | ||
}; | ||
Strings.endsWith = function(string, ending) { | ||
if (('' === (string = _.forceString(string))) || ('' === (ending = _.forceString(ending)))) { | ||
return false; | ||
} | ||
ending = new RegExp(Strings.regEscape(ending) + '$'); | ||
return ending.test(string); | ||
}; | ||
Strings.wrap = function(prepend, append) { | ||
var wrapper; | ||
if (prepend == null) { | ||
prepend = ''; | ||
} | ||
if (append == null) { | ||
append = ''; | ||
} | ||
wrapper = function(string) { | ||
return Strings.create(prepend, string, append); | ||
}; | ||
wrapper.wrap = function(outerPrepend, outerAppend) { | ||
if (outerPrepend == null) { | ||
outerPrepend = ''; | ||
if (_.isString(arg)) { | ||
args.unshift(arg); | ||
} else if (_.isNumber(arg)) { | ||
args.push(Words.positiveIndex(arg, this.count)); | ||
} | ||
} | ||
if (outerAppend == null) { | ||
outerAppend = ''; | ||
} | ||
prepend = _.forceString(outerPrepend) + prepend; | ||
return append += _.forceString(outerAppend); | ||
}; | ||
return wrapper; | ||
}; | ||
function Strings() { | ||
this.set.apply(this, arguments); | ||
this.wrapMethod = null; | ||
this.crop = this.slice; | ||
} | ||
args = _.noDupAndReverse(_.insertSort(args)); | ||
Strings.prototype.set = function() { | ||
this.string = Strings.create.apply(this, arguments); | ||
return this; | ||
}; | ||
for (index = j = 0, len1 = args.length; j < len1; index = ++j) { | ||
arg = args[index]; | ||
Strings.prototype.sort = function() { | ||
this.string = Strings.sort(this.string); | ||
return this; | ||
}; | ||
Strings.prototype.random = function(amount, charSet) { | ||
this.string = Strings.random(amount, charSet); | ||
return this; | ||
}; | ||
Strings.prototype.xs = function(callback) { | ||
this.string = Strings.xs(this.string, callback); | ||
return this; | ||
}; | ||
Strings.prototype.times = function(times) { | ||
if (times == null) { | ||
times = 1; | ||
} | ||
this.string = Strings.times(this.string, times); | ||
return this; | ||
}; | ||
Strings.prototype.get = function() { | ||
var position, string, _i, _len; | ||
if (arguments.length > 0) { | ||
string = ''; | ||
for (_i = 0, _len = arguments.length; _i < _len; _i++) { | ||
position = arguments[_i]; | ||
position = _.positiveIndex(position, this.length); | ||
if (position !== false) { | ||
string += this.string[position]; | ||
if (_.isNumber(arg)) { | ||
this.xs(function (word, index) { | ||
if (index !== arg) { | ||
return true; | ||
} | ||
}); | ||
} else if (_.isString(arg)) { | ||
this.xs(function (word) { | ||
if (word !== arg) { | ||
return true; | ||
} | ||
}); | ||
} | ||
} | ||
return string; | ||
} | ||
return this.string; | ||
}; | ||
Strings.prototype.copy = function(offset, amount) { | ||
return Strings.copy(this.string, offset, amount); | ||
}; | ||
Strings.prototype.empty = function() { | ||
return Strings.empty(this.string); | ||
}; | ||
Strings.prototype.isAlpha = function() { | ||
return Strings.isAlpha(this.string); | ||
}; | ||
Strings.prototype.isNumeric = function() { | ||
return Strings.isNumeric(this.string); | ||
}; | ||
Strings.prototype.isAlphaNumeric = function() { | ||
return Strings.isAlphaNumeric(this.string); | ||
}; | ||
Strings.prototype.isSpecial = function() { | ||
return Strings.isSpecial(this.string); | ||
}; | ||
Strings.prototype.isSpace = function() { | ||
return Strings.isSpace(this.string); | ||
}; | ||
Strings.prototype.isUpper = function() { | ||
return Strings.isUpper(this.string); | ||
}; | ||
Strings.prototype.hasUpper = function() { | ||
return Strings.hasUpper(this.string); | ||
}; | ||
Strings.prototype.isLower = function() { | ||
return Strings.isLower(this.string); | ||
}; | ||
Strings.prototype.push = function() { | ||
this.string = this.string + Strings.create.apply(this, arguments); | ||
return this; | ||
}; | ||
Strings.prototype.prepend = function() { | ||
this.string = Strings.create.apply(this, arguments) + this.string; | ||
return this; | ||
}; | ||
Strings.prototype.pop = function(amount) { | ||
this.string = Strings.pop(this.string, amount); | ||
return this; | ||
}; | ||
Strings.prototype.insert = function() { | ||
var positions, string; | ||
string = arguments[0], positions = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
this.string = Strings.insert.apply(Strings, [this.string, string].concat(__slice.call(positions))); | ||
return this; | ||
}; | ||
Strings.prototype.trim = function() { | ||
this.string = Strings.trim(this.string); | ||
return this; | ||
}; | ||
Strings.prototype.trimLeft = function() { | ||
this.string = Strings.trimLeft(this.string); | ||
return this; | ||
}; | ||
Strings.prototype.trimRight = function() { | ||
this.string = Strings.trimRight(this.string); | ||
return this; | ||
}; | ||
Strings.prototype.oneSpace = function() { | ||
this.string = Strings.oneSpace(this.string); | ||
return this; | ||
}; | ||
Strings.prototype.oneSpaceAndTrim = function() { | ||
this.string = Strings.oneSpaceAndTrim(this.string); | ||
return this; | ||
}; | ||
Strings.prototype.find = function(string) { | ||
return Strings.find(this.string, string); | ||
}; | ||
Strings.prototype.count = function(string) { | ||
return Strings.count(this.string, string); | ||
}; | ||
Strings.prototype.contains = function(string) { | ||
return Strings.contains(this.string, string); | ||
}; | ||
Strings.prototype.between = function(before, after) { | ||
return Strings.between(this.string, before, after); | ||
}; | ||
Strings.prototype.slice = function(start, size) { | ||
this.string = Strings.slice(this.string, start, size); | ||
return this; | ||
}; | ||
Strings.prototype.truncate = function(size, suffix) { | ||
this.string = Strings.truncate(this.string, size, suffix); | ||
return this; | ||
}; | ||
Strings.prototype.remove = function() { | ||
var strings; | ||
strings = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
this.string = Strings.remove.apply(Strings, [this.string].concat(__slice.call(strings))); | ||
return this; | ||
}; | ||
Strings.prototype.removeRange = function(offset, amount) { | ||
this.string = Strings.removeRange(this.string, offset, amount); | ||
return this; | ||
}; | ||
Strings.prototype.removePos = function() { | ||
var positions; | ||
positions = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
this.string = Strings.removePos.apply(Strings, [this.string].concat(__slice.call(positions))); | ||
return this; | ||
}; | ||
Strings.prototype.replace = function(subString, replacement, flags) { | ||
this.string = Strings.replace(this.string, subString, replacement, flags); | ||
return this; | ||
}; | ||
Strings.prototype.reverse = function() { | ||
this.string = Strings.reverse(this.string); | ||
return this; | ||
}; | ||
Strings.prototype.upper = function() { | ||
var args; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
this.string = Strings.upper.apply(Strings, [this.string].concat(__slice.call(args))); | ||
return this; | ||
}; | ||
Strings.prototype.lower = function() { | ||
var args; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
this.string = Strings.lower.apply(Strings, [this.string].concat(__slice.call(args))); | ||
return this; | ||
}; | ||
Strings.prototype.shuffle = function() { | ||
this.string = Strings.shuffle(this.string); | ||
return this; | ||
}; | ||
Strings.prototype.toCamel = function(char) { | ||
this.string = Strings.toCamel(this.string, char); | ||
return this; | ||
}; | ||
Strings.prototype.unCamel = function(insertion) { | ||
this.string = Strings.unCamel(this.string, insertion); | ||
return this; | ||
}; | ||
Strings.prototype.startsWith = function(start) { | ||
return Strings.startsWith(this.string, start); | ||
}; | ||
Strings.prototype.endsWith = function(ending) { | ||
return Strings.endsWith(this.string, ending); | ||
}; | ||
Strings.prototype.setWrap = function(prepend, append) { | ||
if (_.isNull(this.wrapMethod)) { | ||
this.wrapMethod = Strings.wrap(prepend, append); | ||
} else { | ||
this.wrapMethod.wrap(prepend, append); | ||
return this; | ||
} | ||
return this; | ||
}; | ||
}, { | ||
key: "pop", | ||
value: function pop(amount) { | ||
var i, n, pop, popped, ref; | ||
amount = Math.abs(_.forceNumber(amount, 1)); | ||
popped = ''; | ||
Strings.prototype.removeWrap = function() { | ||
this.wrapMethod = null; | ||
return this; | ||
}; | ||
for (n = i = 1, ref = amount; 1 <= ref ? i <= ref : i >= ref; n = 1 <= ref ? ++i : --i) { | ||
pop = this.words.pop(); | ||
Strings.prototype.applyWrap = function(prepend, append) { | ||
this.string = this.setWrap(prepend, append).wrap; | ||
this.removeWrap(); | ||
return this; | ||
}; | ||
if (pop !== void 0) { | ||
popped = pop + ' ' + popped; | ||
} | ||
} | ||
return Strings; | ||
})(Chars); | ||
Object.defineProperty(Strings.prototype, '$', { | ||
get: function() { | ||
return this.get(); | ||
} | ||
}); | ||
Object.defineProperty(Strings.prototype, 'length', { | ||
get: function() { | ||
return this.string.length; | ||
} | ||
}); | ||
Object.defineProperty(Strings.prototype, 'wrap', { | ||
get: function() { | ||
if (!_.isNull(this.wrapMethod)) { | ||
return this.wrapMethod(this.string); | ||
return popped.trim(); | ||
} | ||
return this.string; | ||
} | ||
}); | ||
}, { | ||
key: "push", | ||
value: function push() { | ||
var arg, i, len; | ||
Strings.Types = Types; | ||
for (i = 0, len = arguments.length; i < len; i++) { | ||
arg = arguments[i]; | ||
Strings.Chars = Chars; | ||
Strings.crop = Strings.slice; | ||
Strings.prototype.crop = Strings.prototype.slice; | ||
Strings.prototype.append = Strings.prototype.push; | ||
Words_ = (function() { | ||
function Words_() {} | ||
Words_.delimiter = ' '; | ||
Words_.stringsFromArray = function(array) { | ||
var strings, value, _i, _len, _ref; | ||
strings = []; | ||
_ref = _.forceArray(array); | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
value = _ref[_i]; | ||
if (_.isString(value)) { | ||
strings.push(value); | ||
if ('' !== (arg = _.forceString(arg))) { | ||
this.words.push(Strings.trim(arg)); | ||
} | ||
} | ||
} | ||
return strings; | ||
}; | ||
Words_.numbersFromArray = function(array) { | ||
var numbers, value, _i, _len, _ref; | ||
numbers = []; | ||
_ref = _.forceArray(array); | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
value = _ref[_i]; | ||
if (_.isNumber(value)) { | ||
numbers.push(value + 0); | ||
} | ||
return this; | ||
} | ||
return numbers; | ||
}; | ||
}, { | ||
key: "shift", | ||
value: function shift(amount) { | ||
var i, n, ref; | ||
amount = _.forceNumber(amount, 1); | ||
Words_.changeCase = function(method, args) { | ||
var index, indices, pos, words, _i, _j, _k, _len, _len1, _ref, _results, _results1, _results2; | ||
words = Words_.stringsFromArray(args); | ||
indices = Words_.numbersFromArray(args); | ||
if (words.length > 0) { | ||
this.set(Strings[method].apply(Strings, [this.string].concat(__slice.call(words)))); | ||
} | ||
if (indices[0] === 0) { | ||
_results = []; | ||
for (_i = 0, _len = indices.length; _i < _len; _i++) { | ||
pos = indices[_i]; | ||
_results.push((function() { | ||
var _j, _ref, _results1; | ||
_results1 = []; | ||
for (index = _j = 0, _ref = this.count - 1; 0 <= _ref ? _j <= _ref : _j >= _ref; index = 0 <= _ref ? ++_j : --_j) { | ||
_results1.push(this.words[index] = Strings[method](this.words[index], pos)); | ||
} | ||
return _results1; | ||
}).call(this)); | ||
for (n = i = 1, ref = amount; 1 <= ref ? i <= ref : i >= ref; n = 1 <= ref ? ++i : --i) { | ||
this.words.shift(); | ||
} | ||
return _results; | ||
} else { | ||
if (args.length < 1) { | ||
indices = (function() { | ||
_results1 = []; | ||
for (var _j = 0, _ref = this.count; 0 <= _ref ? _j <= _ref : _j >= _ref; 0 <= _ref ? _j++ : _j--){ _results1.push(_j); } | ||
return _results1; | ||
}).apply(this); | ||
} | ||
_results2 = []; | ||
for (_k = 0, _len1 = indices.length; _k < _len1; _k++) { | ||
index = indices[_k]; | ||
index = _.positiveIndex(index, this.count); | ||
_results2.push(this.words[index] = Strings[method](this.words[index])); | ||
} | ||
return _results2; | ||
} | ||
}; | ||
Words_.applyToValidIndex = function(orgIndex, limit, callback) { | ||
var index; | ||
if (false !== (index = _.positiveIndex(orgIndex, limit))) { | ||
return callback(index); | ||
return this; | ||
} | ||
}; | ||
}, { | ||
key: "prepend", | ||
value: function prepend() { | ||
var arg, i, len, pos; | ||
pos = 0; | ||
return Words_; | ||
for (i = 0, len = arguments.length; i < len; i++) { | ||
arg = arguments[i]; | ||
})(); | ||
if ('' !== (arg = _.forceString(arg))) { | ||
this.words.splice(pos, 0, Strings.trim(arg)); | ||
pos++; | ||
} | ||
} | ||
Words = (function(_super) { | ||
__extends(Words, _super); | ||
function Words() { | ||
this.set.apply(this, arguments); | ||
} | ||
Words.prototype.set = function() { | ||
var arg, args, str, _i, _j, _len, _len1, _ref; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
this.words = []; | ||
args = _.intoArray.apply(this, args); | ||
if (args.length < 1) { | ||
return this; | ||
} | ||
for (_i = 0, _len = args.length; _i < _len; _i++) { | ||
arg = args[_i]; | ||
_ref = Strings.split(Strings.create(arg), Words_.delimiter); | ||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { | ||
str = _ref[_j]; | ||
this.words.push(str); | ||
} | ||
} | ||
return this; | ||
}; | ||
}, { | ||
key: "insert", | ||
value: function insert(index) { | ||
var i, len, pos, word; | ||
index = _.positiveIndex(index, this.count); | ||
pos = 0; | ||
Words.prototype.get = function() { | ||
var index, string, _i, _len; | ||
if (arguments.length < 1) { | ||
return this.words.join(Words_.delimiter); | ||
} | ||
string = ''; | ||
for (_i = 0, _len = arguments.length; _i < _len; _i++) { | ||
index = arguments[_i]; | ||
index = _.positiveIndex(index, this.count); | ||
if (index !== false) { | ||
string += this.words[index] + Words_.delimiter; | ||
for (var _len3 = arguments.length, words = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
words[_key3 - 1] = arguments[_key3]; | ||
} | ||
} | ||
return Strings.trim(string); | ||
}; | ||
Words.prototype.xs = function(callback) { | ||
var index, response, result, word, _i, _len, _ref; | ||
if (callback == null) { | ||
callback = function() { | ||
return true; | ||
}; | ||
} | ||
if (_.notFunction(callback) || this.count < 1) { | ||
return this; | ||
} | ||
result = []; | ||
_ref = this.words; | ||
for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) { | ||
word = _ref[index]; | ||
if (response = callback(word, index)) { | ||
if (response === true) { | ||
result.push(word); | ||
} else if (_.isStringOrNumber(response)) { | ||
result.push(response + ''); | ||
for (i = 0, len = words.length; i < len; i++) { | ||
word = words[i]; | ||
if ('' !== (word = _.forceString(word))) { | ||
this.words.splice(index + pos, 0, Strings.trim(word)); | ||
pos++; | ||
} | ||
} | ||
} | ||
this.words = result; | ||
return this; | ||
}; | ||
Words.prototype.find = function(string) { | ||
var indices; | ||
indices = []; | ||
if ('' !== (string = _.forceString(string))) { | ||
this.xs(function(word, index) { | ||
if (word === string) { | ||
indices.push(index + 1); | ||
} | ||
return true; | ||
}); | ||
return this; | ||
} | ||
return indices; | ||
}; | ||
}, { | ||
key: "replace", | ||
value: function replace(selection) { | ||
var _this4 = this; | ||
Words.prototype.upper = function() { | ||
Words_.changeCase.call(this, 'upper', Array.prototype.slice.call(arguments)); | ||
return this; | ||
}; | ||
var replacement = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; | ||
Words.prototype.lower = function() { | ||
Words_.changeCase.call(this, 'lower', Array.prototype.slice.call(arguments)); | ||
return this; | ||
}; | ||
Words.prototype.reverse = function() { | ||
var arg, _i, _len; | ||
if ((arguments != null ? arguments[0] : void 0) === 0) { | ||
this.xs(function(word) { | ||
return Strings.reverse(word); | ||
}); | ||
} else if (arguments.length > 0) { | ||
for (_i = 0, _len = arguments.length; _i < _len; _i++) { | ||
arg = arguments[_i]; | ||
Words_.applyToValidIndex(arg, this.count, (function(_this) { | ||
return function(index) { | ||
return _this.words[index] = Strings.reverse(_this.words[index]); | ||
}; | ||
})(this)); | ||
if ('' === (replacement = Strings.trim(replacement))) { | ||
return this; | ||
} | ||
} else { | ||
this.xs((function(_this) { | ||
return function(word, index) { | ||
return _this.get(_this.count - index); | ||
}; | ||
})(this)); | ||
} | ||
return this; | ||
}; | ||
Words.prototype.shuffle = function(selection) { | ||
var arg, _i, _j, _len, _len1; | ||
if (selection != null) { | ||
if (_.isString(selection)) { | ||
for (_i = 0, _len = arguments.length; _i < _len; _i++) { | ||
arg = arguments[_i]; | ||
this.xs((function(_this) { | ||
return function(word, index) { | ||
if (word === arg) { | ||
return Strings.shuffle(word); | ||
} | ||
return true; | ||
}; | ||
})(this)); | ||
} | ||
} else if (selection === 0) { | ||
this.xs(function(word) { | ||
return Strings.shuffle(word); | ||
if (_.isNumber(selection)) { | ||
Words_.applyToValidIndex(selection, this.count, function (index) { | ||
return _this4.words.splice(index, 1, replacement); | ||
}); | ||
} else { | ||
for (_j = 0, _len1 = arguments.length; _j < _len1; _j++) { | ||
arg = arguments[_j]; | ||
Words_.applyToValidIndex(arg, this.count, (function(_this) { | ||
return function(index) { | ||
return _this.words[index] = Strings.shuffle(_this.words[index]); | ||
}; | ||
})(this)); | ||
} | ||
} | ||
} else { | ||
this.words = _.shuffleArray(this.words); | ||
} | ||
return this; | ||
}; | ||
this.xs(function (word) { | ||
if (word === selection) { | ||
return replacement; | ||
} | ||
Words.prototype.clear = function() { | ||
this.words = []; | ||
return this; | ||
}; | ||
Words.prototype.remove = function() { | ||
var arg, args, index, _i, _j, _len, _len1; | ||
if (arguments.length < 1) { | ||
return this; | ||
} | ||
args = []; | ||
for (_i = 0, _len = arguments.length; _i < _len; _i++) { | ||
arg = arguments[_i]; | ||
if (_.isString(arg)) { | ||
args.unshift(arg); | ||
} else if (_.isNumber(arg)) { | ||
args.push(Words.positiveIndex(arg, this.count)); | ||
} | ||
} | ||
args = _.noDupAndReverse(_.insertSort(args)); | ||
for (index = _j = 0, _len1 = args.length; _j < _len1; index = ++_j) { | ||
arg = args[index]; | ||
if (_.isNumber(arg)) { | ||
this.xs((function(_this) { | ||
return function(word, index) { | ||
if (index !== arg) { | ||
return true; | ||
} | ||
}; | ||
})(this)); | ||
} else if (_.isString(arg)) { | ||
this.xs(function(word) { | ||
if (word !== arg) { | ||
return true; | ||
} | ||
return true; | ||
}); | ||
} | ||
} | ||
return this; | ||
}; | ||
Words.prototype.pop = function(amount) { | ||
var n, pop, popped, _i; | ||
amount = Math.abs(_.forceNumber(amount, 1)); | ||
popped = ''; | ||
for (n = _i = 1; 1 <= amount ? _i <= amount : _i >= amount; n = 1 <= amount ? ++_i : --_i) { | ||
pop = this.words.pop(); | ||
if (pop !== void 0) { | ||
popped = pop + ' ' + popped; | ||
} | ||
return this; | ||
} | ||
return popped.trim(); | ||
}; | ||
}, { | ||
key: "sort", | ||
value: function sort() { | ||
_.insertSort(this.words); | ||
Words.prototype.push = function() { | ||
var arg, _i, _len; | ||
for (_i = 0, _len = arguments.length; _i < _len; _i++) { | ||
arg = arguments[_i]; | ||
if ('' !== (arg = _.forceString(arg))) { | ||
this.words.push(Strings.trim(arg)); | ||
} | ||
} | ||
return this; | ||
}; | ||
return this; | ||
} // refactor these two later.. | ||
Words.prototype.shift = function(amount) { | ||
var n, _i; | ||
amount = _.forceNumber(amount, 1); | ||
for (n = _i = 1; 1 <= amount ? _i <= amount : _i >= amount; n = 1 <= amount ? ++_i : --_i) { | ||
this.words.shift(); | ||
} | ||
return this; | ||
}; | ||
}, { | ||
key: "startsWith", | ||
value: function startsWith(start) { | ||
var _this5 = this; | ||
Words.prototype.prepend = function() { | ||
var arg, pos, _i, _len; | ||
pos = 0; | ||
for (_i = 0, _len = arguments.length; _i < _len; _i++) { | ||
arg = arguments[_i]; | ||
if ('' !== (arg = _.forceString(arg))) { | ||
this.words.splice(pos, 0, Strings.trim(arg)); | ||
pos++; | ||
} | ||
} | ||
return this; | ||
}; | ||
var result; | ||
Words.prototype.insert = function() { | ||
var index, pos, word, words, _i, _len; | ||
index = arguments[0], words = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
index = _.positiveIndex(index, this.count); | ||
pos = 0; | ||
for (_i = 0, _len = words.length; _i < _len; _i++) { | ||
word = words[_i]; | ||
if ('' !== (word = _.forceString(word))) { | ||
this.words.splice(index + pos, 0, Strings.trim(word)); | ||
pos++; | ||
if ('' === (start = _.forceString(start))) { | ||
return false; | ||
} | ||
} | ||
return this; | ||
}; | ||
Words.prototype.replace = function(selection, replacement) { | ||
if (replacement == null) { | ||
replacement = ''; | ||
} | ||
if ('' === (replacement = Strings.trim(replacement))) { | ||
return this; | ||
} | ||
if (_.isNumber(selection)) { | ||
Words_.applyToValidIndex(selection, this.count, (function(_this) { | ||
return function(index) { | ||
return _this.words.splice(index, 1, replacement); | ||
}; | ||
})(this)); | ||
} else { | ||
this.xs(function(word) { | ||
if (word === selection) { | ||
return replacement; | ||
result = true; | ||
start = new Words(start); | ||
start.xs(function (word, index) { | ||
if (word !== _this5.words[index]) { | ||
return result = false; | ||
} | ||
return true; | ||
}); | ||
return result; | ||
} | ||
return this; | ||
}; | ||
}, { | ||
key: "endsWith", | ||
value: function endsWith(end) { | ||
var count, i, index, ref, result; | ||
Words.prototype.sort = function() { | ||
_.insertSort(this.words); | ||
return this; | ||
}; | ||
if ('' === (end = _.forceString(end))) { | ||
return false; | ||
} | ||
Words.prototype.startsWith = function(start) { | ||
var result; | ||
if ('' === (start = _.forceString(start))) { | ||
return false; | ||
} | ||
result = true; | ||
start = new Words(start); | ||
start.xs((function(_this) { | ||
return function(word, index) { | ||
if (word !== _this.words[index]) { | ||
return result = false; | ||
result = true; | ||
count = 1; | ||
end = new Words(end); | ||
for (index = i = ref = end.count; ref <= 1 ? i <= 1 : i >= 1; index = ref <= 1 ? ++i : --i) { | ||
if (end.get(index) !== this.words[this.count - count++]) { | ||
result = false; | ||
} | ||
}; | ||
})(this)); | ||
return result; | ||
}; | ||
} | ||
Words.prototype.endsWith = function(end) { | ||
var count, index, result, _i, _ref; | ||
if ('' === (end = _.forceString(end))) { | ||
return false; | ||
return result; | ||
} | ||
result = true; | ||
count = 1; | ||
end = new Words(end); | ||
for (index = _i = _ref = end.count; _ref <= 1 ? _i <= 1 : _i >= 1; index = _ref <= 1 ? ++_i : --_i) { | ||
if (end.get(index) !== this.words[this.count - count++]) { | ||
result = false; | ||
} | ||
} | ||
return result; | ||
}; | ||
}]); | ||
return Words; | ||
}(Strings); | ||
})(Strings); | ||
Object.defineProperty(Words.prototype, '$', { | ||
get: function() { | ||
get: function get() { | ||
return this.get(); | ||
} | ||
}); | ||
Object.defineProperty(Words.prototype, 'string', { | ||
get: function() { | ||
get: function get() { | ||
return this.get(); | ||
} | ||
}); | ||
Object.defineProperty(Words.prototype, 'count', { | ||
get: function() { | ||
get: function get() { | ||
return this.words.length; | ||
} | ||
}); | ||
Words.prototype.unshift = Words.prototype.prepend; | ||
Words.flexArgs = Types.intoArray; | ||
Words.flexArgs = types.intoArray; | ||
Words.Strings = Strings; | ||
Words.Types = Types; | ||
Words.types = types; | ||
Words.Chars = Chars; | ||
if ((typeof define !== "undefined" && define !== null) && ('function' === typeof define) && define.amd) { | ||
define('words', [], function() { | ||
if (typeof define !== "undefined" && define !== null && 'function' === typeof define && define.amd) { | ||
define('words', [], function () { | ||
return Words; | ||
@@ -1559,3 +615,3 @@ }); | ||
window.Words = Words; | ||
window.Types = Types; | ||
window.types = types; | ||
window.Strings = Strings; | ||
@@ -1565,3 +621,2 @@ } else if (typeof module !== "undefined" && module !== null) { | ||
} | ||
}).call(this); | ||
}).call(void 0); |
@@ -1,1 +0,1 @@ | ||
(function(){"use strict";var t,r,n,e,i,o,u,s,c,f,p,a,g,h,l,m=[].slice,y={}.hasOwnProperty,d=function(t,r){function n(){this.constructor=t}for(var e in r)y.call(r,e)&&(t[e]=r[e]);return n.prototype=r.prototype,t.prototype=new n,t.__super__=r.prototype,t},v=[].indexOf||function(t){for(var r=0,n=this.length;n>r;r++)if(r in this&&this[r]===t)return r;return-1};p=function(t,r){return r instanceof t},h=function(t,r){return null==r&&(r="object"),typeof t===r},r={Boolean:!1,String:"",Object:{},Array:[],Function:function(){},Number:function(){var t;return t=new Number,t["void"]=!0,t}()},i={Undefined:function(t){return void 0===t},Null:function(t){return null===t},Function:function(t){return h(t,"function")},Boolean:function(t){return h(t,"boolean")},String:function(t){return h(t,"string")},Array:function(t){return h(t)&&p(Array,t)},RegExp:function(t){return h(t)&&p(RegExp,t)},Date:function(t){return h(t)&&p(Date,t)},Number:function(t){return h(t,"number")&&t===t||h(t)&&p(Number,t)},Object:function(t){return!(!h(t)||null===t||p(Boolean,t)||p(Number,t)||p(Array,t)||p(RegExp,t)||p(Date,t))},NaN:function(t){return h(t,"number")&&t!==t},Defined:function(t){return void 0!==t}},i.StringOrNumber=function(t){return i.String(t)||i.Number(t)},o=l={parseIntBase:10},f=function(t){var n;return n=function(r){switch(t){case"Number":if(l.isNumber(r=parseInt(r,l.parseIntBase))&&!r["void"])return r;break;case"String":if(l.isStringOrNumber(r))return r+"";break;default:if(o["is"+t](r))return r}},function(e,i){return null!=e&&void 0!==(e=n(e))?e:null!=i&&void 0!==(i=n(i))?i:r[t]}},g=function(t,r,n){var e,o,u;if(null==n&&(n=[]),n.length<1)return t===i.Undefined;for(o=0,u=n.length;u>o;o++)if(e=n[o],t(e)===r)return r;return!r},c=!0,function(){var t,n,e;e=[];for(t in i)n=i[t],e.push(function(t,n){return o["is"+t]=n,o["not"+t]=function(t){return!n(t)},o["has"+t]=function(){return g(n,c,arguments)},o["all"+t]=function(){return g(n,!c,arguments)},t in r?o["force"+t]=f(t):void 0}(t,n));return e}(),o.intoArray=function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],t.length<2&&(l.isString(t[0])?t=t.join("").replace(/^\s+|\s+$/g,"").replace(/\s+/g," ").split(" "):l.isArray(t[0])&&(t=t[0])),t},o["typeof"]=function(t){var r,n;for(r in i)if(n=i[r],n(t)===!0)return r.toLowerCase()},a=function(t){var r,n,e,i,o;if(l.notArray(t))return 0;for(r=i=0,o=t.length;o>i;r=++i){if(e=t[r],n=l.forceNumber(e),n["void"])return r;t[r]=n}return t.length},l=function(t){function r(){return r.__super__.constructor.apply(this,arguments)}return d(r,t),r.inRange=function(t,n){return r.isNaN(t=parseInt(t,10))||a(n)<2?!1:t>=n[0]&&t<=n[1]},r.limitNumber=function(t,n){return t=r.forceNumber(t,0),a(n)<2?t:t<n[0]?n[0]:t>n[1]?n[1]:t},r.randomNumber=function(t,r){return a([t,r])<2?0:t>r?t:(r=r-t+1,Math.floor(Math.random()*r+t))},r.shuffleArray=function(t){var n,e,i,o,u;if(r.notArray(t)||t.length<1)return[];for(e=t.length-1,n=u=e;0>=e?0>=u:u>=0;n=0>=e?++u:--u)i=r.randomNumber(0,n),o=t[n],t[n]=t[i],t[i]=o;return t},r.positiveIndex=function(t,n){return 0===(t=r.forceNumber(t,0))?!1:(n=Math.abs(r.forceNumber(n)),Math.abs(t)<=n?t>0?t-1:n+t:!1)},r.insertSort=function(t){var r,n,e,i,o;for(e=t.length-1,n=o=1;e>=1?e>=o:o>=e;n=e>=1?++o:--o){for(r=t[n],i=n-1;i>=0&&t[i]>r;)t[i+1]=t[i],--i;t[+i+1]=r}return t},r.noDupAndReverse=function(t){var r,n,e,i;for(n=t.length-1,e=[],r=i=n;0>=n?0>=i:i>=0;r=0>=n?++i:--i)e[e.length-1]!==t[r]&&e.push(t[r]);return e},r.sortNoDupAndReverse=function(t,n){var e,i,o,u,s;for(i=[],e=u=0,s=t.length;s>u;e=++u)o=t[e],o=r.forceNumber(o),o["void"]||(n>=o&&(o=r.positiveIndex(o,n)),i.push(r.forceNumber(o,0)));return r.noDupAndReverse(r.insertSort(i))},r}(o),t=function(t){function r(){return r.__super__.constructor.apply(this,arguments)}return d(r,t),r.ASCII_RANGE_UPPERCASE=[65,90],r.ASCII_RANGE_LOWERCASE=[97,122],r.ASCII_RANGE_NUMBERS=[48,57],r.ASCII_RANGE_SPECIAL_1=[32,47],r.ASCII_RANGE_SPECIAL_2=[58,64],r.ASCII_RANGE_SPECIAL_3=[91,96],r.ASCII_RANGE_SPECIAL_4=[123,126],r.ASCII_RANGE_ALL=[32,126],r.REGEXP_SPECIAL_CHARS=["?","\\","[","]","(",")","*","+",".","/","|","^","$","<",">","-","&"],r.ascii=function(t){return String.fromCharCode(l.forceNumber(t))},r.ordinal=function(t){return l.forceNumber(l.forceString(t).charCodeAt(),0)},r.random=function(t){var n,e;return t=l.forceArray(t,r.ASCII_RANGE_ALL),e=l.limitNumber(t[0],t),n=l.limitNumber(t[1],t),r.ascii(l.randomNumber(e,n))},r}(l),e=function(){function t(){}return t.changeCase=function(){var t,r,e,i,o,u,s,c,f;if(o=arguments[0],e=arguments[1],r=3<=arguments.length?m.call(arguments,2):[],null==o&&(o=""),""===(o=l.forceString(o)))return o;if(r.length<1||void 0===r[0])return o[e]();if(l.isNumber(r[0]))for(u=0,c=r.length;c>u;u++)t=r[u],i=l.positiveIndex(t,o.length),o=n.xs(o,function(t,r){return r===i?t[e]():t});else if(l.isString(r[0]))for(s=0,f=r.length;f>s;s++)t=r[s],o=n.replace(o,t,t[e](),"gi");return o},t}(),n=function(r){function n(){this.set.apply(this,arguments),this.wrapMethod=null,this.crop=this.slice}return d(n,r),n.create=function(){var t,r,n,e;for(r="",n=0,e=arguments.length;e>n;n++)t=arguments[n],r+=l.forceString(t);return r},n.get=function(){var t,r,n,e,i,o,u;if(o=arguments[0],e=2<=arguments.length?m.call(arguments,1):[],arguments.length<2)return"";for(o=l.forceString(o),r=o.length,i="",t=arguments.length,n=u=1;t>=1?t>=u:u>=t;n=t>=1?++u:--u)n=l.positiveIndex(arguments[n],r),n!==!1&&(i+=o[n]);return i},n.sort=function(t){return t=l.forceString(t).trim().split(""),l.insertSort(t).join("")},n.random=function(r,n){var e,i,o;for(r=l.forceNumber(r,1),i="",e=o=1;r>=1?r>=o:o>=r;e=r>=1?++o:--o)i+=t.random(n);return i},n.times=function(t,r){var n;if(""===(t=l.forceString(t)))return"";for(r=l.forceNumber(r,1),n="";r-->0;)n+=t;return n},n.regEscape=function(r){return""===(r=l.forceString(r))?r:n.xs(r,function(r){return v.call(t.REGEXP_SPECIAL_CHARS,r)>=0?"\\"+r:!0})},n.empty=function(t){return l.notString(t)||t.length>0?!1:!0},n.isAlpha=function(t){return""===(t=l.forceString(t))?!1:/^[a-z]*$/gi.test(t)},n.isNumeric=function(t){return""===(t=l.forceString(t))?!1:/^[0-9]*$/g.test(t)},n.isAlphaNumeric=function(t){return""===(t=l.forceString(t))?!1:/^[0-9|a-z]*$/gi.test(t)},n.isSpecial=function(t){return""===(t=l.forceString(t))?!1:/^[^0-9|a-z]*$/gi.test(t)},n.isSpace=function(t){return/^[ \t]+$/g.test(t)},n.hasUpper=function(t){return/[A-Z]+/g.test(t)},n.isUpper=function(t){return/^[A-Z]+$/g.test(t)},n.isLower=function(t){return/^[a-z]+$/g.test(t)},n.xs=function(t,r){var n,e,i,o,u;if(null==t&&(t=""),t=l.forceString(t),-1===(e=t.length-1))return"";for(r=l.forceFunction(r,function(t){return t}),o="",n=u=0;e>=0?e>=u:u>=e;n=e>=0?++u:--u)(i=r(t[n],n))&&(i===!0?o+=t[n]:l.isStringOrNumber(i)&&(o+=i));return o},n.copy=function(t,r,n){return r=l.forceNumber(r),""===(t=l.forceString(t))||Math.abs(r)>t.length?"":(r>0&&(r-=1),t.substr(r,l.forceNumber(n,t.length)))},n.replace=function(t,r,e,i){var o;return null==t&&(t=""),null==r&&(r=""),null==e&&(e=""),null==i&&(i="g"),!l.isStringOrNumber(t)||"string"!==(o=l["typeof"](r))&&"number"!==o&&"regexp"!==o?l.forceString(t):(l.notRegExp(r)&&(r=n.regEscape(r+""),r=new RegExp(r,i)),(t+"").replace(r,e))},n.trim=function(t){return n.replace(t,/^\s+|\s+$/g)},n.trimLeft=function(t){return n.replace(t,/^\s+/g)},n.trimRight=function(t){return n.replace(t,/\s+$/g)},n.oneSpace=function(t){return n.replace(t,/\s+/g," ")},n.oneSpaceAndTrim=function(t){return n.oneSpace(n.trim(t))},n.toCamel=function(t,r){var e;return t=l.forceString(t),r=l.forceString(r,"-"),e=new RegExp(n.regEscape(r)+"([a-z])","ig"),n.replace(t,e,function(t,r){return r.toUpperCase()})},n.unCamel=function(t,r){return t=l.forceString(t),r=l.forceString(r,"-"),n.replace(t,/([A-Z])/g,r+"$1").toLowerCase()},n.shuffle=function(t){return t=l.forceString(t),l.shuffleArray((t+"").split("")).join("")},n.find=function(t,r,e){var i,o;if(i=[],""===(t=l.forceString(t)))return i;if(e=l.forceString(e,"g"),l.isStringOrNumber(r))r=new RegExp(n.regEscape(r+""),e);else{if(!l.isRegExp(r))return i;r=new RegExp(r.source,e)}if(r.global)for(;o=r.exec(t);)i.push(o.index+1);else(o=r.exec(t))&&i.push(o.index+1);return i},n.count=function(t,r){return n.find(t,r).length},n.contains=function(t,r){return n.count(t,r)>0},n.between=function(t,r,e){var i,o;return l.allStringOrNumber(t,r,e)?(r=n.regEscape(r+""),e=n.regEscape(e+""),i=new RegExp(r+"(.+)"+e),(null!=(o=i.exec(t+""))?o[1]:void 0)||""):""},n.slice=function(t,r,n){return t=l.forceString(t),r=l.forceNumber(r||1),!1!==(r=l.positiveIndex(r,t.length))?(n=l.forceNumber(n),t.slice(r,r+n)):""},n.truncate=function(t,r,e){return t=l.forceString(t),r=l.forceNumber(r,t.length),t=n.slice(t,1,r),t+l.forceString(e)},n.pop=function(t,r){return t=l.forceString(t),r=l.forceNumber(r,1),t.slice(0,-Math.abs(r))},n.split=function(t,r){var e,i,o,u,s;if(t=n.oneSpaceAndTrim(t),i=[],t.length<1)return i;for(r=l.forceString(r," "),e=t.split(r[0]||""),u=0,s=e.length;s>u;u++)o=e[u],o.match(/^\s$/)||i.push(n.trim(o));return i},n.reverse=function(t){var r,n,e,i;if(null==t&&(t=""),t=l.forceString(t),(n=t.length-1)<1)return t;for(e="",r=i=n;0>=n?0>=i:i>=0;r=0>=n?++i:--i)e+=t[r];return e},n.upper=function(){var t,r;return r=arguments[0],t=2<=arguments.length?m.call(arguments,1):[],e.changeCase.apply(e,[r,"toUpperCase"].concat(m.call(t)))},n.lower=function(){var t,r;return r=arguments[0],t=2<=arguments.length?m.call(arguments,1):[],e.changeCase.apply(e,[r,"toLowerCase"].concat(m.call(t)))},n.insert=function(){var t,r,n,e,i,o;if(i=arguments[0],r=arguments[1],e=3<=arguments.length?m.call(arguments,2):[],""===(i=l.forceString(i))||""===(r=l.forceString(r)))return i;if(e=l.sortNoDupAndReverse(e,i.length),n=a(e)-1,0>n)return i;for(t=o=0;n>=0?n>=o:o>=n;t=n>=0?++o:--o)t=e[t],t>i.length?i+=r:i=i.substr(0,t)+r+i.substr(t);return i},n.removeRange=function(t,r,e){var i;return t=l.forceString(t),""===t||!1===(r=l.positiveIndex(r,t.length))||0>(e=l.forceNumber(e,1))?t:(i=r+e,n.xs(t,function(t,n){return r>n||n>=i?!0:void 0}))},n.removePos=function(){var t,r,e;return e=arguments[0],r=2<=arguments.length?m.call(arguments,1):[],""===(e=l.forceString(e))?"":(t=r.map(function(t){return l.positiveIndex(t,e.length)}),n.xs(e,function(r,n){return v.call(t,n)>=0?void 0:!0}))},n.remove=function(){var t,r,e,i,o;if(r=arguments[0],e=2<=arguments.length?m.call(arguments,1):[],null==r&&(r=""),""===(r=l.forceString(r))||e.length<1)return r;for(i=0,o=e.length;o>i;i++)t=e[i],r=n.replace(r,t);return r},n.startsWith=function(t,r){return""===(t=l.forceString(t))||""===(r=l.forceString(r))?!1:(r=new RegExp("^"+n.regEscape(r)),r.test(t))},n.endsWith=function(t,r){return""===(t=l.forceString(t))||""===(r=l.forceString(r))?!1:(r=new RegExp(n.regEscape(r)+"$"),r.test(t))},n.wrap=function(t,r){var e;return null==t&&(t=""),null==r&&(r=""),e=function(e){return n.create(t,e,r)},e.wrap=function(n,e){return null==n&&(n=""),null==e&&(e=""),t=l.forceString(n)+t,r+=l.forceString(e)},e},n.prototype.set=function(){return this.string=n.create.apply(this,arguments),this},n.prototype.sort=function(){return this.string=n.sort(this.string),this},n.prototype.random=function(t,r){return this.string=n.random(t,r),this},n.prototype.xs=function(t){return this.string=n.xs(this.string,t),this},n.prototype.times=function(t){return null==t&&(t=1),this.string=n.times(this.string,t),this},n.prototype.get=function(){var t,r,n,e;if(arguments.length>0){for(r="",n=0,e=arguments.length;e>n;n++)t=arguments[n],t=l.positiveIndex(t,this.length),t!==!1&&(r+=this.string[t]);return r}return this.string},n.prototype.copy=function(t,r){return n.copy(this.string,t,r)},n.prototype.empty=function(){return n.empty(this.string)},n.prototype.isAlpha=function(){return n.isAlpha(this.string)},n.prototype.isNumeric=function(){return n.isNumeric(this.string)},n.prototype.isAlphaNumeric=function(){return n.isAlphaNumeric(this.string)},n.prototype.isSpecial=function(){return n.isSpecial(this.string)},n.prototype.isSpace=function(){return n.isSpace(this.string)},n.prototype.isUpper=function(){return n.isUpper(this.string)},n.prototype.hasUpper=function(){return n.hasUpper(this.string)},n.prototype.isLower=function(){return n.isLower(this.string)},n.prototype.push=function(){return this.string=this.string+n.create.apply(this,arguments),this},n.prototype.prepend=function(){return this.string=n.create.apply(this,arguments)+this.string,this},n.prototype.pop=function(t){return this.string=n.pop(this.string,t),this},n.prototype.insert=function(){var t,r;return r=arguments[0],t=2<=arguments.length?m.call(arguments,1):[],this.string=n.insert.apply(n,[this.string,r].concat(m.call(t))),this},n.prototype.trim=function(){return this.string=n.trim(this.string),this},n.prototype.trimLeft=function(){return this.string=n.trimLeft(this.string),this},n.prototype.trimRight=function(){return this.string=n.trimRight(this.string),this},n.prototype.oneSpace=function(){return this.string=n.oneSpace(this.string),this},n.prototype.oneSpaceAndTrim=function(){return this.string=n.oneSpaceAndTrim(this.string),this},n.prototype.find=function(t){return n.find(this.string,t)},n.prototype.count=function(t){return n.count(this.string,t)},n.prototype.contains=function(t){return n.contains(this.string,t)},n.prototype.between=function(t,r){return n.between(this.string,t,r)},n.prototype.slice=function(t,r){return this.string=n.slice(this.string,t,r),this},n.prototype.truncate=function(t,r){return this.string=n.truncate(this.string,t,r),this},n.prototype.remove=function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],this.string=n.remove.apply(n,[this.string].concat(m.call(t))),this},n.prototype.removeRange=function(t,r){return this.string=n.removeRange(this.string,t,r),this},n.prototype.removePos=function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],this.string=n.removePos.apply(n,[this.string].concat(m.call(t))),this},n.prototype.replace=function(t,r,e){return this.string=n.replace(this.string,t,r,e),this},n.prototype.reverse=function(){return this.string=n.reverse(this.string),this},n.prototype.upper=function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],this.string=n.upper.apply(n,[this.string].concat(m.call(t))),this},n.prototype.lower=function(){var t;return t=1<=arguments.length?m.call(arguments,0):[],this.string=n.lower.apply(n,[this.string].concat(m.call(t))),this},n.prototype.shuffle=function(){return this.string=n.shuffle(this.string),this},n.prototype.toCamel=function(t){return this.string=n.toCamel(this.string,t),this},n.prototype.unCamel=function(t){return this.string=n.unCamel(this.string,t),this},n.prototype.startsWith=function(t){return n.startsWith(this.string,t)},n.prototype.endsWith=function(t){return n.endsWith(this.string,t)},n.prototype.setWrap=function(t,r){return l.isNull(this.wrapMethod)?this.wrapMethod=n.wrap(t,r):this.wrapMethod.wrap(t,r),this},n.prototype.removeWrap=function(){return this.wrapMethod=null,this},n.prototype.applyWrap=function(t,r){return this.string=this.setWrap(t,r).wrap,this.removeWrap(),this},n}(t),Object.defineProperty(n.prototype,"$",{get:function(){return this.get()}}),Object.defineProperty(n.prototype,"length",{get:function(){return this.string.length}}),Object.defineProperty(n.prototype,"wrap",{get:function(){return l.isNull(this.wrapMethod)?this.string:this.wrapMethod(this.string)}}),n.Types=o,n.Chars=t,n.crop=n.slice,n.prototype.crop=n.prototype.slice,n.prototype.append=n.prototype.push,s=function(){function t(){}return t.delimiter=" ",t.stringsFromArray=function(t){var r,n,e,i,o;for(r=[],o=l.forceArray(t),e=0,i=o.length;i>e;e++)n=o[e],l.isString(n)&&r.push(n);return r},t.numbersFromArray=function(t){var r,n,e,i,o;for(r=[],o=l.forceArray(t),e=0,i=o.length;i>e;e++)n=o[e],l.isNumber(n)&&r.push(n+0);return r},t.changeCase=function(r,e){var i,o,u,s,c,f,p,a,g,h,y;if(s=t.stringsFromArray(e),o=t.numbersFromArray(e),s.length>0&&this.set(n[r].apply(n,[this.string].concat(m.call(s)))),0===o[0]){for(g=[],c=0,p=o.length;p>c;c++)u=o[c],g.push(function(){var t,e,o;for(o=[],i=t=0,e=this.count-1;e>=0?e>=t:t>=e;i=e>=0?++t:--t)o.push(this.words[i]=n[r](this.words[i],u));return o}.call(this));return g}for(e.length<1&&(o=function(){h=[];for(var t=0,r=this.count;r>=0?r>=t:t>=r;r>=0?t++:t--)h.push(t);return h}.apply(this)),y=[],f=0,a=o.length;a>f;f++)i=o[f],i=l.positiveIndex(i,this.count),y.push(this.words[i]=n[r](this.words[i]));return y},t.applyToValidIndex=function(t,r,n){var e;return!1!==(e=l.positiveIndex(t,r))?n(e):void 0},t}(),u=function(t){function r(){this.set.apply(this,arguments)}return d(r,t),r.prototype.set=function(){var t,r,e,i,o,u,c,f;if(r=1<=arguments.length?m.call(arguments,0):[],this.words=[],r=l.intoArray.apply(this,r),r.length<1)return this;for(i=0,u=r.length;u>i;i++)for(t=r[i],f=n.split(n.create(t),s.delimiter),o=0,c=f.length;c>o;o++)e=f[o],this.words.push(e);return this},r.prototype.get=function(){var t,r,e,i;if(arguments.length<1)return this.words.join(s.delimiter);for(r="",e=0,i=arguments.length;i>e;e++)t=arguments[e],t=l.positiveIndex(t,this.count),t!==!1&&(r+=this.words[t]+s.delimiter);return n.trim(r)},r.prototype.xs=function(t){var r,n,e,i,o,u,s;if(null==t&&(t=function(){return!0}),l.notFunction(t)||this.count<1)return this;for(e=[],s=this.words,r=o=0,u=s.length;u>o;r=++o)i=s[r],(n=t(i,r))&&(n===!0?e.push(i):l.isStringOrNumber(n)&&e.push(n+""));return this.words=e,this},r.prototype.find=function(t){var r;return r=[],""!==(t=l.forceString(t))&&this.xs(function(n,e){return n===t&&r.push(e+1),!0}),r},r.prototype.upper=function(){return s.changeCase.call(this,"upper",Array.prototype.slice.call(arguments)),this},r.prototype.lower=function(){return s.changeCase.call(this,"lower",Array.prototype.slice.call(arguments)),this},r.prototype.reverse=function(){var t,r,e;if(0===(null!=arguments?arguments[0]:void 0))this.xs(function(t){return n.reverse(t)});else if(arguments.length>0)for(r=0,e=arguments.length;e>r;r++)t=arguments[r],s.applyToValidIndex(t,this.count,function(t){return function(r){return t.words[r]=n.reverse(t.words[r])}}(this));else this.xs(function(t){return function(r,n){return t.get(t.count-n)}}(this));return this},r.prototype.shuffle=function(t){var r,e,i,o,u;if(null!=t)if(l.isString(t))for(e=0,o=arguments.length;o>e;e++)r=arguments[e],this.xs(function(){return function(t){return t===r?n.shuffle(t):!0}}(this));else if(0===t)this.xs(function(t){return n.shuffle(t)});else for(i=0,u=arguments.length;u>i;i++)r=arguments[i],s.applyToValidIndex(r,this.count,function(t){return function(r){return t.words[r]=n.shuffle(t.words[r])}}(this));else this.words=l.shuffleArray(this.words);return this},r.prototype.clear=function(){return this.words=[],this},r.prototype.remove=function(){var t,n,e,i,o,u,s;if(arguments.length<1)return this;for(n=[],i=0,u=arguments.length;u>i;i++)t=arguments[i],l.isString(t)?n.unshift(t):l.isNumber(t)&&n.push(r.positiveIndex(t,this.count));for(n=l.noDupAndReverse(l.insertSort(n)),e=o=0,s=n.length;s>o;e=++o)t=n[e],l.isNumber(t)?this.xs(function(){return function(r,n){return n!==t?!0:void 0}}(this)):l.isString(t)&&this.xs(function(r){return r!==t?!0:void 0});return this},r.prototype.pop=function(t){var r,n,e,i;for(t=Math.abs(l.forceNumber(t,1)),e="",r=i=1;t>=1?t>=i:i>=t;r=t>=1?++i:--i)n=this.words.pop(),void 0!==n&&(e=n+" "+e);return e.trim()},r.prototype.push=function(){var t,r,e;for(r=0,e=arguments.length;e>r;r++)t=arguments[r],""!==(t=l.forceString(t))&&this.words.push(n.trim(t));return this},r.prototype.shift=function(t){var r,n;for(t=l.forceNumber(t,1),r=n=1;t>=1?t>=n:n>=t;r=t>=1?++n:--n)this.words.shift();return this},r.prototype.prepend=function(){var t,r,e,i;for(r=0,e=0,i=arguments.length;i>e;e++)t=arguments[e],""!==(t=l.forceString(t))&&(this.words.splice(r,0,n.trim(t)),r++);return this},r.prototype.insert=function(){var t,r,e,i,o,u;for(t=arguments[0],i=2<=arguments.length?m.call(arguments,1):[],t=l.positiveIndex(t,this.count),r=0,o=0,u=i.length;u>o;o++)e=i[o],""!==(e=l.forceString(e))&&(this.words.splice(t+r,0,n.trim(e)),r++);return this},r.prototype.replace=function(t,r){return null==r&&(r=""),""===(r=n.trim(r))?this:(l.isNumber(t)?s.applyToValidIndex(t,this.count,function(t){return function(n){return t.words.splice(n,1,r)}}(this)):this.xs(function(n){return n===t?r:!0}),this)},r.prototype.sort=function(){return l.insertSort(this.words),this},r.prototype.startsWith=function(t){var n;return""===(t=l.forceString(t))?!1:(n=!0,t=new r(t),t.xs(function(t){return function(r,e){return r!==t.words[e]?n=!1:void 0}}(this)),n)},r.prototype.endsWith=function(t){var n,e,i,o,u;if(""===(t=l.forceString(t)))return!1;for(i=!0,n=1,t=new r(t),e=o=u=t.count;1>=u?1>=o:o>=1;e=1>=u?++o:--o)t.get(e)!==this.words[this.count-n++]&&(i=!1);return i},r}(n),Object.defineProperty(u.prototype,"$",{get:function(){return this.get()}}),Object.defineProperty(u.prototype,"string",{get:function(){return this.get()}}),Object.defineProperty(u.prototype,"count",{get:function(){return this.words.length}}),u.prototype.unshift=u.prototype.prepend,u.flexArgs=o.intoArray,u.Strings=n,u.Types=o,u.Chars=t,"undefined"!=typeof define&&null!==define&&"function"==typeof define&&define.amd?define("words",[],function(){return u}):"undefined"!=typeof window&&null!==window?(window.Words=u,window.Types=o,window.Strings=n):"undefined"!=typeof module&&null!==module&&(module.exports=u)}).call(this); | ||
"use strict";function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _inherits(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),r&&_setPrototypeOf(t,r)}function _setPrototypeOf(t,r){return(_setPrototypeOf=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t})(t,r)}function _createSuper(n){return function(){var t,r=_getPrototypeOf(n);if(_isNativeReflectConstruct()){var e=_getPrototypeOf(this).constructor;t=Reflect.construct(r,arguments,e)}else t=r.apply(this,arguments);return _possibleConstructorReturn(this,t)}}function _possibleConstructorReturn(t,r){return!r||"object"!==_typeof(r)&&"function"!=typeof r?_assertThisInitialized(t):r}function _assertThisInitialized(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}function _getPrototypeOf(t){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function _toConsumableArray(t){return _arrayWithoutHoles(t)||_iterableToArray(t)||_unsupportedIterableToArray(t)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(t,r){if(t){if("string"==typeof t)return _arrayLikeToArray(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(e):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?_arrayLikeToArray(t,r):void 0}}function _iterableToArray(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}function _arrayWithoutHoles(t){if(Array.isArray(t))return _arrayLikeToArray(t)}function _arrayLikeToArray(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}function _classCallCheck(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function _createClass(t,r,e){return r&&_defineProperties(t.prototype,r),e&&_defineProperties(t,e),t}(function(){var t,p,r,l,y,e;e=(p=y=require("strings.js")).Types,t=p.Chars,l=function(){var t=function(){function h(){_classCallCheck(this,h)}return _createClass(h,null,[{key:"stringsFromArray",value:function(t){var r,e,n,o,i;for(o=[],r=0,e=(n=y.forceArray(t)).length;r<e;r++)i=n[r],y.isString(i)&&o.push(i);return o}},{key:"numbersFromArray",value:function(t){var r,e,n,o,i;for(n=[],r=0,e=(o=y.forceArray(t)).length;r<e;r++)i=o[r],y.isNumber(i)&&n.push(i+0);return n}},{key:"changeCase",value:function(n,t){var r,o,e,i,s,u,f,a,l,c;c=h.stringsFromArray(t),e=h.numbersFromArray(t),0<c.length&&this.set(p[n].apply(p,[this.string].concat(_toConsumableArray(c))));if(0===e[0]){for(a=[],r=0,s=e.length;r<s;r++)f=e[r],a.push(function(){var t,r,e;for(e=[],o=t=0,r=this.count-1;0<=r?t<=r:r<=t;o=0<=r?++t:--t)e.push(this.words[o]=p[n](this.words[o],f));return e}.call(this));return a}for(t.length<1&&(e=function(){for(var t=[],r=0,e=this.count;0<=e?r<=e:e<=r;0<=e?r++:r--)t.push(r);return t}.apply(this)),l=[],i=0,u=e.length;i<u;i++)o=e[i],o=y.positiveIndex(o,this.count),l.push(this.words[o]=p[n](this.words[o]));return l}},{key:"applyToValidIndex",value:function(t,r,e){var n;if(!1!==(n=y.positiveIndex(t,r)))return e(n)}}]),h}();return t.delimiter=" ",t}.call(this),r=function(){_inherits(u,p);var o=_createSuper(u);function u(){for(var t,r=arguments.length,e=new Array(r),n=0;n<r;n++)e[n]=arguments[n];return _classCallCheck(this,u),(t=o.call(this)).set.apply(_assertThisInitialized(t),arguments),t}return _createClass(u,[{key:"set",value:function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];var n,o,i,s,u,f,a;if(this.words=[],(r=y.intoArray.apply(this,r)).length<1)return this;for(o=0,s=r.length;o<s;o++)for(n=r[o],i=0,u=(f=p.split(p.create(n),l.delimiter)).length;i<u;i++)a=f[i],this.words.push(a);return this}},{key:"get",value:function(){var t,r,e,n;if(arguments.length<1)return this.words.join(l.delimiter);for(n="",t=0,e=arguments.length;t<e;t++)r=arguments[t],!1!==(r=y.positiveIndex(r,this.count))&&(n+=this.words[r]+l.delimiter);return p.trim(n)}},{key:"xs",value:function(t){var r,e,n,o,i,s,u,f=0<arguments.length&&void 0!==t?t:function(){return!0};if(y.notFunction(f)||this.count<1)return this;for(s=[],e=r=0,n=(o=this.words).length;r<n;e=++r)(i=f(u=o[e],e))&&(!0===i?s.push(u):y.isStringOrNumber(i)&&s.push(i+""));return this.words=s,this}},{key:"find",value:function(e){var n;return n=[],""!==(e=y.forceString(e))&&this.xs(function(t,r){return t===e&&n.push(r+1),!0}),n}},{key:"upper",value:function(){return l.changeCase.call(this,"upper",Array.prototype.slice.call(arguments)),this}},{key:"lower",value:function(){return l.changeCase.call(this,"lower",Array.prototype.slice.call(arguments)),this}},{key:"reverse",value:function(t){var r,e,n,o=this;if(0===(null!=arguments?t:void 0))this.xs(function(t){return p.reverse(t)});else if(0<arguments.length)for(e=0,n=arguments.length;e<n;e++)r=arguments[e],l.applyToValidIndex(r,this.count,function(t){return o.words[t]=p.reverse(o.words[t])});else this.xs(function(t,r){return o.get(o.count-r)});return this}},{key:"shuffle",value:function(t){var e,r,n,o,i,s=this;if(null!=t)if(y.isString(t))for(r=0,o=arguments.length;r<o;r++)e=arguments[r],this.xs(function(t,r){return t!==e||p.shuffle(t)});else if(0===t)this.xs(function(t){return p.shuffle(t)});else for(n=0,i=arguments.length;n<i;n++)e=arguments[n],l.applyToValidIndex(e,this.count,function(t){return s.words[t]=p.shuffle(s.words[t])});else this.words=y.shuffleArray(this.words);return this}},{key:"clear",value:function(){return this.words=[],this}},{key:"remove",value:function(){var e,t,r,n,o,i,s;if(arguments.length<1)return this;for(t=[],r=0,i=arguments.length;r<i;r++)e=arguments[r],y.isString(e)?t.unshift(e):y.isNumber(e)&&t.push(u.positiveIndex(e,this.count));for(n=o=0,s=(t=y.noDupAndReverse(y.insertSort(t))).length;o<s;n=++o)e=t[n],y.isNumber(e)?this.xs(function(t,r){if(r!==e)return!0}):y.isString(e)&&this.xs(function(t){if(t!==e)return!0});return this}},{key:"pop",value:function(t){var r,e,n,o;for(n="",r=1,o=t=Math.abs(y.forceNumber(t,1));1<=o?r<=o:o<=r;1<=o?++r:--r)e=this.words.pop(),void 0!==e&&(n=e+" "+n);return n.trim()}},{key:"push",value:function(){var t,r,e;for(r=0,e=arguments.length;r<e;r++)t=arguments[r],""!==(t=y.forceString(t))&&this.words.push(p.trim(t));return this}},{key:"shift",value:function(t){var r,e;for(r=1,e=t=y.forceNumber(t,1);1<=e?r<=e:e<=r;1<=e?++r:--r)this.words.shift();return this}},{key:"prepend",value:function(){var t,r,e,n;for(r=n=0,e=arguments.length;r<e;r++)t=arguments[r],""!==(t=y.forceString(t))&&(this.words.splice(n,0,p.trim(t)),n++);return this}},{key:"insert",value:function(t){var r,e,n,o;t=y.positiveIndex(t,this.count),n=0;for(var i=arguments.length,s=new Array(1<i?i-1:0),u=1;u<i;u++)s[u-1]=arguments[u];for(r=0,e=s.length;r<e;r++)o=s[r],""!==(o=y.forceString(o))&&(this.words.splice(t+n,0,p.trim(o)),n++);return this}},{key:"replace",value:function(r,t){var e=this,n=1<arguments.length&&void 0!==t?t:"";return""===(n=p.trim(n))||(y.isNumber(r)?l.applyToValidIndex(r,this.count,function(t){return e.words.splice(t,1,n)}):this.xs(function(t){return t!==r||n})),this}},{key:"sort",value:function(){return y.insertSort(this.words),this}},{key:"startsWith",value:function(t){var e,n=this;return""!==(t=y.forceString(t))&&(e=!0,(t=new u(t)).xs(function(t,r){if(t!==n.words[r])return e=!1}),e)}},{key:"endsWith",value:function(t){var r,e,n,o,i;if(""===(t=y.forceString(t)))return!1;for(i=!0,r=1,n=e=o=(t=new u(t)).count;o<=1?e<=1:1<=e;n=o<=1?++e:--e)t.get(n)!==this.words[this.count-r++]&&(i=!1);return i}}]),u}(),Object.defineProperty(r.prototype,"$",{get:function(){return this.get()}}),Object.defineProperty(r.prototype,"string",{get:function(){return this.get()}}),Object.defineProperty(r.prototype,"count",{get:function(){return this.words.length}}),r.prototype.unshift=r.prototype.prepend,r.flexArgs=e.intoArray,r.Strings=p,r.types=e,r.Chars=t,"undefined"!=typeof define&&null!==define&&"function"==typeof define&&define.amd?define("words",[],function(){return r}):"undefined"!=typeof window&&null!==window?(window.Words=r,window.types=e,window.Strings=p):"undefined"!=typeof module&&null!==module&&(module.exports=r)}).call(void 0); |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
86280
1
3
9
1281
466
1
+ Addedstrings.js@latest
+ Addedstrings.js@1.4.2(transitive)
+ Addedtypes.js@2.0.1(transitive)