Comparing version 0.0.0 to 1.0.0
114
index.js
'use strict'; | ||
/*! | ||
* acany | ||
* boladao | ||
* Copyright (c) 2016 heyderpd <heyderpd@gmail.com> | ||
@@ -9,88 +9,58 @@ * MIT Licensed | ||
var middle = function middle(word) { | ||
return '*' + word + '*'; | ||
}; | ||
var _require = require('pytils'); | ||
var ___ASTERISK___ = String.fromCharCode(254); | ||
var length = _require.length; | ||
var searchSimple = function searchSimple(word) { | ||
return middle(word.replace('*', '\\*').replace(/\ +/gim, '**')); | ||
var DICT = require('dictany'); | ||
var tendentious = require('random-tendentious'); | ||
var keys = { | ||
first: ['verbo', 'normal', 'pouco', 'muito'], | ||
second: ['eu', 'nos'] | ||
}; | ||
var searchComplex = function searchComplex(word) { | ||
return middle(word.replace('*', ___ASTERISK___).replace(/\ +/gim, '').split('').join('**').replace(___ASTERISK___, '\\*')); | ||
var randomFirst = function randomFirst() { | ||
return Math.floor(tendentious({ | ||
f: Math.random, | ||
l: [1, length(keys.first) + 1.5] })()); | ||
}; | ||
var findAnyMatch = function findAnyMatch(anyneed, setList, limit) { | ||
if (limit <= 0) return []; | ||
var randomSecond = function randomSecond() { | ||
return Math.floor(tendentious({ | ||
f: Math.random, | ||
l: [1, length(keys.second) + 1.5] })()); | ||
}; | ||
var list = copy(setList); | ||
var found = {}; | ||
var foundCount = 0; | ||
var ref = void 0; | ||
while (foundCount < limit && length(list) > 0) { | ||
var item = list.shift(); | ||
if ((ref = anymatch(anyneed, item, true)) >= 0) { | ||
if (!hasProp(found, ref)) { | ||
found[ref] = []; | ||
} | ||
found[ref].push(item); | ||
foundCount++; | ||
} | ||
} | ||
return found; | ||
var getWords = function getWords(level, position) { | ||
return keys[level][position]; | ||
}; | ||
var concatResult = function concatResult(results) { | ||
var found = []; | ||
eachVal(results, function (maths) { | ||
if (length(maths) > 0) { | ||
eachVal(maths, function (item) { | ||
found.push(item); | ||
}); | ||
} | ||
}); | ||
return found; | ||
var getSeed = function getSeed() { | ||
return [getWords('second', randomSecond()), getWords('first', randomFirst())].join(' '); | ||
}; | ||
var doSearch = function doSearch(need, list, limit) { | ||
var anyneed = [need, searchSimple(need), searchComplex(need)]; | ||
var DicionarioBoladao = DICT({ | ||
'*verbo*': 'bolar', | ||
'*normal*': DICT({ | ||
'*eu*': 'bolado', | ||
'*nos*': 'bolados', | ||
'DEFAULT': 'bolando?' | ||
}), | ||
'*pouco*': DICT({ | ||
'*eu*': 'boladinho', | ||
'*nos*': 'boladinhos', | ||
'DEFAULT': 'bolacha?' | ||
}), | ||
'*muito*': DICT({ | ||
'*eu*': 'boladão', | ||
'*nos*': 'boladões', | ||
'DEFAULT': 'biscoito?' | ||
}), | ||
'DEFAULT': 'boladamente?' | ||
}); | ||
var found = findAnyMatch(anyneed, copy(list), limit); | ||
return concatResult(found); | ||
}; | ||
var main = function main() { | ||
var setNeed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined; | ||
var setList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
var setLimit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10; | ||
var list = isArray(setList) && length(setList) > 0 ? copy(setList) : undefined; | ||
if (list === undefined) throw new Error("var 'list' have a invalid value"); | ||
var need = isString(setNeed) ? setNeed : undefined; | ||
if (need === undefined) throw new Error("var 'need' have a invalid value"); | ||
if (length(need) <= 0) return setList; | ||
var limit = isNumber(setLimit) && setLimit > 0 ? setLimit : undefined; | ||
if (limit === undefined) throw new Error("var 'limit' have a invalid value"); | ||
return doSearch(need, list, limit); | ||
return DicionarioBoladao(getSeed()); | ||
}; | ||
var _require = require('pytils'); | ||
var isNumber = _require.isNumber; | ||
var isString = _require.isString; | ||
var isArray = _require.isArray; | ||
var length = _require.length; | ||
var copy = _require.copy; | ||
var eachVal = _require.eachVal; | ||
var arrayDiff = _require.arrayDiff; | ||
var hasProp = _require.hasProp; | ||
var anymatch = require('anymatch'); | ||
module.exports = main; |
{ | ||
"license": "MIT", | ||
"name": "boladao", | ||
"version": "0.0.0", | ||
"description": "boladao", | ||
"version": "1.0.0", | ||
"description": "heyder boladao", | ||
"main": "index.js", | ||
"scripts": {}, | ||
"keywords": [ | ||
"heyder", | ||
"boladao" | ||
@@ -20,3 +21,6 @@ ], | ||
"devDependencies": {}, | ||
"dependencies": {} | ||
"dependencies": { | ||
"dictany": "^1.1.0", | ||
"random-tendentious": "^1.0.2" | ||
} | ||
} |
@@ -1,42 +0,7 @@ | ||
# acany : simple support to autocomplete. receve a list and a word | ||
# return a list math in sort of less diff, but this not sort your initial list | ||
# [Lucas](https://www.npmjs.com/~lucasmreis) say: Heyder Boladão | ||
## I will help if you have any difficulty =) | ||
Contact me by [github:heyderpd](https://github.com/heyderpd). I'll be glad to help you. | ||
## Thanks for [npm~lucasmreis](https://www.npmjs.com/~lucasmreis) | ||
```javascript | ||
npm install --save acany | ||
``` | ||
## Example: | ||
```javascript | ||
const acany = require('acany') | ||
const list = [ 'hot coffee', 'chocolate', 'hot coffee with chocolate', 'coffee' ] | ||
found = acany('coffee', list) | ||
// found = [ 'coffee', 'hot coffee', 'hot coffee with chocolate' ] | ||
found = acany('hot coffee', list) | ||
// found = [ 'hot coffee', 'hot coffee with chocolate' ] | ||
found = acany('hot chocolate', list) | ||
// found = [ 'hot coffee with chocolate' ] | ||
``` | ||
## Full Example: | ||
```javascript | ||
// acany(_NEED_, _LIST_, _LIMIT_) | ||
const list = ['aaa', 'yxuu', 'abb', 'xbbc', 'xc', 'xx cc', 'bbc', 'ccc', 'xccc'] | ||
found = acany('xc', list) | ||
// found = [ 'xc', 'xccc', 'xbbc', 'xx cc' ] | ||
found = acany('x c', list) | ||
// found = [ 'xbbc', 'xc', 'xx cc', 'xccc' ] | ||
found = acany('x c', list, 2) | ||
// found = [ 'xbbc', 'xc' ] | ||
const boladao = require('boladao') | ||
console.log('=>', boladao()) | ||
``` |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
3140
2
53
8
+ Addeddictany@^1.1.0
+ Addedrandom-tendentious@^1.0.2
+ Addedanymatch@1.3.2(transitive)
+ Addedarr-diff@2.0.0(transitive)
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarray-unique@0.2.1(transitive)
+ Addedbraces@1.8.5(transitive)
+ Addeddictany@1.1.0(transitive)
+ Addedexpand-brackets@0.1.5(transitive)
+ Addedexpand-range@1.8.2(transitive)
+ Addedextglob@0.3.2(transitive)
+ Addedfilename-regex@2.0.1(transitive)
+ Addedfill-range@2.2.4(transitive)
+ Addedfor-in@1.0.2(transitive)
+ Addedfor-own@0.1.5(transitive)
+ Addedglob-base@0.3.0(transitive)
+ Addedglob-parent@2.0.0(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-dotfile@1.0.3(transitive)
+ Addedis-equal-shallow@0.1.3(transitive)
+ Addedis-extendable@0.1.1(transitive)
+ Addedis-extglob@1.0.0(transitive)
+ Addedis-glob@2.0.1(transitive)
+ Addedis-number@2.1.04.0.0(transitive)
+ Addedis-posix-bracket@0.1.1(transitive)
+ Addedis-primitive@2.0.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisobject@2.1.0(transitive)
+ Addedkind-of@3.2.26.0.3(transitive)
+ Addedmath-random@1.0.4(transitive)
+ Addedmicromatch@2.3.11(transitive)
+ Addednormalize-path@2.1.1(transitive)
+ Addedobject.omit@2.0.1(transitive)
+ Addedparse-glob@3.0.4(transitive)
+ Addedpreserve@0.2.0(transitive)
+ Addedpytils@0.16.2(transitive)
+ Addedrandom-tendentious@1.0.3(transitive)
+ Addedrandomatic@3.1.1(transitive)
+ Addedregex-cache@0.4.4(transitive)
+ Addedremove-trailing-separator@1.1.0(transitive)
+ Addedrepeat-element@1.1.4(transitive)
+ Addedrepeat-string@1.6.1(transitive)