Skip to content

Instantly share code, notes, and snippets.

View BnayaZil's full-sized avatar

Bnaya Zilberfarb BnayaZil

View GitHub Profile
@drewrawitz
drewrawitz / truncate.js
Created September 29, 2016 19:53
JS Truncate without cutting off words
var truncate = function(text, characterLimit) {
if( !text || text.length < characterLimit ){ return text; }
var expressionString = "^(.{" + characterLimit + "}[^\\s]*).*";
var expression = new RegExp(expressionString);
var truncatedText = text.replace(expression, "$1");
return truncatedText + '...'
}
@aurbano
aurbano / removeKeys.js
Last active November 29, 2022 21:57
Remove a property from a nested object, recursively
/**
* Remove all specified keys from an object, no matter how deep they are.
* The removal is done in place, so run it on a copy if you don't want to modify the original object.
* This function has no limit so circular objects will probably crash the browser
*
* @param obj The object from where you want to remove the keys
* @param keys An array of property names (strings) to remove
*/
function removeKeys(obj, keys){
var index;
@branneman
branneman / better-nodejs-require-paths.md
Last active June 29, 2024 16:00
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@CMCDragonkai
CMCDragonkai / Truncate.Filter.js
Created August 18, 2013 20:46
JS: AngularJS Truncate Filter for Words and Characters. Adapted from https://github.com/sparkalow/angular-truncate
define(['angular'], function(angular){
'use strict';
/**
* Truncates characters or words. Truncate characters by default does not truncates on a word.
*/
angular.module('Filters')
.filter('TruncateCharacters', [
function(){