This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let chance = require('chance')(); | |
function generatePhone(nums) { | |
if (!nums){ | |
nums = 1; | |
} | |
return chance.unique(function generatePhone() { | |
let phone = '1'; | |
phone+= chance.string({length: 1, pool: '34578'}); | |
phone+= chance.string({length: 9, pool: '9876543210'}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 邮箱字符遮罩 | |
* @param email | |
* @returns {string} | |
* @private | |
*/ | |
function _hideEmail(email) { | |
var accounts = email.split('@')[0]; | |
var suffix = email.split('@')[1]; | |
var hideNums = Math.floor(accounts.length/2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Promise = require("bluebird"); | |
return Promise.map(objects, function (object) { | |
sails.log.info('An object will be created:'); | |
sails.log.info(object); | |
return Comment.findOrCreate(object.id , object); | |
}).then(function (objects) { | |
sails.log.info('The objects created or found goes here: '); | |
sails.log.info(objects); | |
return objects; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var paginate = require('handlebars-paginate'); | |
Handlebars.registerHelper('paginate', paginate); | |
/* ... */ | |
var html = template({pagination: { | |
page: 3, | |
pageCount: 10 | |
}}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// # Excerpt Helper | |
// Usage: `{{excerpt}}`, `{{excerpt words="50"}}`, `{{excerpt characters="256"}}` | |
// | |
// Attempts to remove all HTML from the string, and then shortens the result according to the provided option. | |
// | |
// Defaults to words="50" | |
var hbs = require('express-hbs'), | |
_ = require('lodash'), | |
downsize = require('downsize'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// # Date Helper | |
// Usage: `{{date format="DD MM, YYYY"}}`, `{{date updated_at format="DD MM, YYYY"}}` | |
// | |
// Formats a date using moment.js. Formats published_at by default but will also take a date as a parameter | |
var moment = require('moment'), | |
date; | |
date = function (context, options) { | |
if (!options && context.hasOwnProperty('hash')) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var unidecode = require('unidecode'); | |
var safeString = function (string) { | |
string = string.trim(); | |
// Remove non ascii characters | |
string = unidecode(string).trim(); | |
// Remove URL reserved chars: `:/?#[]@!$&'()*+,;=` as well as `\%<>|^~£"` | |
string = string.replace(/[:\/\?#\[\]@!$&'()*+,;=\\%<>\|\^~£"]/g, '') | |
// Replace dots and spaces with a dash |
NewerOlder