0.23.0 • Published 2 years ago

@githubnext/utils v0.23.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 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

2 years ago

0.22.0

2 years ago

0.20.0

2 years ago

0.21.0

2 years ago

0.19.8

2 years ago

0.19.7

2 years ago

0.19.0

2 years ago

0.19.1

2 years ago

0.19.2

2 years ago

0.19.3

2 years ago

0.19.4

2 years ago

0.19.5

2 years ago

0.19.6

2 years ago

0.17.0

2 years ago

0.18.0

2 years ago

0.15.4

2 years ago

0.13.0

2 years ago

0.13.1

2 years ago

0.15.0

2 years ago

0.15.1

2 years ago

0.15.2

2 years ago

0.15.3

2 years ago

0.16.0-0

2 years ago

0.15.0-0

2 years ago

0.14.0

2 years ago

0.16.0

2 years ago

0.12.0

2 years ago

0.11.1

2 years ago

0.12.1

2 years ago

0.11.2

2 years ago

0.12.2

2 years ago

0.11.3

2 years ago

0.12.3

2 years ago

0.11.0

2 years ago

0.10.0

3 years ago

0.9.18

3 years ago

0.9.17

3 years ago

0.9.16

3 years ago

0.9.15

3 years ago

0.9.14

3 years ago

0.9.13

3 years ago

0.9.12

3 years ago

0.9.11

3 years ago

0.9.10

3 years ago

0.9.9

3 years ago

0.9.8

3 years ago

0.9.7

3 years ago

0.9.6

3 years ago

0.9.5

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.9.2

3 years ago

0.9.1

3 years ago

0.9.0

3 years ago

0.8.2

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.7.2-0

3 years ago

0.7.1-0

3 years ago

0.7.0-0

3 years ago

0.6.0

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago