Socket
Socket
Sign inDemoInstall

sveltedoc-parser

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sveltedoc-parser - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

CHANGELOG.md

98

lib/jsdoc.js
const PARAM_NAME = '[a-z0-9$\\.\\[\\]_]+';
const TYPE = '[a-z\\[\\]|\\. \\*]*';
const TYPE = '[a-z\\[\\]|\\.\\s\\*\\\']*';
const TYPE_RE = new RegExp(`^\\s*\\{(${TYPE})\\}`, 'i');
const PARAM_RE = new RegExp(`^\\s*(\\{\\(?(${TYPE})\\)?\\}\\s+)?(${PARAM_NAME}|\\[(${PARAM_NAME})(=(.*))?\\])\\s+-?\\s*(.*)`, 'i');
const RETURN_RE = new RegExp(`^\\s*(\\{\\(?(${TYPE})\\)?\\}\\s+)?-?(.*)`, 'i');
const DEFAULT_TYPE = 'Any';
const DEFAULT_TYPE = 'any';
function parseType(type, param) {

@@ -20,4 +23,86 @@ if (type.indexOf('|') > -1) {

function parseJSDocType(typeValue) {
if (typeValue.indexOf('|') > -1) {
const types = typeValue.split('|');
return {
'kind': 'union',
'text': typeValue,
'type': types
.map(type => parseJSDocType(type))
.filter(type => type != null)
}
}
if (typeValue.startsWith('\'') && typeValue.endsWith('\'')) {
return {
'kind': 'const',
'text': typeValue,
'type': 'string',
'value': typeValue.substr(1, typeValue.length - 2)
}
}
if (typeValue === '*') {
return {
'kind': 'type',
'text': typeValue,
'type': DEFAULT_TYPE
}
}
return {
'kind': 'type',
'text': typeValue,
'type': typeValue
}
}
function parseJSTypeFromValueNode(valueNode) {
if (valueNode == null) {
return null;
}
if (valueNode.type === 'ArrayExpression') {
return {
'kind': 'type',
'text': 'Array<any>',
'type': 'Array<any>'
};
}
if (typeof(valueNode) === 'object') {
return {
'kind': 'type',
'text': 'any',
'type': 'any'
};
}
return {
'kind': 'type',
'text': typeof(valueNode),
'type': typeof(valueNode)
};
}
function parseTypeKeyword(text) {
const match = TYPE_RE.exec(text);
if (match) {
const typeValue = match[1];
if (typeValue) {
return parseJSDocType(typeValue);
}
}
return null;
}
function parseParamKeyword(text) {
const param = { type: DEFAULT_TYPE, name: null, desc: null };
const param = {
type: DEFAULT_TYPE,
name: null,
description: null
};
const matches = PARAM_RE.exec(text);

@@ -41,3 +126,3 @@

param.desc = matches[7];
param.description = matches[7];
}

@@ -64,2 +149,5 @@

module.exports.parseReturnKeyword = parseReturnKeyword;
module.exports.DEFAULT_TYPE = DEFAULT_TYPE;
module.exports.parseTypeKeyword = parseTypeKeyword;
module.exports.parseJSTypeFromValueNode = parseJSTypeFromValueNode;
module.exports.DEFAULT_TYPE = DEFAULT_TYPE;

@@ -28,3 +28,15 @@ const EventEmitter = require('events');

const SUPPORTED_FEATURES = [
'data', 'computed', 'methods', 'actions', 'helpers', 'components', 'description', 'events', 'slots', 'transitions', 'refs'
'name',
'data',
'computed',
'methods',
'actions',
'helpers',
'components',
'description',
'events',
'slots',
'transitions',
'refs',
'store'
];

@@ -184,2 +196,33 @@

entry.args = entry.value.params.map((param) => param.name);
} else if (property.key.name === 'data') {
const typeKeyword = entry.keywords.find(kw => kw.name === 'type');
if (typeKeyword) {
const parsedType = jsdoc.parseTypeKeyword(typeKeyword.description);
if (parsedType) {
entry.type = parsedType;
}
}
// If type can't be pased, but value are suplied, try to parse it
if (!entry.type) {
if (entry.hasOwnProperty('value')) {
const parsedType = jsdoc.parseJSTypeFromValueNode(entry.value);
if (parsedType) {
entry.type = parsedType;
} else {
entry.type = {
'kind': 'type',
'text': 'any',
'type': 'any'
};
}
} else {
entry.type = {
'kind': 'type',
'text': 'any',
'type': 'any'
};
}
}
}

@@ -186,0 +229,0 @@

2

package.json
{
"name": "sveltedoc-parser",
"version": "1.0.0",
"version": "1.1.0",
"description": "Generate a JSON documentation for a Svelte file",

@@ -5,0 +5,0 @@ "main": "index.js",

# The sveltedoc parser
## Key Features
Generate a JSON documentation for a Svelte file
[![npm](https://img.shields.io/npm/v/sveltedoc-parser.svg)](https://www.npmjs.com/package/sveltedoc-parser)
Changelog of release versions can be found [here](/CHANGELOG.md)
## Install
```shell
npm install --save sveltedoc-parser
```
## Features
- JSDoc support
- Extract the component description from JSDoc
- Extract used components list (with short or reference notations)
- Support description extraction for everything items
- Support visibility scope from JSDoc keywords: `@public`, `@protected`, `@private`
- Extract list of imported components
- Extract relative path to imported component (supports full-syntax and short-syntax import styles)
- Extract data properties
- Extract computed properties with dependencies
- Extract events that fired by this component
- Extract events that propogated from child component
- Extract custom implemented events
- Extract description from JSDoc comment
- Extract JS type from JSDoc (`@type {string}`) or parse default value if is not provided
- Extract computed properties with list of dependencies
- Extract list of references that attached to components or HTML elements
- Extract all fired events
- Events that fired by this component by `fire(...)` method
- Events that propogated from child component or HTML elements
- Custom event handlers with `private` visibility scope
- Extract list of used default and named `slots`

@@ -17,3 +35,3 @@ - Extract component methods

- Extract component actions
- Extract used `refs` in template nodes
- Extract component transitions

@@ -26,9 +44,48 @@ ## Configuration

| **fileContent** | The file content to parse. **Required**, unless `filename` is passed. | |
| **encoding** | The file encoding. | 'utf8' |
| **features** | The component features to parse and extracting. | By default used all supported features. |
| **encoding** | The file encoding. | `utf8` |
| **features** | The component features to parse and extracting. | By default used all supported features (see below). |
| **ignoredVisibilities** | The list of ignored visibilities. | `['private', 'protected']` |
### Supported feature names
- `'name'` - Extract the component name.
- `'data'` - Extract and parse the list of component data properties.
- `'computed'` - Extract and parse the list of component computed properties.
- `'methods'` - Extract the list of component methods.
- `'actions'` - Extract the list of component actions.
- `'helpers'` - Extract the list of component helpers.
- `'components'` - Extract the list of imported components.
- `'description'` - Extract the component description.
- `'events'` - Extract the list of events that fired by this component.
- `'slots'` - Extract the list of slots provided by this component.
- `'transitions'` - Extract the list of transitions used by this component.
- `'refs'` - Extract the list of references used by this component.
## Output format
Output format are described at [this document](/typings.d.ts).
See example of output [here](/test/overall/overall.main.doc.json) presented in JSON format for [this component](/test/overall/main.svelte).
## Usage
```js
const sveltedoc = require('sveltedoc-parser');
const options = {
filename: 'main.svelte'
};
sveltedoc.parse(options)
.then(componentDoc => {
console.log(componentDoc);
})
.catch(e => {
console.error(e);
});
```
## Issues
All list of known issues presented at [this page](https://github.com/alexprey/sveltedoc-parser/issues).
Found a new issues? Please contribute and write detailed description [here](https://github.com/alexprey/sveltedoc-parser/issues/new).

@@ -35,0 +92,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc