New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

words.js

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

words.js - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

11

package.json
{
"name": "words.js",
"version": "0.1.1",
"version": "0.1.2",
"description": "A flexible, robust and powerful Javascript word-string manipulation library.",

@@ -16,7 +16,8 @@ "main": "words.min.js",

"strings",
"string-manipulation",
"string-tool",
"tool",
"tools",
"word",
"words",
"word-manipulation"
"manipulation",
"library"
],

@@ -30,5 +31,5 @@ "author": "Dennis Raymondo <phazelift@gmail.com> (https://github.com/phazelift/)",

"dependencies": {
"strings.js" : "1.1.2"
"strings.js" : "1.1.4"
},
"devDependencies": {}
}
words.js
========
words.js is an addition to my strings.js library, and operates primarily on single word-strings instead of
individual characters.
words.js is all about finding/manipulating/sorting/adding/removing words in or from a string.
<br/>
<br/>
words.js extends strings.js. 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. This same idea applies to pretty much all methods of
words.js, although some methods like .upper() and .lower(), combine word and character based manipulation.
<br/><br/>
This is in a very early stage of development, things will change for sure, use with care.
___
You can use `npm install words.js` when using node.js. The dependant strings.js and included types.js will
automatically be installed as well.
<br/>
<br/>
Use:
```javascript
var Types= Words.Types
var Strings= Words.Strings
// or
var Types= require('words.js').Types;
var Strings= require('words.js').Strings;
```
to have the non-overloaded strings.js, but also the handy types.js functions available as well.
___
This manual is still incomplete, will try to complete soon.
types.js, strings.js and words.js are a very powerful set of building blocks that can make the life of a Javascript
developer much more pleasant and bug free IMHO.
<br/>
Words are seperated by spaces.
<br/><br/>
All examples are to be found in the API below.
___

@@ -20,9 +39,25 @@ API

**Words.prototype.constructor**
> `<object>constructor( <string>/<number> string= '', <string>/<number> delimiter= ' ' )`
> `<this> constructor( <string>/<number> string= '', <string>/<number> delimiter= ' ' )`
> Initializes the contextual object.
> Use any combination of arguments to form a string. All invalid arguments will be ignored.
```javascript
var words= new Words('numbers accepted', 123, 'not objects, arrays etc..', {}, [1,2,3], 'they are simply ignored..');
// numbers accepted 123 not objects, arrays etc.. they are simply ignored..
```
**Words.prototype.set**
> `<string> set( <string>/<number> index, [index1, ..., indexN] )`
> Set the internal array. Use any combination of arguments to form a string. All
> invalid arguments will be ignored.
```javascript
var words= new Words();
words.set( 'numbers accepted', 123, 'not objects, arrays etc..', {}, [1,2,3], 'they are simply ignored..' );
// numbers accepted 123 not objects, arrays etc.. they are simply ignored..
```
**Words.prototype.get**

@@ -33,22 +68,92 @@ > `<string> get( <string>/<number> index, [index1, ..., indexN] )`

