Skip to content

Instantly share code, notes, and snippets.

View JerryC8080's full-sized avatar
🇨🇳
Hi~!

JerryC JerryC8080

🇨🇳
Hi~!
View GitHub Profile
@JerryC8080
JerryC8080 / generateZhPhone.js
Last active March 21, 2016 08:06
使用Chance,随机生成中国电话号码
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'});
@JerryC8080
JerryC8080 / 邮箱字符遮罩
Created February 17, 2016 03:27
邮箱字符遮罩
/**
* 邮箱字符遮罩
* @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);
@JerryC8080
JerryC8080 / findOrCreate use way
Last active August 29, 2015 14:19
Sails Model.findOrCreate method use way with promise style
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;
@JerryC8080
JerryC8080 / example
Last active October 28, 2017 05:53
paginate helper
var paginate = require('handlebars-paginate');
Handlebars.registerHelper('paginate', paginate);
/* ... */
var html = template({pagination: {
page: 3,
pageCount: 10
}});
@JerryC8080
JerryC8080 / excerpt.js
Created December 17, 2014 03:38
Excerpt Helper
// # 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'),
@JerryC8080
JerryC8080 / date.js
Created December 16, 2014 15:11
ghost date helper
// # 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')) {
@JerryC8080
JerryC8080 / index.javascript
Last active April 21, 2016 12:01 — forked from shanelau/index.javascript
中文转拼音
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