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

busca-br

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

busca-br - npm Package Compare versions

Comparing version 0.1.7 to 0.2.0

.npmignore

138

buscaBR.js

@@ -1,79 +0,95 @@

function buscaBR(){
(function() {
"use strict";
}
var buscaBR = {};
// Exporta o objeto do buscaBR para o **Node.js**
// com a compatibilidade para o browser definindo
// buscaBR como um objeto global
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = buscaBR;
}
exports.buscaBR = buscaBR;
} else {
window.buscaBR = buscaBR;
}
buscaBR.prototype.searchSync = function(str, array){
var results = [];
for(var i = 0 ; i < array.length; i++){
if(this.encode(str) == this.encode(array[i])){
results.push({termo:array[i], index: i})
}
}
return (results.length>0) ? results : {erro:"Não há registros"};
}
var codes = [
[/BL|BR/, 'B'],
['PH', 'F'],
[/GL|GR|MG|NG|RG/, 'G'],
['Y', 'I'],
[/GE|GI|RJ|MJ/, 'J'],
[/CA|CO|CU|CK|Q/, 'K'],
['N', 'M'],
[/AO|AUM|GM|MD|OM|ON/, 'M'],
['PR', 'P'],
['L', 'R'],
[/CE|CI|CH|CS|RS|TS|X|Z/, 'S'],
[/TR|TL/, 'T'],
[/CT|RT|ST|PT/, 'T'],
[/\b[UW]/, 'V'],
['RM', 'SM'],
[/[MRS]+\b/, ''],
[/[AEIOUH]/, '']
];
buscaBR.prototype.search = function(str, array, callback){
callback(this.searchSync(str, array));
}
buscaBR.searchSync = function(str, array){
var results = [];
for(var i = 0 ; i < array.length; i++){
if(this.encode(str) == this.encode(array[i])){
results.push({termo:array[i], index: i})
}
}
return (results.length>0) ? results : {erro:"Não há registros"};
};
buscaBR.prototype.encode = function(str){
str = removeAcento(str.toUpperCase());
var codes = [ [/BL|BR/, 'B'],
['PH', 'F'],
[/GL|GR|MG|NG|RG/, 'G'],
['Y', 'I'],
[/GE|GI|RJ|MJ/, 'J'],
[/CA|CO|CU|CK|Q/, 'K'],
['N', 'M'],
[/AO|AUM|GM|MD|OM|ON/, 'M'],
['PR', 'P'],
['L', 'R'],
[/CE|CI|CH|CS|RS|TS|X|Z/, 'S'],
[/TR|TL/, 'T'],
[/CT|RT|ST|PT/, 'T'],
[/\b[UW]/, 'V'],
['RM', 'SM'],
[/[MRS]+\b/, ''],
[/[AEIOUH]/, ''] ];
for(var i = 0; i < codes.length; i++){
// str = str.replace(this.codes[i][0],this.codes[i][1]);
str = str.split(codes[i][0]).join(codes[i][1])
}
str = squeeze(str);
buscaBR.search = function(str, array, callback){
callback(this.searchSync(str, array));
};
return str;
}
buscaBR.encode = function (str) {
str = removeAcento(str.toUpperCase());
for(var i = 0; i < codes.length; i++){
// str = str.replace(this.codes[i][0],this.codes[i][1]);
str = str.split(codes[i][0]).join(codes[i][1])
}
function squeeze(str){
var cont = 0;
var newString='';
for(var i = 0 ; i < str.length; i++){
if(str[i] != str[i+1]){
newString +=str[i];
}
}
return newString;
}
str = squeeze(str);
return str;
};
function removeAcento(strToReplace) {
str_acento = "ÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ";
str_sem_acento = "AAAAAEEEEIIIIOOOOOUUUUC";
function squeeze(str){
var cont = 0;
var newString='';
for(var i = 0 ; i < str.length; i++){
if(str[i] != str[i+1]){
newString +=str[i];
}
}
return newString;
}
function removeAcento(strToReplace) {
var str_acento = "ÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ";
var str_sem_acento = "AAAAAEEEEIIIIOOOOOUUUUC";
var nova = "";
for (var i = 0; i < strToReplace.length; i++) {
if (str_acento.indexOf(strToReplace.charAt(i)) != -1) {
nova += str_sem_acento.substr(str_acento.search(strToReplace.substr(i, 1)), 1);
} else {
nova += strToReplace.substr(i, 1);
}
if (str_acento.indexOf(strToReplace.charAt(i)) != -1) {
nova += str_sem_acento.substr(str_acento.search(strToReplace.substr(i, 1)), 1);
} else {
nova += strToReplace.substr(i, 1);
}
}
var nova = nova.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '');
return nova;
}
}
module.exports = new buscaBR();
}());
{
"name": "busca-br",
"description": "Modulo para usar o algoritmo buscaBR em javascript/node.js ",
"readmeFilename": "README.md" ,
"readmeFilename": "README.md",
"keywords": [

@@ -11,9 +11,7 @@ "busca",

"tags": [
"sqlite",
"sqlite3",
"sync",
"async",
"database"
"busca",
"fonetica",
"buscaBR"
],
"version": "0.1.7",
"version": "0.2.0",
"author": {

@@ -28,5 +26,6 @@ "name": "Jayr Alencar",

},
"dependencies":{
"dependencies": {},
"scripts": {
"test": "node test/test.js"
},
"scripts": { "test": "node test/test.js" },
"license": "MIT",

@@ -36,3 +35,7 @@ "engines": {

},
"main": "buscaBR.js"
}
"main": "buscaBR.js",
"devDependencies": {
"mocha": "^2.4.5",
"chai": "^3.5.0"
}
}

@@ -36,3 +36,2 @@ # buscaBR.js

<script>
var buscabr = new buscaBR();
buscaBR.search('feijaum',['arroz','feijão','feijoada'],function(res){

@@ -46,3 +45,2 @@ alert(res[0].termo);

```js
var buscabr = new buscaBR();
var resultado = buscabr.searchSync('feijaum',['arroz','feijão','feijoada']);

@@ -57,3 +55,2 @@ console.log(resultado);

console.log(buscabr('paralalepipedo'));
//Vai retornar
```

@@ -63,4 +60,3 @@

```js
var buscabr = new buscaBR();
alert(buscabr.encode('paralalepipedo'))
alert(buscaBR.encode('paralalepipedo'))
```

@@ -67,0 +63,0 @@

@@ -1,7 +0,21 @@

var buscaBR = require('../buscaBR');
const expect = require('chai').expect;
const buscaBR = require('../buscaBR');
buscaBR.search('feijaum',['arroz','feijão','feijoada'],function(res){
console.log(res);
describe('Busca BR', function() {
describe("Buscar", function() {
it("Nome errado", function(done) {
buscaBR.search('feijaum',['arroz','feijão','feijoada'],function(res){
expect(res).with.length(1);
expect(res[0]).to.have.property('termo').with.equal("feijão");
expect(res[0]).to.have.property('index').with.equal(1);
done();
});
});
});
describe("Encode", function() {
it("Nome com acentos", function() {
expect(buscaBR.encode('Feijão')).to.equal('FJ');
});
});
});
console.log(buscaBR.encode('Feijão'));
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