```javascript
words.set( 'numbers accepted', 123, 'not objects, arrays etc..', {}, [1,2,3], 'they are simply ignored..' );
words.get( 1, 2, 6, -1 );
// numbers accepted arrays ignored..
```
**Words.prototype.xs**
> `<this> xs( <function> callback(<string> word, <number> index) )`
> Access every index/word of the internal array and apply the result of callback to it. After a call to xs, the
> internal array 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 the internal array.
```javascript
words.set( 'numbers accepted', 123, 'not objects, arrays etc..', {}, [1,2,3], 'they are simply ignored..' );
var max3= words.xs( function(word, index){
return true if word.length < 4 ).$;
});
// 123 not are
var max3= words.xs( function(word, index){
if( word === '123' )
return '*'+ word+ '*'
else return true
});
// numbers accepted *123* not objects, arrays etc.. they are simply ignored..
```
**Words.prototype.find**
> `<array> find( <string>/<number> substring, <boolean> addPositions= false )`
> `<array> find( <string>/<number> substring )`
> Returns an array containing all indices(numbers) in this.words where substring is found. If addPositions is set
> true, also the position within the found word is returned, and the result will be an array of arrays with indices.
> Returns an array containing all indices(numbers) in the internal array where substring is found.
```javascript
words.set( 'numbers accepted', 123, 'not objects, arrays etc..', {}, [1,2,3], 'they are simply ignored..' );
words.find( 'hello' );
// []
words.find( 'accepted' );
// [2]
```
**Words.prototype.upper**
> `<string> upper( <string>/<number> index, <string>/<number> position )`
> `<this> upper( <string>/<number> index, <string>/<number> position )`
> Change words or characters in words 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.
```javascript
words.set( 'numbers accepted', 123, 'not objects, arrays etc..', {}, [1,2,3], 'they are simply ignored..' );
console.log( words.upper(0, 1, -1).$ );
// NumberS AccepteD 123 NoT Objects, ArrayS Etc.. TheY ArE SimplY Ignored..
console.log( words.upper(1, 4, -1).$ );
// note that the internal array is changed and we are applying a upper over it:
// NUMBERS AccepteD 123 NOT Objects, ArrayS Etc.. TheY ArE SimplY IGNORED..
console.log( words.upper().$ );
// NUMBERS ACCEPTED 123 NOT OBJECTS, ARRAYS ETC.. THEY ARE SIMPLY IGNORED..
```
**Words.prototype.lower**
> `<string> lower( <string>/<number> index, <string>/<number> position )`
> `<this> lower( <string>/<number> index, <string>/<number> position )`
> The same as with .upper(), except for that uppercase characters are changed to lowercase.
**Words.prototype.reverse**
> `<array> reverse( <string>/<number> index, [index1, ..., indexN] )`
> `<this> reverse( <string>/<number> index, [index1, ..., indexN] )`
> Reverses the word on index if index is given. If index is 0, every word is reversed, but will remain on it's
> current index, every following index will not be reversed. Without arguments, all words and all indices are reversed.
> Without arguments the whole internal array(as string) is reversed. With index or indices given, the words denoted by
> indices are reversed. If index is 0, every word is reversed, but will remain on it's original/current index,
> every additional argument is ignored.
```javascript
words.set( 'numbers accepted', 123, 'not objects, arrays etc..', {}, [1,2,3], 'they are simply ignored..' );
console.log( words.reverse().$ );
//..derongi ylpmis era yeht ..cte syarra ,stcejbo ton 321 detpecca srebmun
words.set( 'numbers accepted', 123, 'not objects, arrays etc..', {}, [1,2,3], 'they are simply ignored..' );
console.log( words.reverse(0).$ );
// srebmun detpecca 321 ton ,stcejbo syarra ..cte yeht era ylpmis ..derongi
words.set( 'numbers accepted', 123, 'not objects, arrays etc..', {}, [1,2,3], 'they are simply ignored..' );
console.log( words.reverse(1, 3, -2).$ );
// srebmun accepted 321 not objects, arrays etc.. they are ylpmis ignored..
```
**Words.prototype.shuffle**
> `<array> shuffle( <string>/<number> index, [index1, ..., indexN] )`
> `<this> shuffle( <string>/<number> index, [index1, ..., indexN] )`

@@ -59,5 +164,139 @@ > Shuffles the word on index, if index is given. If index is/are strings, the matching words will be shuffled.

