The essential toolkit for web-developers
Installations
npm install @emmetio/abbreviation
Score
99.7
Supply Chain
92.8
Quality
78.5
Maintenance
100
Vulnerability
100
License
Developer
Developer Guide
Module System
ESM
Min. Node Version
Typescript Support
Yes
Node Version
16.16.0
NPM Version
lerna/6.5.1/node@v16.16.0+x64 (darwin)
Statistics
4,479 Stars
278 Commits
519 Forks
155 Watching
3 Branches
48 Contributors
Updated on 29 Nov 2024
Bundle Size
13.46 kB
Minified
4.80 kB
Minified + Gzipped
Languages
TypeScript (99.39%)
JavaScript (0.61%)
Total Downloads
Cumulative downloads
Total Downloads
32,133,179
Last day
-16.6%
50,495
Compared to previous day
Last week
-4%
327,780
Compared to previous week
Last month
6.4%
1,412,497
Compared to previous month
Last year
53.6%
14,414,574
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Emmet — the essential toolkit for web-developers
Emmet is a web-developer’s toolkit for boosting HTML & CSS code writing.
With Emmet, you can type expressions (abbreviations) similar to CSS selectors and convert them into code fragment with a single keystroke. For example, this abbreviation:
ul#nav>li.item$*4>a{Item $}
...can be expanded into:
1<ul id="nav"> 2 <li class="item1"><a href="">Item 1</a></li> 3 <li class="item2"><a href="">Item 2</a></li> 4 <li class="item3"><a href="">Item 3</a></li> 5 <li class="item4"><a href="">Item 4</a></li> 6</ul>
Features
- Familiar syntax: as a web-developer, you already know how to use Emmet. Abbreviation syntax is similar to CSS Selectors with shortcuts for id, class, custom attributes, element nesting and so on.
- Dynamic snippets: unlike default editor snippets, Emmet abbreviations are dynamic and parsed as-you-type. No need to predefine them for each project, just type
MyComponent>custom-element
to convert any word into a tag. - CSS properties shortcuts: Emmet provides special syntax for CSS properties with embedded values. For example,
bd1-s#f.5
will be expanded toborder: 1px solid rgba(255, 255, 255, 0.5)
. - Available for most popular syntaxes: use single abbreviation to produce code for most popular syntaxes like HAML, Pug, JSX, SCSS, SASS etc.
Read more about Emmet features
This repo contains only core module for parsing and expanding Emmet abbreviations. Editor plugins are available as separate repos.
This is a monorepo: top-level project contains all the code required for converting abbreviation into code fragment while ./packages
folder contains modules for parsing abbreviations into AST and can be used independently (for example, as lexer for syntax highlighting).
Installation
You can install Emmet as a regular npm module:
1npm i emmet
Usage
To expand abbreviation, pass it to default function of emmet
module:
1import expand from 'emmet'; 2 3console.log(expand('p>a')); // <p><a href=""></a></p>
By default, Emmet expands markup abbreviation, e.g. abbreviation used for producing nested elements with attributes (like HTML, XML, HAML etc.). If you want to expand stylesheet abbreviation, you should pass it as a type
property of second argument:
1import expand from 'emmet'; 2 3console.log(expand('p10', { type: 'stylesheet' })); // padding: 10px;
A stylesheet abbreviation has slightly different syntax compared to markup one: it doesn’t support nesting and attributes but allows embedded values in element name.
Alternatively, Emmet supports syntaxes with predefined snippets and options:
1import expand from 'emmet'; 2 3console.log(expand('p10', { syntax: 'css' })); // padding: 10px; 4console.log(expand('p10', { syntax: 'stylus' })); // padding 10px
Predefined syntaxes already have type
attribute which describes whether given abbreviation is markup or stylesheet, but if you want to use it with your custom syntax name, you should provide type
config option as well (default is markup
):
1import expand from 'emmet'; 2 3console.log(expand('p10', { 4 syntax: 'my-custom-syntax', 5 type: 'stylesheet', 6 options: { 7 'stylesheet.between': '__', 8 'stylesheet.after': '', 9 } 10})); // padding__10px
You can pass options
property as well to shape-up final output or enable/disable various features. See src/config.ts
for more info and available options.
Extracting abbreviations from text
A common workflow with Emmet is to type abbreviation somewhere in source code and then expand it with editor action. To support such workflow, abbreviations must be properly extracted from source code:
1import expand, { extract } from 'emmet'; 2 3const source = 'Hello world ul.tabs>li'; 4const data = extract(source, 22); // { abbreviation: 'ul.tabs>li' } 5 6console.log(expand(data.abbreviation)); // <ul class="tabs"><li></li></ul>
The extract
function accepts source code (most likely, current line) and character location in source from which abbreviation search should be started. The abbreviation is searched in backward direction: the location pointer is moved backward until it finds abbreviation bound. Returned result is an object with abbreviation
property and start
and end
properties which describe location of extracted abbreviation in given source.
Most current editors automatically insert closing quote or bracket for (
, [
and {
characters so when user types abbreviation that uses attributes or text, it will end with the following state (|
is caret location):
ul>li[title="Foo|"]
E.g. caret location is not at the end of abbreviation and must be moved a few characters ahead. The extract
function is able to handle such cases with lookAhead
option (enabled by default). This this option enabled, extract
method automatically detects auto-inserted characters and adjusts location, which will be available as end
property of the returned result:
1import { extract } from 'emmet';
2
3const source = 'a div[title] b';
4const loc = 11; // right after "title" word
5
6// `lookAhead` is enabled by default
7console.log(extract(source, loc)); // { abbreviation: 'div[title]', start: 2, end: 12 }
8console.log(extract(source, loc, { lookAhead: false })); // { abbreviation: 'title', start: 6, end: 11 }
By default, extract
tries to detect markup abbreviations (see above). stylesheet abbreviations has slightly different syntax so in order to extract abbreviations for stylesheet syntaxes like CSS, you should pass type: 'stylesheet'
option:
1import { extract } from 'emmet'; 2 3const source = 'a{b}'; 4const loc = 3; // right after "b" 5 6console.log(extract(source, loc)); // { abbreviation: 'a{b}', start: 0, end: 4 } 7 8 9// Stylesheet abbreviations does not have `{text}` syntax 10console.log(extract(source, loc, { type: 'stylesheet' })); // { abbreviation: 'b', start: 2, end: 3 }
Extract abbreviation with custom prefix
Lots of developers uses React (or similar) library for writing UI code which mixes JS and XML (JSX) in the same source code. Since any Latin word can be used as Emmet abbreviation, writing JSX code with Emmet becomes pain since it will interfere with native editor snippets and distract user with false positive abbreviation matches for variable names, methods etc.:
1var div // `div` is a valid abbreviation, Emmet may transform it to `<div></div>`
A possible solution for this problem it to use prefix for abbreviation: abbreviation can be successfully extracted only if its preceded with given prefix.
1import { extract } from 'emmet'; 2 3const source1 = '() => div'; 4const source2 = '() => <div'; 5 6extract(source1, source1.length); // Finds `div` abbreviation 7extract(source2, source2.length); // Finds `div` abbreviation too 8 9extract(source1, source1.length, { prefix: '<' }); // No match, `div` abbreviation is not preceded with `<` prefix 10extract(source2, source2.length, { prefix: '<' }); // Finds `div` since it preceded with `<` prefix
With prefix
option, you can customize your experience with Emmet in any common syntax (HTML, CSS and so on) if user is distracted too much with Emmet completions for any typed word. A prefix
may contain multiple character but the last one must be a character which is not part of Emmet abbreviation. Good candidates are <
, &
, →
(emoji or Unicode symbol) and so on.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
9 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 7
Reason
Found 14/30 approved changesets -- score normalized to 4
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/emmetio/emmet/node.js.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/emmetio/emmet/node.js.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/node.js.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 14 are checked with a SAST tool
Reason
17 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-8hc4-vh64-cxmj
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-2j2x-2gpw-g8fm
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
Score
3.7
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to @emmetio/abbreviation
@emmetio/css-abbreviation
Parses Emmet CSS abbreviation into AST tree
emmet
Emmet — the essential toolkit for web-developers
@emmetio/html-transform
Prepares given Emmet abbreviation for HTML output
@emmetio/markup-formatters
Formats and outputs Emmet abbreviation in different markup languages (HTML, XML, Slim, Pug etc)