Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Dreaming

Christopher Tran pfftdammitchris

💭
Dreaming
View GitHub Profile
View noodl.schema.json
{
"$id": "noodl-schema",
"$ref": "#/definitions/Page",
"$schema": "http://json-schema.org/draft-07/schema#",
"anyOf": [
{
"$ref": "#/definitions/RootConfig"
}
],
"definitions": {
View yaml.schema.json
{
"$defs": {
"Action": {
"accessToken": {
"type": "string"
},
"actionType": {
"description": "Used as an identifier for an action",
"type": "string"
},
View 5-java-script-practices-that-will-help-your-teammates-sleep-at-night_3.ts
type ReferenceString = string
type Obj = Record<string, any>
interface TransformFunc {
(
transformer: <V>(value: ReferenceString | Obj | any[]) => V,
...args: any
): any[]
}
View 5-java-script-practices-that-will-help-your-teammates-sleep-at-night_8.js
async function initContainer({ children, tagName = 'div' } = {}) {
const container = document.createElement(tagName)
if (children) {
container.appendChild(await children(container))
}
return container
}
async function startApp() {
await initContainer({
View 5-java-script-practices-that-will-help-your-teammates-sleep-at-night_9.js
// elements.js
function getIframe(container = document.body) {
return new Promise((resolve, reject) => {
const attributes = { src: 'http://www.google.com/abc.png' }
const elem = document.createElement('iframe')
// Assuming "attributes" also includes the "src"
Object.entries(attributes).forEach(([attr, value]) => {
elem.setAttribute(attr, value)
})
View 5-java-script-practices-that-will-help-your-teammates-sleep-at-night_1.js
function createSignature(obj) {
if (typeof obj === 'string') {
// Do something
} else if (Array.isArray(obj)) {
// Do something
} else {
// Do something
}
}
View 5-java-script-practices-that-will-help-your-teammates-sleep-at-night_2.js
function validateURL(value) {
if (typeof value === 'string') {
// URL string
} else if (value && typeof value === 'object') {
// URL instance
}
}
View 5-java-script-practices-that-will-help-your-teammates-sleep-at-night_4.js
const transform = (transformer, ...args) => {
return args.reduce(
(arr, arg) =>
Array.isArray(arg)
? arr.concat(...arg.map((val) => transformer(val)))
: transformer(arg),
[],
)
}
View 5-java-script-practices-that-will-help-your-teammates-sleep-at-night_7.js
function getDogs() {
return new Promise((resolve, reject) => ['dog1', 'dog2'])
}
const getDogs = () => new Promise((resolve, reject) => ['dog1', 'dog2'])