Skip to content

Instantly share code, notes, and snippets.

{
"name": "MongoSourceChangeEvent",
"namespace": "com.company.common.avro",
"type": "record",
"fields": [
{
"name": "_id",
"type": "string"
},
{
/*
* This is just the IEEE 754 spec. Nothing specific to JavaSctipt.
* */
typeof NaN; // number
/*
* JavaScript will invoke ToPrimitive operation.
* In this case, because the hint sent to ToPrimitive is "default", the flow is: [].valueOf -> [].toString.
* [].toString returns "", so "" + "" === ""
* */
const truncateString = (str, len) => {
if (str.length > len && str.length > 0) {
let newStr = str + ' ';
newStr = str.substr(0, len);
newStr = str.substr(0, newStr.lastIndexOf(' '));
newStr = newStr.length > 0 ? newStr : str.substr(0, len);
return `${newStr}...`;
}
return str;
};
@SasonBraha
SasonBraha / .env
Created July 19, 2019 08:45
.env file example
PORT=5000