notion-to-md 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -167,10 +167,16 @@ const n2m = new notion2md({ notionClient: notion });
167
167
 
168
168
  ### Converting a single block to markdown string
169
169
 
170
- - just takes a single notion block and returns corresponding markdown string
170
+ - only takes a single notion block and returns corresponding markdown string
171
171
  - nesting is ignored
172
+ - not dependent on @notionhq/client
172
173
 
173
174
  ```js
175
+ const notion2md = require("notion-to-md");
176
+
177
+ // notion client not required
178
+ const n2m = new notion2md();
179
+
174
180
  const result = n2m.blockToMarkdown(block);
175
181
  console.log(result);
176
182
  ```
package/notion-to-md.js CHANGED
@@ -3,11 +3,11 @@ const { getBlockChildren } = require("./utils/notion");
3
3
 
4
4
  class notion2md {
5
5
  constructor(options) {
6
- if (!options || !options.notionClient)
7
- throw new Error(
8
- "notion2md takes notion client as argument, for more details check out https://github.com/souvikinator/notion2md"
9
- );
10
- this.notionClient = options.notionClient;
6
+ if (!options) {
7
+ this.notionClient = undefined;
8
+ } else {
9
+ this.notionClient = options.notionClient || undefined;
10
+ }
11
11
  }
12
12
 
13
13
  toMarkdownString(mdBlocks = [], nestingLevel = 0) {
@@ -37,6 +37,12 @@ ${md.addTabSpace(mdBlocks.parent, nestingLevel)}
37
37
  * @returns array of md blocks with their children
38
38
  */
39
39
  async blocksToMarkdown(blocks, mdBlocks = []) {
40
+ if (!this.notionClient) {
41
+ throw new Error(
42
+ "notion client is not provided, for more details check out https://github.com/souvikinator/notion-to-md"
43
+ );
44
+ }
45
+
40
46
  for (let i = 0; i < blocks.length; i++) {
41
47
  let block = blocks[i];
42
48
  if (block.has_children) {
@@ -58,6 +64,8 @@ ${md.addTabSpace(mdBlocks.parent, nestingLevel)}
58
64
  * @returns markdown form of the passed block
59
65
  */
60
66
  blockToMarkdown(block) {
67
+ if (!block) throw new Error("notion block required");
68
+
61
69
  let parsedData = "",
62
70
  blockContent;
63
71
  const { type } = block;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notion-to-md",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "main": "notion-to-md.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/utils/notion.js CHANGED
@@ -1,5 +1,10 @@
1
1
  exports.getBlockChildren = async (notionClient, block_id) => {
2
2
  try {
3
+ if (!notionClient) {
4
+ throw new Error(
5
+ "notion client is not provided, for more details check out https://github.com/souvikinator/notion-to-md"
6
+ );
7
+ }
3
8
  const response = await notionClient.blocks.children.list({
4
9
  block_id,
5
10
  });