Comparing version 0.1.6 to 0.1.7
{ | ||
"name": "words.js", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "A flexible, robust and powerful Javascript word-string manipulation library.", | ||
@@ -5,0 +5,0 @@ "main": "words.min.js", |
136
README.md
@@ -60,2 +60,8 @@ words.js | ||
```javascript | ||
var words= new Words('word counting included'); | ||
console.log( words.count ); | ||
// 3 | ||
``` | ||
**Words.prototype.set** | ||
@@ -80,5 +86,5 @@ > `<this> set( <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.. | ||
var words= new Words('we can be very specific and pick any word we need'); | ||
words.get( 5, -1 ); | ||
// specific need | ||
``` | ||
@@ -90,2 +96,8 @@ **Words.prototype.$** | ||
```javascript | ||
var words= new Words('fetch the whole string with a getter'); | ||
console.log( words.$ ); | ||
// fetch the whole string with a getter | ||
``` | ||
**Words.prototype.string** | ||
@@ -107,14 +119,18 @@ > `string` | ||
```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 ).$; | ||
var words= new Words('access all words and do whatever you like with them'); | ||
words.xs( function(word, index){ | ||
if( word.length < 4 ) | ||
return true; | ||
}); | ||
// 123 not are | ||
console.log( words.$ ); | ||
// all and do you | ||
var max3= words.xs( function(word, index){ | ||
if( word === '123' ) | ||
return '*'+ word+ '*' | ||
else return true | ||
var words= new Words('or mark words in a string'); | ||
words.xs( function(word, index){ | ||
if( word === 'mark' ) | ||
return '*marked*'; | ||
return true; | ||
}); | ||
// numbers accepted *123* not objects, arrays etc.. they are simply ignored.. | ||
console.log( words.$ ); | ||
// or *marked* words in a string | ||
``` | ||
@@ -128,7 +144,5 @@ | ||
```javascript | ||
words.set( 'numbers accepted', 123, 'not objects, arrays etc..', {}, [1,2,3], 'they are simply ignored..' ); | ||
words.find( 'hello' ); | ||
// [] | ||
words.find( 'accepted' ); | ||
// [2] | ||
var words= new Words('finding words with words is easy!'); | ||
console.log( words.find('words') ); | ||
// [2, 4] | ||
``` | ||
@@ -144,10 +158,13 @@ | ||
```javascript | ||
words.set( 'numbers accepted', 123, 'not objects, arrays etc..', {}, [1,2,3], 'they are simply ignored..' ); | ||
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 | ||
var words= new Words('you can be very specific with upper and lowercase'); | ||
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.. | ||
// YoU CaN BE VerY SpecifiC WitH UppeR AnD LowercasE | ||
var words= new Words('shout it all out!'); | ||
console.log( words.upper().$ ); | ||
// NUMBERS ACCEPTED 123 NOT OBJECTS, ARRAYS ETC.. THEY ARE SIMPLY IGNORED.. | ||
// SHOUT IT ALL OUT! | ||
``` | ||
@@ -168,13 +185,13 @@ | ||
```javascript | ||
words.set( 'numbers accepted', 123, 'not objects, arrays etc..', {}, [1,2,3], 'they are simply ignored..' ); | ||
var words= new Words('reverse this whole string'); | ||
console.log( words.reverse().$ ); | ||
//..derongi ylpmis era yeht ..cte syarra ,stcejbo ton 321 detpecca srebmun | ||
// gnirts elohw siht esrever | ||
words.set( 'numbers accepted', 123, 'not objects, arrays etc..', {}, [1,2,3], 'they are simply ignored..' ); | ||
var words= new Words('words are reversed in place when 0 is given'); | ||
console.log( words.reverse(0).$ ); | ||
// srebmun detpecca 321 ton ,stcejbo syarra ..cte yeht era ylpmis ..derongi | ||
// sdrow era desrever ni ecalp nehw 0 si nevig | ||
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.. | ||
var words= new Words('any reason to reverse a specific word?'); | ||
console.log( words.reverse(1, -1, -2).$ ); | ||
// yna reason to reverse a cificeps ?drow | ||
``` | ||
@@ -190,18 +207,15 @@ | ||
```javascript | ||
words.set( 'numbers accepted', 123, 'not objects, arrays etc..', {}, [1,2,3], 'they are simply ignored..' ); | ||
// pseudo random, it should be extremely rare to see the same results on any run! | ||
var words= new Words('let\'s mess up this sentence'); | ||
console.log( words.shuffle().$ ); | ||
// without arguments all words positions are pseudo randomly shuffled: | ||
// they numbers accepted not objects, etc.. ignored.. arrays are simply 123 | ||
// sentence let's up mess this | ||
var words= new Words('or mess it up totally in place'); | ||
console.log( words.shuffle(0).$ ); | ||
// ro esms it up ltlotay ni eclpa | ||
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 | ||
var words= new Words('let\'s shuffle some specific words'); | ||
console.log( words.shuffle(2, -1).$ ); | ||
// let's efsfluh some specific srowd | ||
``` | ||
@@ -221,5 +235,5 @@ | ||
```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 | ||
var words= new Words('removing specific words is very easy'); | ||
console.log( words.remove(2, 3, -2).$ ); | ||
// removing is easy | ||
``` | ||
@@ -234,5 +248,5 @@ | ||
```javascript | ||
var words= new Words( 'testing words is real fun!' ); | ||
console.log( words.pop(3) ); | ||
// testing words | ||
var words= new Words( 'pop means: remove words from the end of this string' ); | ||
console.log( words.pop(3).$ ); | ||
// pop means: remove words from the end | ||
``` | ||
@@ -246,5 +260,5 @@ | ||
```javascript | ||
var words= new Words( 'testing words' ); | ||
console.log( words.push( 'before', 'usage' ).$ ); | ||
// testing words before usage | ||
var words= new Words( 'push means: add to the end of this' ); | ||
console.log( words.push( 'string' ).$ ); | ||
// push means: add to the end of this string | ||
``` | ||
@@ -260,5 +274,5 @@ | ||
```javascript | ||
var words= new Words( 'serious testing of words is fun!' ); | ||
console.log( words.shift(3).$ ); | ||
// words is fun! | ||
var words= new Words( 'shift means: remove words from the start' ); | ||
console.log( words.shift(2).$ ); | ||
// remove words from the start | ||
``` | ||
@@ -272,5 +286,5 @@ | ||
```javascript | ||
var words= new Words( 'words is fun!' ); | ||
console.log( words.unshift('serious', 'testing', 'of').$ ); | ||
// serious testing of words is fun! | ||
var words= new Words( 'adding words to the start of a string' ); | ||
console.log( words.unshift('unshift', 'means:').$ ); | ||
// unshift means: adding words to the start of a string | ||
``` | ||
@@ -284,5 +298,5 @@ | ||
```javascript | ||
var words= new Words( 'testing words' ); | ||
console.log( words.insert( -1, 'some', 'silly' ).$ ); | ||
// testing some silly words | ||
var words= new Words( 'insert a word in this string' ); | ||
console.log( words.insert( 3, 'specific' ).$ ); | ||
// insert a specific word in this string | ||
``` | ||
@@ -289,0 +303,0 @@ |
13
words.js
// Generated by CoffeeScript 1.8.0 | ||
(function() { | ||
"use strict"; | ||
var Str, Strings, Words, applyToValidIndex, changeCase, delimiter, insertSort, objectToArray, removeDupAndFlip, _, | ||
var Str, Strings, Words, applyToValidIndex, changeCase, delimiter, insertSort, removeDupAndFlip, _, | ||
__slice = [].slice, | ||
@@ -38,12 +38,2 @@ __hasProp = {}.hasOwnProperty, | ||
objectToArray = function(object) { | ||
var array, data, key; | ||
array = []; | ||
for (key in object) { | ||
data = object[key]; | ||
array.push(data); | ||
} | ||
return array; | ||
}; | ||
changeCase = function(method, args) { | ||
@@ -203,3 +193,2 @@ var index, pos, _i, _j, _k, _len, _len1, _ref, _results, _results1, _results2; | ||
var arg, _i, _len; | ||
console.log('from words: ', arguments); | ||
if ((arguments != null ? arguments[0] : void 0) === 0) { | ||
@@ -206,0 +195,0 @@ this.xs(function(word) { |
@@ -1,1 +0,1 @@ | ||
(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,s;for(n=e=0,s=arguments.length;s>e;n=++e)r=arguments[n],""!==(r=f.forceString(r))&&this.words.splice(n,0,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); | ||
(function(){"use strict";var t,r,n,e,s,i,o,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,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},s=function(r,n){var e,s,i,o,u,p,c,l,a;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++)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,p=n.length;p>o;o++)s=n[o],s=h.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=h.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 c(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=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,s,i,o,u;if(null==t&&(t=function(){return!0}),!(h.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):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 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(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(h.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=h.shuffleArray(this.words);return this},n.prototype.clear=function(){return this.words=[],this},n.prototype.remove=function(){var t,r,e,s,i,f,p;if(arguments.length<1)return this;for(r=[],s=0,f=arguments.length;f>s;s++)t=arguments[s],h.isString(t)?r.unshift(t):h.isNumber(t)&&r.push(n.positiveIndex(t,this.count));for(r=u(o(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,s;for(n=e=0,s=arguments.length;s>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,s,i,o;for(n=arguments[0],s=2<=arguments.length?f.call(arguments,1):[],n=h.positiveIndex(n,this.count),r=i=0,o=s.length;o>i;r=++i)e=s[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 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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
334
33942
355