function buildIndex (doc, projection) { let fields = projection.call(doc), search = [], pos = 0, positions = {}, inverse = {}, inv = 0 for (let key in fields) { let value = (fields[key]) ? fields[key] : '' let transliterated = unidecode(value) search.push(transliterated) positions[key] = pos for (let i in range(value.length)) { let part = value.substr(0,i) let part_t = unidecode(part) inverse[part_t.length+inv] = i + pos } pos += value.length inv += transliterated.length + 1 inverse[inv-1] = pos } search = search.join(' ').toLowerCase() return { search_strings: search, positions: positions, inverse: inverse } }
module.exports.createReplacer = function(tokens) { var replacers = []; for (var token in tokens) { var entry = {}; var f = unidecode(token); // normalize expanded entry.from = new RegExp("(\\W|^)"+f+"(\\W|$)", "gi"); // create regex obj for expanded entry.to = unidecode("$1"+tokens[token]+"$2"); // normalize abbrev replacers.push(entry); } return replacers; };
module.exports.npmString = function(string){ var sanitizedString = this.technical_name = string.toLowerCase(); sanitizedString = sanitizedString.split(' ').join('-'); sanitizedString = unidecode(sanitizedString); sanitizedString = sanitizedString.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, ''); return sanitizedString; }
this.cleanFilename = function (filename) { var cleanedFilename = unidecode(filename) .replace(/[^a-zA-Z0-9\-\.]/g, '') .replace(/_/g, '-') .replace(/ /g, '-'); return cleanedFilename; }
safeString: function (string, options) { options = options || {}; // Handle the £ symbol separately, since it needs to be removed before the unicode conversion. string = string.replace(/£/g, '-'); // Remove non ascii characters string = unidecode(string); // Replace URL reserved chars: `@:/?#[]!$&()*+,;=` as well as `\%<>|^~£"{}` and \` string = string.replace(/(\s|\.|@|:|\/|\?|#|\[|\]|!|\$|&|\(|\)|\*|\+|,|;|=|\\|%|<|>|\||\^|~|"|\{|\}|`|–|—)/g, '-') // Remove apostrophes .replace(/'/g, '') // Make the whole thing lowercase .toLowerCase(); // We do not need to make the following changes when importing data if (!_.has(options, 'importing') || !options.importing) { // Convert 2 or more dashes into a single dash string = string.replace(/-+/g, '-') // Remove trailing dash .replace(/-$/, '') // Remove any dashes at the beginning .replace(/^-/, ''); } // Handle whitespace at the beginning or end. string = string.trim(); return string; },
this.cleanString = function (inputString) { var cleanedString = unidecode(inputString .replace(/_/g, '-') .replace(/[^a-zA-Z0-9\-\.]/g, '')) .replace(/ /g,'-'); return cleanedString; }
function filterBadwords(unit, message, dictionaries) { // unidecode the message to get ASCCI message = unidecode(message); var wordHits = []; var status = "clean"; _.each(dictionaries.badwords, function(rxp, key) { // Test each word for a match if(message.match(rxp)) { wordHits.push(key); } }); if(wordHits.length === 0) { // No bad words are found return { message: message, status: status } } else { // nasty things are being said // Need to add ifcase so the production server doesn't log that much logger.warn('Ironbot badwords (' + unit.name + '): ' + wordHits.join()+"; original message: " + message); var badUnit = addUnitToList(unit); if(badUnit.funnyActive) { // Return random funny message instead of real message var keys = Object.keys(dictionaries.funnyRandom); message = dictionaries.funnyRandom[keys[~~(Math.random()*(keys.length))]]; } if(badUnit.counter >= warnCount) { // Warn unit switch(badUnit.counter){ case 5: // Implement lightwarn status = 'lightwarn'; break; case 6: // Implement serius warn status = 'warn'; break; case 7: // Implement kick or ban status = 'kick'; break; default: // Nothing break; } } logger.warn('Ironbot badwords (' + unit.name + '): ' + wordHits.join()+"; original message: " + message+ "; status: " + status); return { message: message, status: status } } }
generateSlug: function (Model, base, readOptions) { var slug, slugTryCount = 1, // Look for a post with a matching slug, append an incrementing number if so checkIfSlugExists = function (slugToFind) { var args = {slug: slugToFind}; //status is needed for posts if (readOptions && readOptions.status) { args.status = readOptions.status; } return Model.findOne(args, readOptions).then(function (found) { var trimSpace; if (!found) { return when.resolve(slugToFind); } slugTryCount += 1; // If this is the first time through, add the hyphen if (slugTryCount === 2) { slugToFind += '-'; } else { // Otherwise, trim the number off the end trimSpace = -(String(slugTryCount - 1).length); slugToFind = slugToFind.slice(0, trimSpace); } slugToFind += slugTryCount; return checkIfSlugExists(slugToFind); }); }; // Remove URL reserved chars: `:/?#[]@!$&'()*+,;=` as well as `\%<>|^~£"` slug = base.trim().replace(/[:\/\?#\[\]@!$&'()*+,;=\\%<>\|\^~£"]/g, '') // Replace dots and spaces with a dash .replace(/(\s|\.)/g, '-') // Convert 2 or more dashes into a single dash .replace(/-+/g, '-') // Make the whole thing lowercase .toLowerCase(); // Remove trailing hyphen slug = slug.charAt(slug.length - 1) === '-' ? slug.substr(0, slug.length - 1) : slug; // Remove non ascii characters slug = unidecode(slug); // Check the filtered slug doesn't match any of the reserved keywords slug = /^(ghost|ghost\-admin|admin|wp\-admin|wp\-login|dashboard|logout|login|signin|signup|signout|register|archive|archives|category|categories|tag|tags|page|pages|post|posts|user|users|rss)$/g .test(slug) ? slug + '-post' : slug; //if slug is empty after trimming use "post" if (!slug) { slug = 'post'; } // Test for duplicate slugs. return checkIfSlugExists(slug); }
module.exports.replaceToken = function(tokens, query) { var query = unidecode(query); var abbr = query; for (var i=0; i<tokens.length; i++) { var abbr = abbr.replace(tokens[i].from,tokens[i].to); } return abbr; }
var tags = json.feed.category ? json.feed.category.map(function(category, i) { var name = convertTag(category.term); tagIds[name] = i; return { id: i, name: name, slug: snakeCase(unidecode(name)), description: '' }; }): [];
function unidecodeString(value) { var isParamBad = _.str.isBlank(value); if (isParamBad) { return value; } var unidecodedValue = unidecode(value); return unidecodedValue; }
function getLowerCaseUnidecodedString(value) { var isParamBad = _.str.isBlank(value); if (isParamBad) { return value; } var lowerCaseValue = value.toLowerCase(); var unidecodedLowerCaseValue = unidecode(lowerCaseValue); return unidecodedLowerCaseValue; }
const sanitize = function(file, opts = {}) { const sanitized = unidecode(file) .replace(rxWhiteSpace, '_') .replace(rxRemove, '') .toLowerCase() .split('.'); const ext = sanitized.pop(); let name = sanitized.join(''); if (opts.limit) { name = name.substr(0, opts.limit); } return { name, ext } };
export function searchIn (collection, txt, filter) { if (!(collection instanceof Mongo.Collection)) throw new Error(`Passed param is not a Mongo Collection.`) if (searchIn.collections[collection._name] !== true) throw new Error("This collection is not registered in buildIndex") let normalized = unidecode(txt).toLowerCase() let query = normalized.split(' ').map((x) => { return { search_strings: new RegExp(x.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&")) } }) if (typeof filter !== "undefined" && filter !== null) query.push(filter) return collection.find({$and: query}, {limit : 10}).fetch() }
function slugify(str) { var out, re, i, l, stri; re = /[§\-=±!@#\$%\^&\*\(\)_\+`~\[\]{};'\\:\"\|,\./<>\?\s\u2010-\u28ff]/; str = str.toLowerCase() str = str.split(re); out = []; for (i = 0, l = str.length; i < l; i++) { stri = str[i]; if (stri) { out.push(stri); } } return unidecode(out.join('-')); }
'safeString': function (string) { string = string.trim(); // Remove non ascii characters string = unidecode(string); // Remove URL reserved chars: `:/?#[]@!$&'()*+,;=` as well as `\%<>|^~£"` string = string.replace(/[:\/\?#\[\]@!$&'()*+,;=\\%<>\|\^~£"]/g, '') // Replace dots and spaces with a dash .replace(/(\s|\.)/g, '-') // Convert 2 or more dashes into a single dash .replace(/-+/g, '-') // Make the whole thing lowercase .toLowerCase(); return string; },
function getPublisher (title, callback) { var translit_t = unidecode(title); var sql = `SELECT showcaseid, title, logoname, RIGHT(logoname, 3) AS extension, about, begindate, showcaseimg, logoandtitle FROM pubshowcase WHERE REPLACE(RTRIM(LTRIM(title)), ' ', '-') = :title OR REPLACE(RTRIM(LTRIM(altsearch1)), ' ', '-') = :title OR REPLACE(RTRIM(LTRIM(altsearch2)), ' ', '-') = :title OR REPLACE(RTRIM(LTRIM(altsearch3)), ' ', '-') = :title OR REPLACE(RTRIM(LTRIM(title)), ' ', '-') = :translit_t OR REPLACE(RTRIM(LTRIM(altsearch1)), ' ', '-') = :translit_t OR REPLACE(RTRIM(LTRIM(altsearch2)), ' ', '-') = :translit_t OR REPLACE(RTRIM(LTRIM(altsearch3)), ' ', '-') = :translit_t OR REPLACE(REPLACE(RTRIM(LTRIM(title)), ' ', ''), '-', '') = REPLACE(REPLACE(:title, ' ', ''), '-', '') OR REPLACE(REPLACE(RTRIM(LTRIM(altsearch1)), ' ', ''), '-', '') = REPLACE(REPLACE(:title, ' ', ''), '-', '') OR REPLACE(REPLACE(RTRIM(LTRIM(altsearch2)), ' ', ''), '-', '') = REPLACE(REPLACE(:title, ' ', ''), '-', '') OR REPLACE(REPLACE(RTRIM(LTRIM(altsearch3)), ' ', ''), '-', '') = REPLACE(REPLACE(:title, ' ', ''), '-', '') OR REPLACE(REPLACE(RTRIM(LTRIM(title)), ' ', ''), '-', '') = REPLACE(REPLACE(:translit_t, ' ', ''), '-', '') OR REPLACE(REPLACE(RTRIM(LTRIM(altsearch1)), ' ', ''), '-', '') = REPLACE(REPLACE(:translit_t, ' ', ''), '-', '') OR REPLACE(REPLACE(RTRIM(LTRIM(altsearch2)), ' ', ''), '-', '') = REPLACE(REPLACE(:translit_t, ' ', ''), '-', '') OR REPLACE(REPLACE(RTRIM(LTRIM(altsearch3)), ' ', ''), '-', '') = REPLACE(REPLACE(:translit_t, ' ', ''), '-', '')`; var params = { title: title, translit_t: translit_t }; photoeye .query(sql, { replacements: params }) .spread(function(results, metadata) { callback(results); }); }
function slugify(str, sep) { var out, re, i, l, stri; sep = (typeof sep !== 'undefined') ? sep : '-'; re = RegExp('[\x00-\x2f\x3a-\x60\x7b-\x7f]'); str = unidecode(str); str = str.toLowerCase() str = str.split(re); out = []; for (i = 0, l = str.length; i < l; i++) { stri = str[i]; if (stri) { out.push(stri); } } return out.join(sep); }
.spread(function(user, booked, failed, waiting_list) { // log and send confirmation email // prepare data for email var data = { booked:booked, waiting_list:waiting_list, totalPrice: _.sum(booked, "transaction_value"), payment_deadline: moment().add(14,'d').format("dddd, MMMM Do YYYY"), sampleID: booked.length>0?booked[0].id:123, payments: { } }; for (var i in booked) { var ticket = booked[i]; if (ticket.payment_method.name === "Cheque") { data.payments.cheque = true; } else if (ticket.payment_method.name === "College Bill") { data.payments.college_bill = true; } else if (ticket.payment_method.name === "Bank Transfer") { data.payments.bank_transfer = true; } } if (booked.length + waiting_list.length > 0) { // print to the log for fun console.log(user.name + " just made a booking - " + booked.length + " tickets" + (waiting_list.length>0?" (and " + waiting_list.length + " waiting list)":"") + " for a total of £" + data.totalPrice + ""); // send the user an email emailer.send("'" + unidecode(user.name) + "' <" + user.email + ">", "Emmanuel May Ball - Booking Confirmation", "bookConf.jade", data); } return { booked: booked, waiting_list:waiting_list, failed: failed, totalPrice: data.totalPrice, payment_deadline: data.payment_deadline }; });
var posts = json.feed.entry ? json.feed.entry.map(function(post, i) { var title = post.title['$t'].trim(), slug = snakeCase(unidecode(title)), html = post.content['$t'], markdown = tomd(html), published = Date.parse(post.published['$t']); // prevent duplicate slugs (suffix post index if slug exists) slug = slugs.indexOf(slug) === -1 ? slug : slug + i; slugs.push(slug); // grab a post's images and add to global images array (for download later) var postImages = markdown.match(/\[!\[]\((.*?)\)/); if (postImages !== null) { postImages.forEach(function(image){ images.push(image.replace('[![](', '').replace(/.(jpg|JPG|jpeg|JPEG|gif|GIF|png|PNG)\)/, '.$1')); }); } return extend({ id: i, title: title, slug: slug, markdown: markdown, html: html, image: null, featured: 0, page: 0, status: 'published', language: 'en_US', 'meta_title': null, 'meta_description': null, 'author_id': 1, 'created_at': published, 'created_by': 1, 'updated_at': Date.parse(post.updated['$t']), 'updated_by': 1, 'published_at': published, 'published_by': 1 }, post); }): [];
function replaceNonLatinChars(input, options) { input = unidecode(input); return input; }
function getPublisherBooks (publisher, skip, take, callback) { var translit_t = unidecode(publisher); var sql = `SELECT * FROM ( SELECT ROW_NUMBER() OVER (ORDER BY publisher_books.datepub DESC) AS row_number, * FROM ( SELECT * FROM ( ( SELECT inventory.recordid, LTRIM(RTRIM(inventory.catalog)) AS catalog, LTRIM(RTRIM(inventory.hard_isbn)) AS hard_isbn, LTRIM(RTRIM(inventory.soft_isbn)) AS soft_isbn, LTRIM(RTRIM(inventory.subjectx)) AS subjectx, LTRIM(RTRIM(inventory.title2x)) AS title2x, LTRIM(RTRIM(inventory.publisherx)) AS publisherx, LTRIM(RTRIM(inventory.authorsx)) AS authorsx, inventory.use_pe_image_only, inventory.ltd_editio, inventory.datepub, 1 AS nyp, ROW_NUMBER() OVER(PARTITION BY inventory.catalog ORDER BY recordid DESC) row_num FROM inventory WHERE (hardbound = 1 AND hard_nyp = 1) OR (softbound = 1 AND soft_nyp = 1) ) UNION ( SELECT inventory.recordid, LTRIM(RTRIM(inventory.catalog)) AS catalog, LTRIM(RTRIM(inventory.hard_isbn)) AS hard_isbn, LTRIM(RTRIM(inventory.soft_isbn)) AS soft_isbn, LTRIM(RTRIM(inventory.subjectx)) AS subjectx, LTRIM(RTRIM(inventory.title2x)) AS title2x, LTRIM(RTRIM(inventory.publisherx)) AS publisherx, LTRIM(RTRIM(inventory.authorsx)) AS authorsx, inventory.use_pe_image_only, inventory.ltd_editio, inventory.datepub, 0 AS nyp, ROW_NUMBER() OVER(PARTITION BY inventory.catalog ORDER BY recordid DESC) row_num FROM inventory WHERE hard_nyp = 0 AND soft_nyp = 0 ) ) unique_books WHERE unique_books.row_num = 1 ) publisher_books WHERE REPLACE(RTRIM(LTRIM(publisher_books.publisherx)), ' ', '-') = :publisher OR REPLACE(RTRIM(LTRIM(publisher_books.publisherx)), ' ', '-') = :translit_t OR REPLACE(REPLACE(RTRIM(LTRIM(publisher_books.publisherx)), ' ', ''), '-', '') = REPLACE(REPLACE(:publisher, ' ', ''), '-', '') OR REPLACE(REPLACE(RTRIM(LTRIM(publisher_books.publisherx)), ' ', ''), '-', '') = REPLACE(REPLACE(:translit_t, ' ', ''), '-', '') ) paged_books WHERE row_number BETWEEN :skip + 1 AND :skip + :take ORDER BY paged_books.nyp DESC, paged_books.datepub DESC`; var params = { publisher: publisher, translit_t: translit_t, skip: parseInt(skip), take: parseInt(take) }; photoeye .query(sql, { replacements: params }) .spread(function(results, metadata) { misc.normalizeInventoryData(results); callback(results); }); }
.then((text) => { text = text.replace(/Dates flexible\?/g, '').replace(/Find Availability/g, '').replace(/\n/g, ' ').trim().replace(/\s\s+/g, '\n').replace(/New\n/g, '') let count = 0; let start = 0; let end = 0; for (let i = 0; i < text.length; i++) { if (text.charAt(i) == '{' && count == 0) { start = i; count++; } else if (text.charAt(i) == '{') { count++; } else if (text.charAt(i) == '}') { if (--count == 0) { end = i; text = text.substr(0, start) + text.substr(end + 1); i -= (end - start) } } } let hotels = text.split("\n\n") let hotel_results = [] for (let i = 0; i < hotels.length; i++) { if (hotels[i].indexOf('This hotel is not currently accepting reservations.') > -1) { continue } let current = hotels[i].split('\n') let result = {} for (let j = 0; j < current.length; j++) { if (j == 0) { result.hotel_name = unidecode(current[j]) } else if (current[j] == "Lowest Standard Rate") { if (current[++j] == "Find Available Dates") { continue } result.BAR = current[++j].match(/\d+/)[0] } else if (current[j] == "SPG Free Nights") { if (current[++j] == "Find Available Dates" || current[j] == "Please contact us to redeem your Free Nights." || current[j] == "This hotel has Limited Participation in the Starwood Preferred Guest® Program.") { continue } result.FN = current[++j].replace(',', '').match(/\d+/)[0] } else if (current[j] == "SPG Cash & Points") { if (current[++j] == "Find Available Dates" || current[j] == "This hotel has Limited Participation in the Starwood Preferred Guest® Program.") { continue } result.CP = { "p": current[++j].replace(',', '').match(/\d+/)[0], "c": current[++j].match(/\d+/)[0] } } } //DNS SOLUTION for fetching data let fileName = "" fileName = hotelConverter[result.hotel_name] if(fileName == undefined){ fileName = result.hotel_name.replace(/ /g, "_").replace(/,/g, "").replace(/_-_/g, "_").replace(/\'/g,"").replace(/_&_/g, "_").replace(/\./g, "") } let r = Math.floor(Math.random() * 10000000) / 10000000 if (master.cors == "DNS") { result.targetURL = `http://hotels.justbrg.it/Hotel/SearchResults?checkin=${req.query.checkin}&checkout=${req.query.checkout}&Rooms=1&adults_1=2&fileName=${fileName}&r=${r}` } else { result.targetURL = `http://www.hotelscombined.com/Hotel/SearchResults?checkin=${req.query.checkin}&checkout=${req.query.checkout}&Rooms=1&adults_1=2&fileName=${fileName}&r=${r}` } hotel_results.push(result) } return res.end(JSON.stringify(hotel_results)); })