```javascript
words.set( 'numbers accepted', 123, 'not objects, arrays etc..', {}, [1,2,3], 'they are simply ignored..' );
console.log( words.shuffle().$ );
// without arguments all words positions are pseudo randomly shuffled:
// they numbers accepted not objects, etc.. ignored.. arrays are simply 123
words.set( 'numbers accepted', 123, 'not objects, arrays etc..', {}, [1,2,3], 'they are simply ignored..' );
console.log( words.reverse(0).$ );
// with 0, characters in words are pseudo randomly shuffled in place, below a run on my system:
//brmneus ptcdeace 231 tno e,bsctjo raaysr .et.c yteh ear ilmyps .ro.engdi
words.set( 'numbers accepted', 123, 'not objects, arrays etc..', {}, [1,2,3], 'they are simply ignored..' );
console.log( words.reverse(1, 3, -1).$ );
// characters in words on indices are pseudo randomly shuffled:
//rubmsne accepted 312 not objects, arrays etc.. they are simply d.eirno.g
```
**Words.prototype.clear**
> `<this> clear()`
> Resets the internal array to empty [].
**Words.prototype.remove**
> `<this> remove( <string>/<number> indices and or words )`
> Removes any combination of indices or words from the internal array. Without arguments remove does nothing.
> Invalid arguments are ignored
```javascript
var words= new Words( 'testing words is real fun, actually for real!' );
console.log( words.remove( null, 'real', -1, {}, 4, 5, new Date(), -2, 'is', []) );
// testing words actually
```
**Words.prototype.pop**
> `pop( <string>/<number> amount )`
> Removes the last word from the internal array if no arguments are given. If amount is valid, amount words will
> be removed from the internal array, starting from the last word going backwards.
```javascript
var words= new Words( 'testing words is real fun!' );
console.log( words.pop(3) );
// testing words
```
**Words.prototype.push**
> `push( <string>/<number> word, [word1, ..., wordN] )`
> Adds words to the end of the internal array.
```javascript
var words= new Words( 'testing words' );
console.log( words.push( 'before', 'usage' ).$ );
// testing words before usage
```
**Words.prototype.shift**
> `shift( <string>/<number> amount )`
> Removes the first word from the internal array if no arguments are given. If amount is valid, amount words will
> be removed from the internal array, starting from the first word going forwards.
```javascript
var words= new Words( 'serious testing of words is fun!' );
console.log( words.shift(3).$ );
// words is fun!
```
**Words.prototype.unshift**
> `unshift( <string>/<number> word, [word1, ..., wordN] )`
> Adds words to the beginning of the internal array.
```javascript
var words= new Words( 'words is fun!' );
console.log( words.unshift('of', 'testing', 'serious').$ );
// serious testing of words is fun!
```
**Words.prototype.insert**
> `insert( <string>/<number> index, <string>/<number> word, [word1, ..., wordN] )`
> Insert word(s) at index of the internal array.
```javascript
var words= new Words( 'testing words' );
console.log( words.insert( -1, 'some', 'silly' ).$ );
// testing some silly words
```
**Words.prototype.replace**
> `replace( <string>/<number> selection, <string>/<number> replacement )`
> Replace all words equal to selection to replacement.
```javascript
var words= new Words( 'to replace or not to replace' );
console.log( words.replace('replace', 'be').$ );
// to be or not to be
```
**Words.prototype.sort**
> `<this> sort()`
> Sorts the internal array alphabetically
```javascript
var words= new Words( 'testing words is really funny actually' );
console.log( words.sort().$ );
// actually funny is really testing words
```
__________
change log
==========
**0.1.2**
words.js now depends on strings.js version 1.1.4.. strings.js now includes types.js version 1.2.8, which is
improved with force'Type'. Check types.js in the phazelift repo for changes and API.
Words.prototype.find only finds words now, use Strings.find for finding characters in words.
Words.prototype.remove(0) has been removed as an option to clear the internal array. Not a big thing, I just thought
that we have .clear() for that, so it felt a bit confusing and redundant.
The manual is now more complete and up to date.
Next up are the Jasmine tests!
__________
// Generated by CoffeeScript 1.8.0
(function() {
"use strict";
var Str, Strings, Words, changeCase, delimiter, _,
var Str, Strings, Words, applyToValidIndex, changeCase, delimiter, insertSort, objectToArray, removeDupAndFlip, _,
__slice = [].slice,

@@ -11,2 +11,39 @@ __hasProp = {}.hasOwnProperty,

removeDupAndFlip = 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;
};
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;
}
return array;
};
objectToArray = function(object) {
var array, data, key;
array = [];
for (key in object) {
data = object[key];
array.push(data);
}
return array;
};
changeCase = function(method, args) {

@@ -48,2 +85,11 @@ var index, pos, _i, _j, _k, _len, _len1, _ref, _results, _results1, _results2;

applyToValidIndex = (function(_this) {
return function(orgIndex, limit, callback) {
var index;
if (false !== (index = _.positiveIndex(orgIndex, limit))) {
return callback(index);
}
};
})(this);
delimiter = ' ';

@@ -124,3 +170,3 @@

} else if (_.isStringOrNumber(response)) {
result.push(response);
result.push(response + '');
}

@@ -133,19 +179,11 @@ }

