Skip to content

Commit

Permalink
feat: add utils and code languages
Browse files Browse the repository at this point in the history
  • Loading branch information
EndBug committed Jun 3, 2022
1 parent 3c775cd commit 5216e1b
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * as Blocks from './builders';
export * as Types from './types';
export * as Utils from './utils';
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
import {Code} from 'notion-api-types/responses/blocks';

export * from 'notion-api-types';
export type CodeLang = Code['code']['language'];
84 changes: 84 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -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<CodeLang, null> = {
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);
}

0 comments on commit 5216e1b

Please sign in to comment.