Skip to content

Instantly share code, notes, and snippets.

View Sanchithasharma's full-sized avatar
😃

Sanchitha SR Sanchithasharma

😃
View GitHub Profile
@Sanchithasharma
Sanchithasharma / gist:7e193212b414a06f89be3cfb72b6a882
Last active February 5, 2021 10:43
Convert HTML to plain text using html-to-text package
const { htmlToText } = require('html-to-text');
const text = htmlToText('<div>Nope Its not Ashton Kutcher. It is Kevin Malone. <p>Equally Smart and equally handsome</p></div>', {
wordwrap: 130
});
console.log(text); // expected result:
// Nope Its not Ashton Kutcher. It is Kevin Malone.
// Equally Smart and equally handsome
@Sanchithasharma
Sanchithasharma / gist:8ab572ac877f3856fce12eb78b29acc6
Last active January 26, 2022 14:18
Convert HTML text to plain text using temporary DOM element
function convertToPlain(html){
// Create a new div element
var tempDivElement = document.createElement("div");
// Set the HTML content with the given value
tempDivElement.innerHTML = html;
// Retrieve the text property of the element
return tempDivElement.textContent || tempDivElement.innerText || "";
@Sanchithasharma
Sanchithasharma / usingReplace.js
Created February 5, 2021 09:00
Convert HTML text to plain text
var myHTML= "<div><h1>Jimbo.</h1>\n<p>That's what she said</p></div>";
var strippedHtml = myHTML.replace(/<[^>]+>/g, '');
// Jimbo.
// That's what she said
console.log(stripedHtml);
@Sanchithasharma
Sanchithasharma / isFinite.js
Created January 26, 2021 17:15
Check if the variable is number using Number.isFinite()
var numberOfpushUpsToday = 34;
if(Number.isFinite(numberOfpushUpsToday) ){
console.log('It is a number')
}
else {
console.log('It is not a number')
}
@Sanchithasharma
Sanchithasharma / typeof.js
Created January 26, 2021 17:06
Check if variable is a number using typeof
var numberOfpushUpsToday = 34;
if(typeof numberOfpushUpsToday === 'number' ){
console.log('It is a number')
}
else {
console.log('It is not a number')
}
@Sanchithasharma
Sanchithasharma / isNan.js
Last active January 26, 2021 17:30
Check if a variable is Number or not using isNan()
var numberOfpushUpsToday = 34;
if(!isNaN(numberOfpushUpsToday)){
console.log('It is a number')
}
else {
console.log('It is not a number')
}
@Sanchithasharma
Sanchithasharma / usingToString.js
Created January 4, 2021 17:05
Using to String to flatten the array
favMovies = ['Begin Again', 'Soul', ['Matrix', 'Matix Reloaded', 'Matrix Revolutions'],['Frozen', 'Frozen 2', ['Tangled', 'Alladin']]]
favMovies.toString().split(",")
// expected result: ["Begin Again", "Soul", "Matrix", "Matix Reloaded", "Matrix Revolutions", "Frozen", "Frozen 2", "Tangled", "Alladin"]
@Sanchithasharma
Sanchithasharma / es.js
Last active November 28, 2020 18:10
Adding the property to the object using ES7
var list =
{
name: 'Michael Scott',
company: 'Dunder Mufflin',
designation: 'Regional Manager',
show: 'The Office',
},
new_obj = { ...list, partner: 'Holly Flax' }
@Sanchithasharma
Sanchithasharma / deleteProperty.js
Created November 28, 2020 15:38
Delete the Property from an Object
var brooklynNineNine = {
name: 'Amy Santiago',
currentRole: 'Detective brooklyn99',
husband: 'Jake Peralta',
mentor: 'Raymond Holt'
}
delete brooklynNineNine.mentor;
console.log(brooklynNineNine)