Comparing version 0.4.1 to 0.5.0
@@ -10,2 +10,3 @@ "use strict"; | ||
exports.parse = parse; | ||
exports.ready = ready; | ||
@@ -19,2 +20,8 @@ var _starryNight = require("@wooorm/starry-night"); | ||
const starryNight = (0, _starryNight.createStarryNight)(_starryNight.all); | ||
let starryNightCache = null; | ||
async function ready() { | ||
starryNightCache = await starryNight; | ||
} | ||
const handler = { | ||
@@ -35,5 +42,6 @@ get(_, language) { | ||
async function parse(code) { | ||
function parse(code) { | ||
const raw = integrate(code); | ||
const sn = await starryNight; | ||
if (starryNightCache == null) throw new Error(`you must await ready()`); | ||
const sn = starryNightCache; | ||
const scope = sn.flagToScope(code.language); | ||
@@ -184,5 +192,5 @@ | ||
async function diff(start, end) { | ||
const startParsed = chars(await parse(start)); | ||
const endParsed = chars(await parse(end)); | ||
function diff(start, end) { | ||
const startParsed = chars(parse(start)); | ||
const endParsed = chars(parse(end)); | ||
let index = 0; | ||
@@ -189,0 +197,0 @@ let endex = 0; |
import { createStarryNight, all } from '@wooorm/starry-night'; | ||
import style from './dark-style'; | ||
const starryNight = createStarryNight(all); | ||
let starryNightCache = null; | ||
export async function ready() { | ||
starryNightCache = await starryNight; | ||
} | ||
const handler = { | ||
@@ -17,5 +21,6 @@ get(_, language) { | ||
export const language = new Proxy({}, handler); | ||
export async function parse(code) { | ||
export function parse(code) { | ||
const raw = integrate(code); | ||
const sn = await starryNight; | ||
if (starryNightCache == null) throw new Error(`you must await ready()`); | ||
const sn = starryNightCache; | ||
const scope = sn.flagToScope(code.language); | ||
@@ -162,5 +167,5 @@ | ||
export async function diff(start, end) { | ||
const startParsed = chars(await parse(start)); | ||
const endParsed = chars(await parse(end)); | ||
export function diff(start, end) { | ||
const startParsed = chars(parse(start)); | ||
const endParsed = chars(parse(end)); | ||
let index = 0; | ||
@@ -167,0 +172,0 @@ let endex = 0; |
@@ -0,1 +1,7 @@ | ||
import type { Root } from 'hast'; | ||
export interface StarryNight { | ||
flagToScope: (flag: string) => string | undefined; | ||
highlight: (value: string, scope: string) => Root; | ||
} | ||
export declare function ready(): Promise<void>; | ||
export interface CodeTree { | ||
@@ -15,5 +21,5 @@ language: string; | ||
} | ||
export declare function parse(code: CodeTree): Promise<Token[]>; | ||
export declare function parse(code: CodeTree): Token[]; | ||
export declare function getColor(classList: string[]): string | undefined; | ||
export declare function diff(start: CodeTree, end: CodeTree): Promise<(Token | null)[]>; | ||
export declare function diff(start: CodeTree, end: CodeTree): (Token | null)[]; | ||
//# sourceMappingURL=tags.d.ts.map |
{ | ||
"name": "code-fns", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "A library for visualizing code.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -34,4 +34,5 @@ # code-fns | ||
```tsx | ||
import { language, parse } from './tags'; | ||
import { ready, language, parse } from './tags'; | ||
await ready(); | ||
const tsx = language.tsx; | ||
@@ -55,4 +56,5 @@ await parse(tsx`() => true`); | ||
```tsx | ||
import { language, parse } from './tags'; | ||
import { ready, language, parse } from './tags'; | ||
await ready(); | ||
const tsx = language.tsx; | ||
@@ -74,4 +76,5 @@ const generate = (result: string) => tsx`(${result});`; | ||
```tsx | ||
import { language, diff } from './tags'; | ||
import { ready, language, diff } from './tags'; | ||
await ready(); | ||
const tsx = language.tsx; | ||
@@ -78,0 +81,0 @@ const generate = (result: string) => tsx`(${result});`; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28455
877
93