Skip to content

Commit 32a49d8

Browse files
committed
init: first commit
0 parents  commit 32a49d8

14 files changed

+3203
-0
lines changed

.clean-publish

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"cleanDocs": true
3+
}

.gitignore

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# dependencies
2+
node_modules
3+
.pnp
4+
.pnp.js
5+
6+
# testing
7+
coverage
8+
9+
# production
10+
dist
11+
build
12+
13+
# dotenv environment variables file
14+
.env
15+
.env.local
16+
.env.development.local
17+
.env.test.local
18+
.env.production.local
19+
20+
# logs
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
25+
# misc
26+
.DS_Store
27+
.idea

.nano-staged.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"*.{js,ts,tsx,md}": ["prettier --write"]
3+
}

.prettierrc.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'semi': false
2+
'trailingComma': 'es5'
3+
'singleQuote': true
4+
'bracketSameLine': true
5+
'tabWidth': 2
6+
'printWidth': 80

LICENCE

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Tinyhighlight core license
2+
3+
MIT License
4+
5+
Copyright (c) 2023 Tinylibs
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
# Additionaly Tinyhighlight modifies code with the following licenses:
26+
27+
MIT
28+
29+
## @babel/highlight
30+
31+
MIT License
32+
33+
Copyright (c) 2014-present Sebastian McKenzie and other contributors
34+
35+
Permission is hereby granted, free of charge, to any person obtaining
36+
a copy of this software and associated documentation files (the
37+
"Software"), to deal in the Software without restriction, including
38+
without limitation the rights to use, copy, modify, merge, publish,
39+
distribute, sublicense, and/or sell copies of the Software, and to
40+
permit persons to whom the Software is furnished to do so, subject to
41+
the following conditions:
42+
43+
The above copyright notice and this permission notice shall be
44+
included in all copies or substantial portions of the Software.
45+
46+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
47+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
48+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
49+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
50+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
51+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
52+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
53+
54+
## @babel/helper-validator-identifier
55+
56+
MIT License
57+
58+
Copyright (c) 2014-present Sebastian McKenzie and other contributors
59+
60+
Permission is hereby granted, free of charge, to any person obtaining
61+
a copy of this software and associated documentation files (the
62+
"Software"), to deal in the Software without restriction, including
63+
without limitation the rights to use, copy, modify, merge, publish,
64+
distribute, sublicense, and/or sell copies of the Software, and to
65+
permit persons to whom the Software is furnished to do so, subject to
66+
the following conditions:
67+
68+
The above copyright notice and this permission notice shall be
69+
included in all copies or substantial portions of the Software.
70+
71+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
72+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
73+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
74+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
75+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
76+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
77+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# tinyhighlight
2+
3+
> minimal fork of @babel/highlight 🌈
4+
5+
This fork of [`@babel/highlight`](https://www.npmjs.com/package/@babel/highlight) tries to be the most compact library you can use to stylize JS/TS/JSX/TSX code.
6+
7+
## Usage
8+
9+
Changes made to `@babel/highlight`:
10+
11+
- Updated [`js-tokens`](https://github.com/lydell/js-tokens) (which adds more code, but it is up-to-date with the latest standards)
12+
- `chalk` is replaced with `picocolors`
13+
- Two methods from `@babel/helper-validator-identifier` are inlined to save space
14+
- Introduced a token type for methods (`IdentifierMethodName`/`PrivateIdentifierMethodName`)
15+
- This package is ESM-only
16+
17+
API is not compatible with `@babel/highlight` because we use the latest `js-tokens` version.
18+
19+
This package provides two entry points:
20+
21+
- The default module exposes `highlight` method without any styling.
22+
23+
```js
24+
import { highlight } from 'tinyhighlight'
25+
highlight('const answer = 42', {
26+
jsx: false,
27+
colors: provideYourOwnColors(),
28+
})
29+
```
30+
31+
> [!TIP]
32+
> You can use `colors` option to provide color methods. If you support JSX, make sure to provide JSX-named colors because they use a separate token identifier.
33+
34+
- The `./picocolors` entry point exposes `highlight` method that uses [`picocolors`](https://www.npmjs.com/package/picocolors) for styling:
35+
36+
```js
37+
import { highlight } from 'tinyhighlight/picocolors'
38+
highlight('const answer = 42', { jsx: false })
39+
```
40+
41+
> [!WARNING]
42+
> This package doesn't install `picocolors` automatically, you need to add it to your own dependencies if you use this option
43+
44+
## Token Types
45+
46+
You can look at [`js-tokens`](https://github.com/lydell/js-tokens) documentation to read about most of the tokens. On top of that, `tinyhighlight` also provides these tokens:
47+
48+
**IdentifierMethodName**
49+
50+
This is an `Identifier` that has a bracket (`(`) after it. `someName` is `IdentifierMethodName` in all of these examples:
51+
52+
```
53+
someName()
54+
property.someName()
55+
function someName() {}
56+
class Test {
57+
someName() {}
58+
}
59+
```
60+
61+
**PrivateIdentifierMethodName**
62+
63+
This is a `PrivateIdentifier` that has a bracket (`(`) after it. `#someName` (`#` is also part of the value) is `IdentifierMethodName` in all of these examples:
64+
65+
```
66+
this.#someName()
67+
class Test {
68+
#someName() {}
69+
}
70+
```
71+
72+
**IdentifierCapitalized**
73+
74+
This is an `Identifier` that starts with a capital letter. For example:
75+
76+
```
77+
Test
78+
class Test {}
79+
function Test() {}
80+
function(Test) {}
81+
```
82+
83+
**Keyword**
84+
85+
This is a potential `Identifier` that uses a reserved name. For example (not a full list):
86+
87+
```
88+
const
89+
export
90+
null
91+
true
92+
protected
93+
public
94+
void
95+
this
96+
```
97+
98+
**Bracket**
99+
100+
This is a `Punctuator` equal to one of `[`, `]`, `{`, `}`, `(`, `)`.

index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './dist/index.js'

package.json

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"name": "tinyhighlight",
3+
"version": "0.0.1",
4+
"type": "module",
5+
"packageManager": "[email protected]",
6+
"scripts": {
7+
"dev": "tsup --watch",
8+
"build": "tsup",
9+
"prepare": "husky install",
10+
"publish-test": "clean-publish --without-publish",
11+
"release": "node ./tools/clean-banner.js && bumpp package.json --commit --push --tag && tsup && clean-publish && node ./tools/return-banner.js",
12+
"test": "vitest --single-thread"
13+
},
14+
"main": "./dist/index.cjs",
15+
"module": "./dist/index.js",
16+
"types": "./dist/index.d.ts",
17+
"exports": {
18+
".": {
19+
"types": "./dist/index.d.ts",
20+
"import": "./dist/index.js",
21+
"require": "./dist/index.js"
22+
},
23+
"./picocolors": {
24+
"types": "./dist/picocolors.d.ts",
25+
"import": "./dist/picocolors.js",
26+
"default": "./dist/picocolors.js"
27+
}
28+
},
29+
"files": [
30+
"dist/**",
31+
"*.d.ts"
32+
],
33+
"repository": {
34+
"type": "git",
35+
"url": "git+https://github.com/tinylibs/tinyhighlight.git"
36+
},
37+
"license": "MIT",
38+
"bugs": {
39+
"url": "https://github.com/tinylibs/tinyhighlight/issues"
40+
},
41+
"homepage": "https://github.com/tinylibs/tinyhighlight#readme",
42+
"peerDependencies": {
43+
"picocolors": "^1.0.0"
44+
},
45+
"peerDependenciesMeta": {
46+
"picocolors": {
47+
"optional": true
48+
}
49+
},
50+
"devDependencies": {
51+
"@size-limit/preset-small-lib": "^7.0.4",
52+
"@size-limit/time": "^7.0.4",
53+
"bumpp": "^8.2.0",
54+
"changelogithub": "^0.6.6",
55+
"clean-publish": "^3.4.4",
56+
"husky": "^7.0.4",
57+
"js-tokens": "^8.0.2",
58+
"nano-staged": "^0.5.0",
59+
"picocolors": "^1.0.0",
60+
"prettier": "^2.5.1",
61+
"size-limit": "^7.0.4",
62+
"tsup": "^5.11.7",
63+
"typescript": "^4.5.4",
64+
"vitest": "^0.34.6"
65+
},
66+
"keywords": [
67+
"highlight",
68+
"code",
69+
"syntax"
70+
],
71+
"engines": {
72+
"node": ">=14.0.0"
73+
}
74+
}

picocolors.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './dist/colors.js'

0 commit comments

Comments
 (0)