Skip to content

Instantly share code, notes, and snippets.

View miraage's full-sized avatar

Mikhail Osher miraage

View GitHub Profile
function slugify(text) {
return angular.lowercase((text || ''))
.replace(/\s+/g, '-')
.replace(/[^\w\-]+/g, '')
.replace(/\-\-+/g, '-')
.replace(/^-+/, '')
.replace(/-+$/, '');
}
@miraage
miraage / get-line-breaks.ts
Created November 9, 2021 14:57
Multiline ellipsis
// https://stackoverflow.com/a/55605049
export function getLineBreaks(node: Node): string[] {
// we only deal with TextNodes
if (!node || !node.parentNode || node.nodeType !== 3 || !node.textContent) return [];
// our Range object form which we'll get the characters positions
const range = document.createRange();
// here we'll store all our lines
const lines = [];
// begin at the first char
range.setStart(node, 0);