Skip to content

Commit

Permalink
Enhancement | Added serialization & cleaned up API (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
zrosenbauer authored Jul 15, 2023
1 parent 52de285 commit 1fffc59
Show file tree
Hide file tree
Showing 14 changed files with 1,092 additions and 113 deletions.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div>
<p align="center">
<img src="/logo.png" align="center" width="240" />
<img src="./logo.png" align="center" width="240" />
</p>
<hr>
<blockquote align="center">
Expand Down Expand Up @@ -86,6 +86,32 @@ fs.writeFile('myFile.md', result)
});
```

## Serialized Data (⚠️ Unstable API ⚠️)

Tempo creates a syntax tree that can be serialized and stored in a data base.

```typescript
import db from 'db/orm';
import tempo from '@joggrdocs/tempo';

const result = tempo()
.h1('Hello World')
.paragraph('Some things')
.paragraph((txt) =>
txt
.text('A sentence with')
.bold('bolded words')
.text('and')
.italic('italicized words')
.text('.')
.build()
)
.toJSON();

// Example of storing a serializable data object to the DB
await db.collection('tempoDoc').findAndSave(1, result);
```

### Credits

- Logo by [Time management icons created by Freepik - Flaticon](https://www.flaticon.com/free-icons/time-management)
9 changes: 9 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ const config: JestConfigWithTsJest = {
roots: ['<rootDir>/src'],
testMatch: ['**/__tests__/**/*.test.ts'],
testPathIgnorePatterns: ['dist', '/node_modules/'],
collectCoverageFrom: ['src/**/*.ts'],
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100
}
},
transform: {
'^.+\\.(ts|tsx)$': [
'ts-jest',
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Library used to programmatically build markdown documents, with a heavy tilt toward GitHub Flavored Markdown (GFM).",
"main": "dist/index.js",
"scripts": {
"test": "jest",
"test": "jest --coverage",
"build": "tsc",
"build:examples": "ts-node examples/index.ts",
"format:check": "prettier --check .",
Expand Down
12 changes: 12 additions & 0 deletions src/__tests__/exports.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import tempo, { Document, Text } from '../index';
import { Document as DocumentClass } from '../lib/Document';
import { Text as TextClass } from '../lib/Text';

describe('tempo', () => {
it('should export the correct types', () => {
expect(typeof tempo).toBe('function');
expect(tempo()).toBeInstanceOf(DocumentClass);
expect(new Document()).toBeInstanceOf(DocumentClass);
expect(new Text()).toBeInstanceOf(TextClass);
});
});
Loading

0 comments on commit 1fffc59

Please sign in to comment.