Skip to content

Instantly share code, notes, and snippets.

View jquintozamora's full-sized avatar

José Quinto jquintozamora

View GitHub Profile
/**
* 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]
*/
// 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")
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];
<%@ Register TagPrefix="SearchWC" Namespace="Microsoft.Office.Server.Search.WebControls" Assembly="Microsoft.Office.Server.Search, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>
...
<SharePoint:AjaxDelta id="DeltaPlaceHolderSearchArea" blockelement="true" cssclass="ms-mpSearchBox ms-floatRight" runat="server">
<asp:contentplaceholder id="PlaceHolderSearchArea" runat="server">
<div id="peopleSearch">
<SearchWC:SearchBoxScriptWebPart
ID="SmallSearchInputBoxPeople"
UseSiteCollectionSettings="false"
InitialPrompt="Search for people"
EmitStyleReference="false"
// It is important to have the following folder structure
// root
// |
// |-- containers
// | |
// | |-- MyAppContainer
// | |
// | |-- MyAppContainer.tsx (here is where we use the api)
// |
// |-- api
// 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(() => {
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();
module.exports = {
// target, entry, output, etc..
plugins: [
// replacement for Mock APIs
new webpack.NormalModuleReplacementPlugin(/(\.*)\/api\/(\.*)/, function (resource) {
resource.request = resource.request.replace(/api/, `/apiMock/`);
})
]
}
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"lib": [
"dom",
"es5",
"scripthost",
"es2015.promise"
],
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) {