
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fixβa new CLI tool that turns CVE alerts into safe, automated upgrades.
sveltedoc-parser
Advanced tools
Generate a JSON documentation for a Svelte file.
self
and trusted
event modifiers [Issue #80].JSDocTypeFunction
to support functions types in variable definitions and provide details about function parameters and methods.JSDocType
to support new JSDocTypeFunction
.array
, object
, function
.@type {import('../typings.d.ts').ExternalTypeClass}
. In order to do this, new field importPath
introduced to JSDocType
, in the name property now it returns imported class name, f.ex.: ExternalTypeClass
.typings.d.ts
file.SvelteSlotParameter
definition, to support name
, description
, type
fields, instead of many not relevant fields that was inherited from ISvelteItem
interface.SvelteSlotItem
definition, to improve consistency:
parameters
property to params
to be most likely the same as SvelteMethodItem
. Old field still available until 5.* release.Thanks a lot @soft-decay for contributing in this release!
args
property renamed to params
;return
item for methods:
desc
property renamed to description
;type
property now contains a JSDocType
object instead of a string
with a text representation of the type. This text representation is still available from the text
property of the JSDocType
object;SvelteMethodParamItem
type;loc
property removed: Use locations
instead;value
property of SvelteComponentItem
removed: Use importPath
instead;Full changelog of release versions can be found here.
npm install --save sveltedoc-parser
@public
, @protected
, @private
@type {string}
) or parse default value if is not provided<button on:click>...</button>
... on:click|once
slots
@param {string} parameter
)@param [parameter]
) or using Google ClosureCompiler syntax (@param {string=} parameter
)
@param [parameter=Default value]
)fire(...)
methodprivate
visibility scope@component
. Example script, Example htmlThe options
object passed to the parse
function must include filename
or fileContent
.
Here are the properties supported by options
(see the Usage section below):
json Path | Description | Type | Default value |
---|---|---|---|
filename | The filename to parse. Required, unless fileContent is passed. | string | |
fileContent | The file content to parse. Required, unless filename is passed. | string | |
encoding | The file encoding. | string | utf8 |
features | The component features to parse and extract. | string[] | All supported features |
ignoredVisibilities | The list of ignored visibilities. Symbols with a visibility that is ignored will not be included in the output. | string[] | ['private', 'protected'] |
includeSourceLocations | Flag, which indicates that source locations should be provided for component symbols. | boolean | false |
version | Optional. Use 2 or 3 to specify which svelte syntax should be used. When that is not provided, parser try to detect version of the syntax. | number? | undefined |
defaultVersion | Optional. Specify default version of svelte syntax, if auto-detector can't identify correct version. | number? | undefined |
These are the values that can be included in the options.features
array:
Feature | Svelte 2 | Svelte 3 | Description |
---|---|---|---|
name | β | β | Component's name |
description | β | β | Component's description |
keywords | β | β | List of JSDoc keywords found in the top level comment |
components | β | β | List of imported components |
computed | β | β | List of computed properties |
data | β | β | List of data properties (Component's props) |
events | β | β | List of events fired/dispatched by this component |
methods | β | β | List of methods |
refs | β | β | List of references used by this component |
slots | β | β | List of slots provided by this component |
actions | β | List of actions | |
helpers | β | List of helpers | |
transitions | β | List of transitions used by this component | |
store | NOT SUPPORTED |
Output format is described in this document.
For Svelte 3 examples, take a look at the examples folder to check how Svelte 3 components are transformed to JSON documents.
For a Svelte 2 example, take a look at the JSON output generated from this component.
Minimal example:
const sveltedoc = require('sveltedoc-parser');
const options = {
filename: 'main.svelte'
};
sveltedoc.parse(options)
.then(componentDoc => {
console.log(componentDoc);
})
.catch(e => {
console.error(e);
});
or with options customization:
const { parse } = require('sveltedoc-parser');
const { externalFileContent } = require('./local-file');
const options = {
fileContent: externalFileContent,
encoding: 'ascii',
features: ['data', 'computed', 'methods'],
ignoredVisibilities: ['private'],
includeSourceLocations: true,
version: 3
};
const doc = await parse(options);
console.log(doc)
Method to parse svelte component and provide doc object structure with details information.
Method to detect the Svelte syntax used in the component. It returns, in order:
options.version
, if present; else2
or 3
if Svelte 2 syntax or Svelte 3 syntax is detected, respectively; elseoptions.defaultVersion
, if present; elseundefined
if the function failed to detect the syntax to useA list of known issues can be found here.
Found a new issue? Please contribute and write a detailed description here.
Author Alexey Mulyukin
Inspired by Vuedoc Parser
FAQs
Generate a JSON documentation for a Svelte file
The npm package sveltedoc-parser receives a total of 103,220 weekly downloads. As such, sveltedoc-parser popularity was classified as popular.
We found that sveltedoc-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Β It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Automatically fix and test dependency updates with socket fixβa new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
Weβre excited to announce a powerful new capability in Socket: historical data and enhanced analytics.