0.23.0 • Published 3 years ago

@githubnext/utils v0.23.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

GitHub Blocks Utils Functions

To reduce the cognitive load associated with writing file and folder block components, we've assembled a helper library called @githunext/utils that exposes interface definitions and a few helper functions.

How to use

yarn add @githubnext/utils

import {
  FileBlockProps,
  FolderBlockProps,
  getLanguageFromFilename,
  getNestedFileTree,
} from '@githubnext/utils`

FileBlockProps

import { FileBlockProps } from '@githubnext/utils';

export default function (props: FileBlockProps) {
  const { content, metadata, onUpdateMetadata } = props;
  ...
}

FolderBlockProps

import { FolderBlockProps } from '@githubnext/utils';

export default function (props: FileBlockProps) {
  const { tree, metadata, onUpdateMetadata, BlockComponent } = props;
  ...
}

getLanguageFromFilename

A helper function that returns the "language" of a file, given a valid file path with extension.

getNestedFileTree

A helper function to turn the flat folder tree array into a nested tree structure

import { FolderBlockProps, getNestedFileTree, } from "@githubnext/utils";

export default function (props: FolderBlockProps) {
  const { tree, onNavigateToPath } = props;

  const data = useMemo(() => {
    const nestedTree = getNestedFileTree(tree)[0]
    return nestedTree
  }, [tree])
  ...
}

bundleCodesandboxFiles

A helper function to generate a bundle of files to send to CodeSandbox's Sandpack library. For an example, see the custom Block template repo.

onRequestGitHubData

A helper function to handle the onRequestGitHubData callback for Blocks. This function will GET data from any GitHub API endpoint.

0.23.0

3 years ago

0.22.0

3 years ago

0.20.0

3 years ago

0.21.0

3 years ago

0.19.8

3 years ago

0.19.7

3 years ago

0.19.0

3 years ago

0.19.1

3 years ago

0.19.2

3 years ago

0.19.3

3 years ago

0.19.4

3 years ago

0.19.5

3 years ago

0.19.6

3 years ago

0.17.0

3 years ago

0.18.0

3 years ago

0.15.4

3 years ago

0.13.0

3 years ago

0.13.1

3 years ago

0.15.0

3 years ago

0.15.1

3 years ago

0.15.2

3 years ago

0.15.3

3 years ago

0.16.0-0

3 years ago

0.15.0-0

3 years ago

0.14.0

3 years ago

0.16.0

3 years ago

0.12.0

4 years ago

0.11.1

4 years ago

0.12.1

4 years ago

0.11.2

4 years ago

0.12.2

4 years ago

0.11.3

4 years ago

0.12.3

4 years ago

0.11.0

4 years ago

0.10.0

4 years ago

0.9.18

4 years ago

0.9.17

4 years ago

0.9.16

4 years ago

0.9.15

4 years ago

0.9.14

4 years ago

0.9.13

4 years ago

0.9.12

4 years ago

0.9.11

4 years ago

0.9.10

4 years ago

0.9.9

4 years ago

0.9.8

4 years ago

0.9.7

4 years ago

0.9.6

4 years ago

0.9.5

4 years ago

0.9.4

4 years ago

0.9.3

4 years ago

0.9.2

4 years ago

0.9.1

4 years ago

0.9.0

4 years ago

0.8.2

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.7.2-0

4 years ago

0.7.1-0

4 years ago

0.7.0-0

4 years ago

0.6.0

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago