This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gives a numeric range | |
* | |
* @param {number} start - initial number | |
* @param {number} stop - final number | |
* @param {number} step - increment value | |
* @returns {Array} numeric range between start and stop by increments of step | |
* | |
* Example: numericRange(-2, 2, 1) = numericRange(-2, 2) => [-2, -1, 0, 1, 2] | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Implementing logger class with Winston 3, using custom label and singleton pattern | |
// logger/index.js | |
const { createLogger, format, transports } = require("winston"); | |
const { combine, timestamp, colorize, label, printf } = format; | |
const myFormat = printf(info => { | |
return `${info.timestamp} [${info.label}] ${info.level}: ${ | |
typeof info.message === "string" | |
? info.message | |
: JSON.stringify(info.message, null, "\t") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getDescendantProp(obj: {[key: string]: {}}, desc: string) { | |
if (obj === null || obj === undefined || desc === "") { | |
return undefined; | |
} | |
const arr: string[] = desc.split("."); | |
if (arr.length > 0 && arr[0] !== "") { | |
while (arr.length) { | |
const name: string | undefined = arr.shift(); | |
if ((typeof name === "string") && (name in obj)) { | |
obj = obj[name]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// It is important to have the following folder structure | |
// root | |
// | | |
// |-- containers | |
// | | | |
// | |-- MyAppContainer | |
// | | | |
// | |-- MyAppContainer.tsx (here is where we use the api) | |
// | | |
// |-- api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// delay to emulate api call | |
const delay: number = 500; | |
export default class TaxonomyAPI { | |
/* | |
* MOCK Function to get all terms of a given taxonomy Term Set | |
*/ | |
public static getAllTermsByTermSet(termSetGuid: string, termSetName: string, showOnlyAdvailableForTag: boolean) { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class TaxonomyAPI { | |
/* | |
* Function to get all terms of a given taxonomy Term Set | |
*/ | |
public static getAllTermsByTermSet(termSetGuid: string, termSetName: string, showOnlyAdvailableForTag: boolean) { | |
return new Promise((resolve, reject) => { | |
SP.SOD.executeFunc("sp.js", "SP.ClientContext", () => { | |
SP.SOD.registerSod("sp.taxonomy.js", SP.Utilities.Utility.getLayoutsPageUrl("sp.taxonomy.js")); | |
SP.SOD.executeFunc("sp.taxonomy.js", "SP.Taxonomy.TaxonomySession", () => { | |
const ctx = SP.ClientContext.get_current(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
// target, entry, output, etc.. | |
plugins: [ | |
// replacement for Mock APIs | |
new webpack.NormalModuleReplacementPlugin(/(\.*)\/api\/(\.*)/, function (resource) { | |
resource.request = resource.request.replace(/api/, `/apiMock/`); | |
}) | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"compilerOptions": { | |
"target": "es5", | |
"module": "esnext", | |
"lib": [ | |
"dom", | |
"es5", | |
"scripthost", | |
"es2015.promise" | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import(/* webpackChunkName: "momentjs" */ "moment") | |
.then(function (moment) { | |
// lazyModule has all of the proper types, autocomplete works, | |
// type checking works, code references work \o/ | |
var time = moment().format(); | |
console.log("TypeScript >= 2.4.0 Dynamic Import Expression:"); | |
console.log(time); | |
_this.setState({ time: time }); | |
}) | |
.catch(function (err) { |
NewerOlder