Huge News!Announcing our $40M Series B led by Abstract Ventures.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.2.6 to 0.2.7

4

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

@@ -30,5 +30,5 @@ "main": "words.min.js",

"dependencies": {
"strings.js" : "1.1.6"
"strings.js" : "1.1.9"
},
"devDependencies": {}
}
words.js
========
words.js is all about finding/manipulating/sorting/adding/removing words in or from a string.
Only 5.5Kb minified (depends on strings.js), words.js is a toolbox for words from a space seperated string.
Great for text input or command-line parsing, educational tools, word-games, text filters, password generators, etc..
<br/>
<br/>
words.js extends strings.js. Most methods overload strings.js methods, only to focus on words rather than characters.
**a few quick examples:**
```javascript
var words= new Words('pick the words you need with indices');
console.log( words.get(1, 3, -2, 3) );
// pick words with words
words.set('you can be very specific with upper and lowercase')
.upper(-1, -3, 'y', 'specific')
console.log( words.$ );
// You can be verY SPECIFIC with UPPER and LOWERCASE
words.set('you can reverse all word positions').upper(3).reverse();
console.log( words.$ );
// positions word all REVERSE can you
words.set('or reverse or remove specific words and sort?')
.reverse(2, -1).remove('or', 'remove').sort();
console.log( words.$ );
// ?tros and esrever specific words
words.set('noticed you can remove indices and words mixed?')
.remove('noticed', -2, -4, 'and');
console.log( words.$ );
// you can remove mixed?
words.set('or shuffle specific words').shuffle(2, 3);
console.log( words.$ );
// or seuhlff fiiespcc words (pseudo random)
words.set('Words.startsWith searches for matching words');
console.log( words.startsWith('Words.') );
// false
console.log( words.startsWith('Words.startsWith searches') );
// true
// more examples below in the API
```
__________________________________
words.js depends on, and 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

@@ -15,6 +54,6 @@ shuffle function randomly reorders the words in a string, or you can shuffle the characters of a specific word in

The `new Words()` object is made for chaining operations on words in strings, most of it's methods return their
words.js is made for chaining operations on words in strings, most of it's methods return their
own context. To return the actual value of the internal string/array, one can use `.get()` or `.$` or `.string`.
___
You can use `npm install words.js` when using node.js. The dependant strings.js and included types.js will
You can use `npm install words.js` when using node.js. The dependent strings.js and included types.js will
automatically be installed as well.

@@ -154,12 +193,13 @@ <br/>

**Words.prototype.upper**
> `<this> upper( <string>/<number> index, <string>/<number> position )`
> `<this> upper( <string>/<number> value, [value1, ..., valueN] )`
> Change words or characters in words to uppercase. If no arguments are given, all words are changed to uppercase.
> 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.
> (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.
```javascript
var words= new Words('you can be very specific with upper and lowercase');
console.log( words.upper(-1, -3).$ );
// you can be very specific with UPPER and LOWERCASE
console.log( words.upper(-1, -3, 'y', 'specific').$ );
// You can be verY SPECIFIC with UPPER and LOWERCASE

@@ -176,3 +216,3 @@ var words= new Words('you can be very specific with upper and lowercase');

**Words.prototype.lower**
> `<this> lower( <string>/<number> index, <string>/<number> position )`
> `<this> lower( <string>/<number> value, [value1, ..., valueN] )`

@@ -351,6 +391,16 @@ > The same as with .upper(), except for that uppercase characters are changed to lowercase.

**0.2.7**
Words.upper and Words.lower now accept multiple indices and/or words as mixed arguments.
```javascript
var words= new Words('you can upper or lower with indices and words mixed');
console.log( words.upper('can', 0, 1, 'indices', 'words') );
// [ 'You', 'CAN', 'Upper', 'Or', 'Lower', 'With', 'INDICES', 'And', 'WORDS', 'Mixed' ]
```
_______________________________
**0.2.4**
Updated strings.js dependency to version 1.1.6, which includes types.js version 1.3.4.
_______________________________
**0.2.0**

@@ -368,4 +418,3 @@

Don't mind the version please, as for every typo in the readme I have to bump the version for npm..
________________________________
**0.1.2**

@@ -372,0 +421,0 @@

// Generated by CoffeeScript 1.8.0
(function() {
"use strict";
var Str, Strings, Words, applyToValidIndex, changeCase, delimiter, insertSort, removeDupAndFlip, _,
var Str, Strings, Words, applyToValidIndex, changeCase, delimiter, numbersFromArray, stringsFromArray, _,
__slice = [].slice,

@@ -11,37 +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]);
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);
}
}
return newArr;
return strings;
};
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;
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);
}
array[+prev + 1] = current;
}
return array;
return numbers;
};
changeCase = function(method, args) {
var index, pos, _i, _j, _k, _len, _len1, _ref, _results, _results1, _results2;
if (_.isString(args != null ? args[0] : void 0)) {
return this.set(Str[method].apply(Str, [this.$].concat(__slice.call(args))));
} else if ((args != null ? args[0] : void 0) === 0) {
var index, indices, pos, words, _i, _j, _k, _len, _len1, _ref, _results, _results1, _results2;
words = stringsFromArray(args);
indices = 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 = args.length; _i < _len; _i++) {
pos = args[_i];
for (_i = 0, _len = indices.length; _i < _len; _i++) {
pos = indices[_i];
_results.push((function() {

@@ -59,3 +61,3 @@ var _j, _ref, _results1;

if (args.length < 1) {
args = (function() {
indices = (function() {
_results1 = [];

@@ -67,6 +69,6 @@ for (var _j = 0, _ref = this.count; 0 <= _ref ? _j <= _ref : _j >= _ref; 0 <= _ref ? _j++ : _j--){ _results1.push(_j); }

_results2 = [];
for (_k = 0, _len1 = args.length; _k < _len1; _k++) {
pos = args[_k];
pos = _.positiveIndex(pos, this.count);
_results2.push(this.words[pos] = Str[method](this.words[pos]));
for (_k = 0, _len1 = indices.length; _k < _len1; _k++) {
index = indices[_k];
index = _.positiveIndex(index, this.count);
_results2.push(this.words[index] = Str[method](this.words[index]));
}

@@ -257,3 +259,3 @@ return _results2;

}
args = removeDupAndFlip(insertSort(args));
args = _.noDupAndReverse(_.insertSort(args));
for (index = _j = 0, _len1 = args.length; _j < _len1; index = ++_j) {

@@ -358,3 +360,3 @@ arg = args[index];

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

@@ -361,0 +363,0 @@ };

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

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

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