This file contains hidden or 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
/** | |
* Return an object that describes types of the given value. | |
* | |
* @param {unknown} value | |
* @param {object} schema | |
*/ | |
function buildSchema(value, schema = {}) { | |
if (value === null) { | |
schema.nulls = (schema.nulls || 0) + 1; | |
return schema; |
This file contains hidden or 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
// From https://github.com/locutusjs/locutus/blob/main/src/php/strings/strtr.js | |
// but adapted to the all-strings case. | |
function strtr(str: string, trFrom: string, trTo: string) { | |
let j = 0; | |
let lenStr = 0; | |
let lenFrom = 0; | |
let istr = ''; | |
let ret = ''; | |
let match = false; |
This file contains hidden or 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
/** | |
* Generates file ./utils/queries/WpBlocksFragment.ts containing | |
* a fragment with all the WP core block fragments Faust provides. | |
* | |
* USAGE: ts-node block-fragments.ts | |
*/ | |
import { CoreBlocks } from '@faustwp/blocks'; | |
import { glob } from 'glob'; | |
import { mkdirSync, writeFileSync } from 'node:fs'; |
This file contains hidden or 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
type OmitNull<T> = T extends null ? Exclude<T, null> | undefined : T; | |
type OmitNullProps<T extends object> = { [Key in keyof T]: OmitNull<T[Key]> }; | |
/** | |
* Allow destructuring an object, turning any null properties into undefined so | |
* a default can be given. If the given object may be null/undefined, then every | |
* property may be undefined. | |
* | |
* Useful for assigning defaults for properties that may be null. In a usual destructuring | |
* assignment, nulls are passed through so you can't provide a default for that case: |
This file contains hidden or 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
/** | |
* Creates embed-friendly dist/fragment.html | |
* | |
* Install qwik: `npm create qwik@latest` | |
* Configure static: https://qwik.builder.io/docs/guides/static-site-generation/#static-site-generation-config | |
* In adapters/static/vite.config.ts place vitePluginQwikFragment() after the staticAdapter. | |
* Build: `npm run build` | |
* The file `dist/fragment.html` will be created. | |
* To test: `npx serve dist` and open http://localhost:3000/fragment.html | |
* |
This file contains hidden or 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
[...document.querySelectorAll('h1,h2,h3,h4,h5,h6')].filter(el => !el.textContent.trim()).forEach(el => console.log(el)) |
This file contains hidden or 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
// filename.json <-- the data | |
// filename.json.d.ts <-- type definition (this file) | |
// Just an example type | |
const value: Record<string, string>; | |
export default value; |
This file contains hidden or 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 interface FetchInfo { | |
uri: RequestInfo; | |
init: RequestInit; | |
res?: unknown; | |
text?: string; | |
error?: unknown; | |
} | |
function defaultLogger({uri, init, text}: FetchInfo): void { | |
console.info({uri, text, init}); |
NewerOlder