Words.prototype.find = function(string, showPositions) {
Words.prototype.find = function(string) {
var indices;
indices = [];
if ('' !== (string = Str.force(string))) {
if ('' !== (string = _.forceString(string))) {
this.xs(function(word, index) {
var position, _i, _len, _ref, _results;
_ref = Str.find(word, string);
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
position = _ref[_i];
if (showPositions) {
_results.push(indices.push([index + 1, position]));
} else {
_results.push(indices.push(index + 1));
}
if (word === string) {
indices.push(index + 1);
}
return _results;
return true;
});

@@ -156,10 +194,2 @@ }

Words.prototype.applyToValidIndex = function(orgIndex, callback) {
var index;
if (false !== (index = _.positiveIndex(orgIndex, this.count))) {
callback(index);
}
return this;
};
Words.prototype.upper = function() {

@@ -177,2 +207,3 @@ changeCase.call(this, 'upper', Array.prototype.slice.call(arguments));

var arg, _i, _len;
console.log('from words: ', arguments);
if ((arguments != null ? arguments[0] : void 0) === 0) {

@@ -185,3 +216,3 @@ this.xs(function(word) {

arg = arguments[_i];
this.applyToValidIndex(arg, (function(_this) {
applyToValidIndex(arg, this.count, (function(_this) {
return function(index) {

@@ -220,3 +251,3 @@ return _this.words[index] = Str.reverse(_this.words[index]);

arg = arguments[_j];
this.applyToValidIndex(arg, (function(_this) {
applyToValidIndex(arg, this.count, (function(_this) {
return function(index) {

@@ -240,12 +271,27 @@ return _this.words[index] = Str.shuffle(_this.words[index]);

Words.prototype.remove = function() {
var arg, _i, _len;
var arg, args, index, _i, _j, _len, _len1;
if (arguments.length < 1) {
return this;
}
if ((arguments != null ? arguments[0] : void 0) === 0) {
return this.clear();
}
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 = removeDupAndFlip(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) {

@@ -256,10 +302,2 @@ if (word !== arg) {

});
} else {
this.xs((function(_this) {
return function(word) {
if (word !== _this.words[_.positiveIndex(arg, _this.count)]) {
return true;
}
};
})(this));
}

@@ -272,5 +310,3 @@ }

var n, _i;
if (amount == null) {
amount = 1;
}
amount = _.forceNumber(amount, 1);
for (n = _i = 1; 1 <= amount ? _i <= amount : _i >= amount; n = 1 <= amount ? ++_i : --_i) {

@@ -286,3 +322,3 @@ this.words.pop();

arg = arguments[_i];
if (_.isStringOrNumber(arg)) {
if ('' !== (arg = _.forceString(arg))) {
this.words.push(Str.trim(arg));

@@ -296,5 +332,3 @@ }

var n, _i;
if (amount == null) {
amount = 1;
}
amount = _.forceNumber(amount, 1);
for (n = _i = 1; 1 <= amount ? _i <= amount : _i >= amount; n = 1 <= amount ? ++_i : --_i) {

@@ -310,3 +344,3 @@ this.words.shift();

arg = arguments[_i];
if (_.isStringOrNumber(arg)) {
if ('' !== (arg = _.forceString(arg))) {
this.words.unshift(Str.trim(arg));

@@ -319,11 +353,11 @@ }

Words.prototype.insert = function() {
var index, word, words, _i, _len;
var count, index, word, words, _i, _len;
index = arguments[0], words = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
if (_.isString(index)) {
return this.prepend.apply(this, arguments);
index = _.positiveIndex(index, this.count);
for (count = _i = 0, _len = words.length; _i < _len; count = ++_i) {
word = words[count];
if ('' !== (word = _.forceString(word))) {
this.words.splice(index + count, 0, Str.trim(word));
}
}
for (_i = 0, _len = words.length; _i < _len; _i++) {
word = words[_i];
this.words.splice(index, 0, Str.trim(word));
}
return this;

@@ -340,3 +374,3 @@ };

if (_.isNumber(selection)) {
this.applyToValidIndex(selection, (function(_this) {
applyToValidIndex(selection, this.count, (function(_this) {
return function(index) {

@@ -357,2 +391,7 @@ return _this.words.splice(index, 1, replacement);

Words.prototype.sort = function() {
insertSort(this.words);
return this;
};
return Words;

@@ -364,2 +403,8 @@

Words.Strings = Strings;
Words.Types = Strings.Types;
Words.Chars = Strings.Chars;
if (typeof window !== "undefined" && window !== null) {

@@ -366,0 +411,0 @@ return window.Words;

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

(function(){"use strict";var t,r,n,e,i,s,u=[].slice,o={}.hasOwnProperty,f=function(t,r){for(var n in r){if(o.call(r,n))t[n]=r[n]}function e(){this.constructor=t}e.prototype=r.prototype;t.prototype=new e;t.__super__=r.prototype;return t};r=t=s=require("strings.js");e=function(r,n){var e,i,o,f,h,p,l,a,c,g,d;if(s.isString(n!=null?n[0]:void 0)){return this.set(t[r].apply(t,[this.$].concat(u.call(n))))}else if((n!=null?n[0]:void 0)===0){c=[];for(o=0,p=n.length;o<p;o++){i=n[o];c.push(function(){var n,s,u;u=[];for(e=n=0,s=this.count-1;0<=s?n<=s:n>=s;e=0<=s?++n:--n){u.push(this.words[e]=t[r](this.words[e],i))}return u}.call(this))}return c}else{if(n.length<1){n=function(){g=[];for(var t=0,r=this.count;0<=r?t<=r:t>=r;0<=r?t++:t--){g.push(t)}return g}.apply(this)}d=[];for(h=0,l=n.length;h<l;h++){i=n[h];i=s.positiveIndex(i,this.count);d.push(this.words[i]=t[r](this.words[i]))}return d}};i=" ";n=function(r){f(n,r);function n(){Object.defineProperty(this,"$",{get:function(){return this.get()}});Object.defineProperty(this,"string",{get:function(){return this.get()}});Object.defineProperty(this,"count",{get:function(){return this.words.length}});this.set.apply(this,arguments)}n.prototype.set=function(){var r,n,e,s,u,o,f;if(arguments.length<1){return this}this.words=[];for(e=0,u=arguments.length;e<u;e++){r=arguments[e];f=t.split(t.create(r),i);for(s=0,o=f.length;s<o;s++){n=f[s];this.words.push(n)}}return this};n.prototype.get=function(){var r,n,e,u;if(arguments.length<1){return this.words.join(i)}n="";for(e=0,u=arguments.length;e<u;e++){r=arguments[e];r=s.positiveIndex(r,this.count);if(r!==false){n+=this.words[r]+i}}return t.trim(n)};n.prototype.xs=function(t){var r,n,e,i,u,o,f;if(t==null){t=function(){return true}}if(s.notFunction(t)||this.count<1){return}e=[];f=this.words;for(r=u=0,o=f.length;u<o;r=++u){i=f[r];if(n=t(i,r)){if(n===true){e.push(i)}else if(s.isStringOrNumber(n)){e.push(n)}}}this.words=e;return this};n.prototype.find=function(r,n){var e;e=[];if(""!==(r=t.force(r))){this.xs(function(i,s){var u,o,f,h,p;h=t.find(i,r);p=[];for(o=0,f=h.length;o<f;o++){u=h[o];if(n){p.push(e.push([s+1,u]))}else{p.push(e.push(s+1))}}return p})}return e};n.prototype.applyToValidIndex=function(t,r){var n;if(false!==(n=s.positiveIndex(t,this.count))){r(n)}return this};n.prototype.upper=function(){e.call(this,"upper",Array.prototype.slice.call(arguments));return this};n.prototype.lower=function(){e.call(this,"lower",Array.prototype.slice.call(arguments));return this};n.prototype.reverse=function(){var r,n,e;if((arguments!=null?arguments[0]:void 0)===0){this.xs(function(r){return t.reverse(r)})}else if(arguments.length>0){for(n=0,e=arguments.length;n<e;n++){r=arguments[n];this.applyToValidIndex(r,function(r){return function(n){return r.words[n]=t.reverse(r.words[n])}}(this))}}else{this.set(t.reverse(this.$))}return this};n.prototype.shuffle=function(r){var n,e,i,u,o;if(r!=null){if(s.isString(r)){for(e=0,u=arguments.length;e<u;e++){n=arguments[e];this.xs(function(r){return function(r,e){if(r===n){return t.shuffle(r)}return true}}(this))}}else if(r===0){this.xs(function(r){return t.shuffle(r)})}else{for(i=0,o=arguments.length;i<o;i++){n=arguments[i];this.applyToValidIndex(n,function(r){return function(n){return r.words[n]=t.shuffle(r.words[n])}}(this))}}}else{this.words=s.shuffleArray(this.words)}return this};n.prototype.clear=function(){this.words=[];return this};n.prototype.remove=function(){var t,r,n;if(arguments.length<1){return this}if((arguments!=null?arguments[0]:void 0)===0){return this.clear()}for(r=0,n=arguments.length;r<n;r++){t=arguments[r];if(s.isString(t)){this.xs(function(r){if(r!==t){return true}})}else{this.xs(function(r){return function(n){if(n!==r.words[s.positiveIndex(t,r.count)]){return true}}}(this))}}return this};n.prototype.pop=function(t){var r,n;if(t==null){t=1}for(r=n=1;1<=t?n<=t:n>=t;r=1<=t?++n:--n){this.words.pop()}return this};n.prototype.push=function(){var r,n,e;for(n=0,e=arguments.length;n<e;n++){r=arguments[n];if(s.isStringOrNumber(r)){this.words.push(t.trim(r))}}return this};n.prototype.shift=function(t){var r,n;if(t==null){t=1}for(r=n=1;1<=t?n<=t:n>=t;r=1<=t?++n:--n){this.words.shift()}return this};n.prototype.prepend=function(){var r,n,e;for(n=0,e=arguments.length;n<e;n++){r=arguments[n];if(s.isStringOrNumber(r)){this.words.unshift(t.trim(r))}}return this};n.prototype.insert=function(){var r,n,e,i,o;r=arguments[0],e=2<=arguments.length?u.call(arguments,1):[];if(s.isString(r)){return this.prepend.apply(this,arguments)}for(i=0,o=e.length;i<o;i++){n=e[i];this.words.splice(r,0,t.trim(n))}return this};n.prototype.replace=function(r,n){if(n==null){n=""}if(""===(n=t.trim(n))){return this}if(s.isNumber(r)){this.applyToValidIndex(r,function(t){return function(r){return t.words.splice(r,1,n)}}(this))}else{this.xs(function(t){if(t===r){return n}return true})}return this};return n}(r);n.prototype.unshift=n.prototype.prepend;if(typeof window!=="undefined"&&window!==null){return window.Words}if(module){return module.exports=n}}).call(this);
(function(){"use strict";var t,r,n,e,s,i,o,u,h,f,p=[].slice,c={}.hasOwnProperty,l=function(t,r){function n(){this.constructor=t}for(var e in r)c.call(r,e)&&(t[e]=r[e]);return n.prototype=r.prototype,t.prototype=new n,t.__super__=r.prototype,t};return r=t=f=require("strings.js"),h=function(t){var r,n,e,s;for(n=t.length-1,e=[],r=s=n;0>=n?0>=s:s>=0;r=0>=n?++s:--s)e[e.length-1]!==t[r]&&e.push(t[r]);return e},o=function(t){var r,n,e,s,i;for(e=t.length-1,n=i=1;e>=1?e>=i:i>=e;n=e>=1?++i:--i){for(r=t[n],s=n-1;s>=0&&t[s]>r;)t[s+1]=t[s],--s;t[+s+1]=r}return t},u=function(t){var r,n,e;r=[];for(e in t)n=t[e],r.push(n);return r},s=function(r,n){var e,s,i,o,u,h,c,l,a;if(f.isString(null!=n?n[0]:void 0))return this.set(t[r].apply(t,[this.$].concat(p.call(n))));if(0===(null!=n?n[0]:void 0)){for(c=[],i=0,u=n.length;u>i;i++)s=n[i],c.push(function(){var n,i,o;for(o=[],e=n=0,i=this.count-1;i>=0?i>=n:n>=i;e=i>=0?++n:--n)o.push(this.words[e]=t[r](this.words[e],s));return o}.call(this));return c}for(n.length<1&&(n=function(){l=[];for(var t=0,r=this.count;r>=0?r>=t:t>=r;r>=0?t++:t--)l.push(t);return l}.apply(this)),a=[],o=0,h=n.length;h>o;o++)s=n[o],s=f.positiveIndex(s,this.count),a.push(this.words[s]=t[r](this.words[s]));return a},e=function(){return function(t,r,n){var e;return!1!==(e=f.positiveIndex(t,r))?n(e):void 0}}(this),i=" ",n=function(r){function n(){Object.defineProperty(this,"$",{get:function(){return this.get()}}),Object.defineProperty(this,"string",{get:function(){return this.get()}}),Object.defineProperty(this,"count",{get:function(){return this.words.length}}),this.set.apply(this,arguments)}return l(n,r),n.prototype.set=function(){var r,n,e,s,o,u,h;if(arguments.length<1)return this;for(this.words=[],e=0,o=arguments.length;o>e;e++)for(r=arguments[e],h=t.split(t.create(r),i),s=0,u=h.length;u>s;s++)n=h[s],this.words.push(n);return this},n.prototype.get=function(){var r,n,e,s;if(arguments.length<1)return this.words.join(i);for(n="",e=0,s=arguments.length;s>e;e++)r=arguments[e],r=f.positiveIndex(r,this.count),r!==!1&&(n+=this.words[r]+i);return t.trim(n)},n.prototype.xs=function(t){var r,n,e,s,i,o,u;if(null==t&&(t=function(){return!0}),!(f.notFunction(t)||this.count<1)){for(e=[],u=this.words,r=i=0,o=u.length;o>i;r=++i)s=u[r],(n=t(s,r))&&(n===!0?e.push(s):f.isStringOrNumber(n)&&e.push(n+""));return this.words=e,this}},n.prototype.find=function(t){var r;return r=[],""!==(t=f.forceString(t))&&this.xs(function(n,e){return n===t&&r.push(e+1),!0}),r},n.prototype.upper=function(){return s.call(this,"upper",Array.prototype.slice.call(arguments)),this},n.prototype.lower=function(){return s.call(this,"lower",Array.prototype.slice.call(arguments)),this},n.prototype.reverse=function(){var r,n,s;if(console.log("from words: ",arguments),0===(null!=arguments?arguments[0]:void 0))this.xs(function(r){return t.reverse(r)});else if(arguments.length>0)for(n=0,s=arguments.length;s>n;n++)r=arguments[n],e(r,this.count,function(r){return function(n){return r.words[n]=t.reverse(r.words[n])}}(this));else this.set(t.reverse(this.$));return this},n.prototype.shuffle=function(r){var n,s,i,o,u;if(null!=r)if(f.isString(r))for(s=0,o=arguments.length;o>s;s++)n=arguments[s],this.xs(function(){return function(r){return r===n?t.shuffle(r):!0}}(this));else if(0===r)this.xs(function(r){return t.shuffle(r)});else for(i=0,u=arguments.length;u>i;i++)n=arguments[i],e(n,this.count,function(r){return function(n){return r.words[n]=t.shuffle(r.words[n])}}(this));else this.words=f.shuffleArray(this.words);return this},n.prototype.clear=function(){return this.words=[],this},n.prototype.remove=function(){var t,r,e,s,i,u,p;if(arguments.length<1)return this;for(r=[],s=0,u=arguments.length;u>s;s++)t=arguments[s],f.isString(t)?r.unshift(t):f.isNumber(t)&&r.push(n.positiveIndex(t,this.count));for(r=h(o(r)),e=i=0,p=r.length;p>i;e=++i)t=r[e],f.isNumber(t)?this.xs(function(){return function(r,n){return n!==t?!0:void 0}}(this)):f.isString(t)&&this.xs(function(r){return r!==t?!0:void 0});return this},n.prototype.pop=function(t){var r,n;for(t=f.forceNumber(t,1),r=n=1;t>=1?t>=n:n>=t;r=t>=1?++n:--n)this.words.pop();return this},n.prototype.push=function(){var r,n,e;for(n=0,e=arguments.length;e>n;n++)r=arguments[n],""!==(r=f.forceString(r))&&this.words.push(t.trim(r));return this},n.prototype.shift=function(t){var r,n;for(t=f.forceNumber(t,1),r=n=1;t>=1?t>=n:n>=t;r=t>=1?++n:--n)this.words.shift();return this},n.prototype.prepend=function(){var r,n,e;for(n=0,e=arguments.length;e>n;n++)r=arguments[n],""!==(r=f.forceString(r))&&this.words.unshift(t.trim(r));return this},n.prototype.insert=function(){var r,n,e,s,i,o;for(n=arguments[0],s=2<=arguments.length?p.call(arguments,1):[],n=f.positiveIndex(n,this.count),r=i=0,o=s.length;o>i;r=++i)e=s[r],""!==(e=f.forceString(e))&&this.words.splice(n+r,0,t.trim(e));return this},n.prototype.replace=function(r,n){return null==n&&(n=""),""===(n=t.trim(n))?this:(f.isNumber(r)?e(r,this.count,function(t){return function(r){return t.words.splice(r,1,n)}}(this)):this.xs(function(t){return t===r?n:!0}),this)},n.prototype.sort=function(){return o(this.words),this},n}(r),n.prototype.unshift=n.prototype.prepend,n.Strings=r,n.Types=r.Types,n.Chars=r.Chars,"undefined"!=typeof window&&null!==window?window.Words:module?module.exports=n:void 0}).call(this);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc