diff --git a/src/index.ts b/src/index.ts index 5458093..c4cd08f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,3 @@ export * as Blocks from './builders'; export * as Types from './types'; +export * as Utils from './utils'; diff --git a/src/types.ts b/src/types.ts index 189c90d..e0ea10a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1 +1,4 @@ +import {Code} from 'notion-api-types/responses/blocks'; + export * from 'notion-api-types'; +export type CodeLang = Code['code']['language']; diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..1de033d --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,84 @@ +import {CodeLang} from './types'; + +/** This is just to keep a value with all languages, so that is can be used at runtime */ +const codeLangs: Record = { + abap: null, + arduino: null, + bash: null, + basic: null, + c: null, + clojure: null, + coffeescript: null, + 'c++': null, + 'c#': null, + css: null, + dart: null, + diff: null, + docker: null, + elixir: null, + elm: null, + erlang: null, + flow: null, + fortran: null, + 'f#': null, + gherkin: null, + glsl: null, + go: null, + graphql: null, + groovy: null, + haskell: null, + html: null, + java: null, + javascript: null, + json: null, + julia: null, + kotlin: null, + latex: null, + less: null, + lisp: null, + livescript: null, + lua: null, + makefile: null, + markdown: null, + markup: null, + matlab: null, + mermaid: null, + nix: null, + 'objective-c': null, + ocaml: null, + pascal: null, + perl: null, + php: null, + 'plain text': null, + powershell: null, + prolog: null, + protobuf: null, + python: null, + r: null, + reason: null, + ruby: null, + rust: null, + sass: null, + scala: null, + scheme: null, + scss: null, + shell: null, + sql: null, + swift: null, + typescript: null, + 'vb.net': null, + verilog: null, + vhdl: null, + 'visual basic': null, + webassembly: null, + xml: null, + yaml: null, + 'java/c/c++/c#': null, +}; + +/** + * Returns whether a string is a supported language for `code` blocks + */ +export function isCodeLang(str: string): str is CodeLang { + return Object.keys(codeLangs).includes(str); +}