Skip to content

Commit

Permalink
update exports style, add types
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzha0 committed Feb 11, 2022
1 parent c25c76e commit c71bab6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ The package exports a function called `createTelescopicText` that returns a HTML
Basic usage may look something like this:

```html
<head>
<script src="https://unpkg.com/telescopic-text/index.js"></script>
<link href="https://unpkg.com/telescopic-text/index.css" rel="stylesheet">
</head>
<div id="text-container"></div>

<script>
Expand All @@ -33,4 +37,22 @@ Basic usage may look something like this:
const container = document.getElementById("text-container")
container.appendChild(node)
</script>
```

## Types
```typescript
interface Content {
text: string // Original string content in the line
replacements: Line[] // Sections of the original text to replace/expand
}

interface Line {
og: string // the original string to replace
new: string // the replacement string
replacements: Line[] // nested replacements to apply on the resultant line afterwards
}

// Default function to create a new `<div>` node containing the
// telescoping text.
function createTelescopicText(content: Content[])
```
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
// interface Line {
// og: string // the original string to replace
// new: string // the replacement string
// replacement: Line[] // nested replacements to apply on the resultant line afterwards
// replacements: Line[] // nested replacements to apply on the resultant line afterwards
// }
// ```
export function hydrate(line, node) {
function hydrate(line, node) {
let lineText = line.text || line.og

if (line.replacements.length > 0) {
Expand Down Expand Up @@ -80,7 +80,7 @@ export function hydrate(line, node) {
// replacements: Line[] // Sections of the original text to replace/expand
// }
// ```
export function createTelescopicText(content) {
function createTelescopicText(content) {
const letter = document.createElement("div")
letter.id = "telescope"
content.forEach(line => {
Expand All @@ -94,4 +94,6 @@ export function createTelescopicText(content) {
return letter
}


module.exports = {
createTelescopicText, hydrate
}

0 comments on commit c71bab6

Please sign in to comment.