Skip to content

Instantly share code, notes, and snippets.

Avatar

Phil Harding phillipharding

View GitHub Profile
@phillipharding
phillipharding / Search for Modern News Page Content using PnPJS.ts
Created Sep 11, 2020
Search for Modern News Page Content using PnPJS
View Search for Modern News Page Content using PnPJS.ts
import { sp, SearchResults, SearchQueryInit, ISearchResult } from "@pnp/sp/presets/all";
console.clear();
function parseUserFormattedString(ownerString) {
const owners = ownerString.split(";")
.map( (owner) => {
const parts = owner.trim().split("|");
const oidstr = parts.splice(2,3).join("").trim();
const oids = oidstr.split(" ");
return {
@phillipharding
phillipharding / Create new ClientsidePage using PnPJS.ts
Last active Sep 16, 2020
Create new ClientsidePage using PnPJS
View Create new ClientsidePage using PnPJS.ts
import { sp, ClientsidePageFromFile, PromotedState, IListItemFormUpdateValue, IClientsidePage, IFileInfo } from "@pnp/sp/presets/all";
console.clear();
function SafeFilename(fileName: string, convertToLower?: boolean): string {
const name = (fileName || "")
.replace(/[^ a-zA-Z0-9-_]*/gi, "")
.replace(/ /gi, "-")
.replace(/-*$/gi, "")
.replace(/[-]{2,}/gi, "-");
return convertToLower ? name.toLowerCase() : name;
View Get Taxonomy Terms Hierarchy using PnPJS
import { sp } from "@pnp/sp/presets/all";
import "@pnp/sp/taxonomy";
import { taxonomy, ITerm, ITermData } from "@pnp/sp-taxonomy"
(async () => {
interface ITermDataNode {
Id: string;
ParentTermId?: string;
Name: string;
Path: string;
View Create and Locate an Item in a JSON Tree
json = [
{
key: 1,
id: 1,
label: "Parent #1",
isexpanded: false,
children: [
{
key: 11,
id: 11,
@phillipharding
phillipharding / Get Paged Items from a Large List using RenderListDataAsStream
Last active Jul 14, 2020
Gets Items from a Large Document Library/List (over 5000 items) using a Paged RenderListDataAsStream
View Get Paged Items from a Large List using RenderListDataAsStream
import { sp } from "@pnp/sp/presets/all";
(async () => {
console.clear();
const doPagedQuery = (folder: string, rowLimit: number, scope: "Files"|"Folders", pageToken?: string) => {
const list = sp.web.getList('/sites/EDMS_InformationGovernance/Shared%20Documents');
return list.renderListDataAsStream({
ViewXml: `
<View Scope="RecursiveAll">
View NVM Commands.md

NVM version

nvm --version

List versions of Node installed

nvm ls --no-alias

List current version of Node

nvm current

Use the specified version of Node

View Matching Invalid Characters in Team & Channel Names.md

~ # % & * { } + \ / : < > ? | " .

REGEX

[~#%&*{}+\\/:<>?|'".]+
const hasInvalidCharacters = teamName.match(/[~#%&*{}+\\/:<>?|'".]+/gi);
@phillipharding
phillipharding / Remove .DS_Store files.sh
Created Apr 28, 2020
Recursively removes .DS_Store files
View Remove .DS_Store files.sh
## Recursively Remove .DS_Store
# Show
find . -name '.DS_Store' -type f
# Remove
find . -name '.DS_Store' -type f -delete
View SharePoint V2 API Convert to PDF.js
//import { sp, Site, spGet, SharePointQueryable } from "@pnp/sp/presets/all";
import { sp } from "@pnp/sp";
import { Site } from "@pnp/sp/sites";
import "@pnp/sp/sites";
import { IFetchOptions } from "@pnp/common";
console.clear();
(async () => {
// get site using PnPJs
@phillipharding
phillipharding / SP.MoveCopyUtil.CopyFileByPath.md
Last active Feb 5, 2020
SP.MoveCopyUtil.CopyFileByPath()
View SP.MoveCopyUtil.CopyFileByPath.md