Init
This commit is contained in:
21
node_modules/simple-code-frame/LICENSE
generated
vendored
Normal file
21
node_modules/simple-code-frame/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020-present Marvin Hagemeister
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
31
node_modules/simple-code-frame/README.md
generated
vendored
Normal file
31
node_modules/simple-code-frame/README.md
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
# simple-code-frame
|
||||
|
||||
Tiny library for displaying code frames. The main difference to `@babel/code-frame` is that this library doesn't ship with a parser. It is soley aimed at taking text input and adding column + line markers.
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
npm install simple-code-frame
|
||||
# or via yarn
|
||||
yarn add simple-code-frame
|
||||
```
|
||||
|
||||
Usage
|
||||
|
||||
```js
|
||||
import { createCodeFrame } from 'simple-code-frame';
|
||||
|
||||
const str = `foo\nbar\nbob`;
|
||||
|
||||
const codeFrame = createCodeFrame(str, 1, 2);
|
||||
console.log(codeFrame);
|
||||
// Logs:
|
||||
// 1 | foo
|
||||
// > 2 | bar
|
||||
// | ^
|
||||
// 3 | bob
|
||||
```
|
||||
|
||||
### License
|
||||
|
||||
`MIT`, see [the license file](./LICENSE).
|
103
node_modules/simple-code-frame/dist/cjs/index.js
generated
vendored
Normal file
103
node_modules/simple-code-frame/dist/cjs/index.js
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createCodeFrame = void 0;
|
||||
const kl = __importStar(require("kolorist"));
|
||||
/**
|
||||
* Convert tabs indentation to two spaces.
|
||||
*/
|
||||
function tabs2Spaces(str) {
|
||||
return str.replace(/^\t+/, tabs => ' '.repeat(tabs.length));
|
||||
}
|
||||
/**
|
||||
* Generate an excerpt of the location in the source around the
|
||||
* specified position.
|
||||
*/
|
||||
function createCodeFrame(text, lineNum, columnNum, { before = 2, after = 3, colors = true, maxWidth = 0, lineMarkerChar = '▶', seperatorChar = '│', columnMarkerChar = '▲' } = {}) {
|
||||
const lines = text.split('\n');
|
||||
const start = Math.max(0, lineNum - before);
|
||||
const end = Math.min(lines.length, lineNum + after + 1);
|
||||
// Maximum space needed for line numbering in the current range.
|
||||
// Necessary when the amount of digits of the line numbering grows:
|
||||
// 999 | asdf
|
||||
// 1000 | asdjadfjsa
|
||||
const maxLineNum = String(end).length;
|
||||
const padding = ' '.repeat(maxLineNum);
|
||||
// Normalize all indentation (=tabs) to use 2 spaces. We need to
|
||||
// apply the difference to the marker position to move it back in
|
||||
// place.
|
||||
const spaceLines = [];
|
||||
let maxLineLen = 0;
|
||||
for (let i = start; i < end; i++) {
|
||||
const line = tabs2Spaces(lines[i]);
|
||||
spaceLines.push(line);
|
||||
if (line.length > maxLineLen)
|
||||
maxLineLen = line.length;
|
||||
}
|
||||
const activeLine = spaceLines[lineNum - start];
|
||||
// Move marker into correct place by taking the amount of
|
||||
// normalized tabs into account
|
||||
const count = Math.max(0, activeLine.length - lines[lineNum].length + columnNum);
|
||||
const maxLensWidth = maxWidth - '> '.length - padding.length - ' | '.length;
|
||||
let left = 0;
|
||||
let right = maxLensWidth;
|
||||
if (maxWidth > 0) {
|
||||
const half = Math.floor(maxLensWidth / 2);
|
||||
let winLeft = count - half;
|
||||
if (winLeft > 0) {
|
||||
let winRight = count + half - 1;
|
||||
left = winLeft;
|
||||
right = winRight;
|
||||
if (winRight > maxLensWidth) {
|
||||
const offset = Math.min(0, winRight - maxLensWidth);
|
||||
left -= offset;
|
||||
right -= offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
const sep = kl.dim(seperatorChar);
|
||||
let out = '';
|
||||
for (let i = 0; i < spaceLines.length; i++) {
|
||||
const line = spaceLines[i];
|
||||
const currentLine = kl.dim((padding + (i + start + 1)).slice(-maxLineNum));
|
||||
let formatted = line;
|
||||
if (maxWidth > 0) {
|
||||
formatted = formatted.slice(left, Math.min(right, line.length));
|
||||
if (left > 0) {
|
||||
formatted = '…' + formatted;
|
||||
}
|
||||
if (line.length > right) {
|
||||
formatted += '…';
|
||||
}
|
||||
}
|
||||
// Line where the error occured
|
||||
if (i === lineNum - start) {
|
||||
out += kl.red(lineMarkerChar) + ` ${currentLine} ${sep} ${formatted}\n`;
|
||||
out += ` ${padding} ${sep} ${' '.repeat(count - left)}${kl.bold(kl.red(columnMarkerChar))}\n`;
|
||||
}
|
||||
else {
|
||||
out += ` ${currentLine} ${sep} ${formatted}\n`;
|
||||
}
|
||||
}
|
||||
return colors ? out : kl.stripColors(out);
|
||||
}
|
||||
exports.createCodeFrame = createCodeFrame;
|
||||
//# sourceMappingURL=index.js.map
|
1
node_modules/simple-code-frame/dist/cjs/index.js.map
generated
vendored
Normal file
1
node_modules/simple-code-frame/dist/cjs/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAE/B;;GAEG;AACH,SAAS,WAAW,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9D,CAAC;AAYD;;;GAGG;AACH,SAAgB,eAAe,CAC9B,IAAY,EACZ,OAAe,EACf,SAAiB,EAEjB,EACC,MAAM,GAAG,CAAC,EACV,KAAK,GAAG,CAAC,EACT,MAAM,GAAG,IAAI,EACb,QAAQ,GAAG,CAAC,EACZ,cAAc,GAAG,GAAG,EACpB,aAAa,GAAG,GAAG,EACnB,gBAAgB,GAAG,GAAG,KACV,EAAE;IAEf,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE/B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC;IAC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+B;QAC/B,IAAI,CAAC,KAAK,OAAO,GAAG,KAAK,EAAE;YAC1B,GAAG,IAAI,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC,GAAG,IAAI,WAAW,IAAI,GAAG,IAAI,SAAS,IAAI,CAAC;YAExE,GAAG,IAAI,KAAK,OAAO,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAC/D,EAAE,CAAC,GAAG,CAAC,gBAAgB,CAAC,CACxB,IAAI,CAAC;SACN;aAAM;YACN,GAAG,IAAI,KAAK,WAAW,IAAI,GAAG,IAAI,SAAS,IAAI,CAAC;SAChD;KACD;IAED,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;AAC3C,CAAC;AApGD,0CAoGC"}
|
80
node_modules/simple-code-frame/dist/esm/index.js
generated
vendored
Normal file
80
node_modules/simple-code-frame/dist/esm/index.js
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
import * as kl from 'kolorist';
|
||||
/**
|
||||
* Convert tabs indentation to two spaces.
|
||||
*/
|
||||
function tabs2Spaces(str) {
|
||||
return str.replace(/^\t+/, tabs => ' '.repeat(tabs.length));
|
||||
}
|
||||
/**
|
||||
* Generate an excerpt of the location in the source around the
|
||||
* specified position.
|
||||
*/
|
||||
export function createCodeFrame(text, lineNum, columnNum, { before = 2, after = 3, colors = true, maxWidth = 0, lineMarkerChar = '▶', seperatorChar = '│', columnMarkerChar = '▲' } = {}) {
|
||||
const lines = text.split('\n');
|
||||
const start = Math.max(0, lineNum - before);
|
||||
const end = Math.min(lines.length, lineNum + after + 1);
|
||||
// Maximum space needed for line numbering in the current range.
|
||||
// Necessary when the amount of digits of the line numbering grows:
|
||||
// 999 | asdf
|
||||
// 1000 | asdjadfjsa
|
||||
const maxLineNum = String(end).length;
|
||||
const padding = ' '.repeat(maxLineNum);
|
||||
// Normalize all indentation (=tabs) to use 2 spaces. We need to
|
||||
// apply the difference to the marker position to move it back in
|
||||
// place.
|
||||
const spaceLines = [];
|
||||
let maxLineLen = 0;
|
||||
for (let i = start; i < end; i++) {
|
||||
const line = tabs2Spaces(lines[i]);
|
||||
spaceLines.push(line);
|
||||
if (line.length > maxLineLen)
|
||||
maxLineLen = line.length;
|
||||
}
|
||||
const activeLine = spaceLines[lineNum - start];
|
||||
// Move marker into correct place by taking the amount of
|
||||
// normalized tabs into account
|
||||
const count = Math.max(0, activeLine.length - lines[lineNum].length + columnNum);
|
||||
const maxLensWidth = maxWidth - '> '.length - padding.length - ' | '.length;
|
||||
let left = 0;
|
||||
let right = maxLensWidth;
|
||||
if (maxWidth > 0) {
|
||||
const half = Math.floor(maxLensWidth / 2);
|
||||
let winLeft = count - half;
|
||||
if (winLeft > 0) {
|
||||
let winRight = count + half - 1;
|
||||
left = winLeft;
|
||||
right = winRight;
|
||||
if (winRight > maxLensWidth) {
|
||||
const offset = Math.min(0, winRight - maxLensWidth);
|
||||
left -= offset;
|
||||
right -= offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
const sep = kl.dim(seperatorChar);
|
||||
let out = '';
|
||||
for (let i = 0; i < spaceLines.length; i++) {
|
||||
const line = spaceLines[i];
|
||||
const currentLine = kl.dim((padding + (i + start + 1)).slice(-maxLineNum));
|
||||
let formatted = line;
|
||||
if (maxWidth > 0) {
|
||||
formatted = formatted.slice(left, Math.min(right, line.length));
|
||||
if (left > 0) {
|
||||
formatted = '…' + formatted;
|
||||
}
|
||||
if (line.length > right) {
|
||||
formatted += '…';
|
||||
}
|
||||
}
|
||||
// Line where the error occured
|
||||
if (i === lineNum - start) {
|
||||
out += kl.red(lineMarkerChar) + ` ${currentLine} ${sep} ${formatted}\n`;
|
||||
out += ` ${padding} ${sep} ${' '.repeat(count - left)}${kl.bold(kl.red(columnMarkerChar))}\n`;
|
||||
}
|
||||
else {
|
||||
out += ` ${currentLine} ${sep} ${formatted}\n`;
|
||||
}
|
||||
}
|
||||
return colors ? out : kl.stripColors(out);
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
1
node_modules/simple-code-frame/dist/esm/index.js.map
generated
vendored
Normal file
1
node_modules/simple-code-frame/dist/esm/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,UAAU,CAAC;AAE/B;;GAEG;AACH,SAAS,WAAW,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9D,CAAC;AAYD;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC9B,IAAY,EACZ,OAAe,EACf,SAAiB,EAEjB,EACC,MAAM,GAAG,CAAC,EACV,KAAK,GAAG,CAAC,EACT,MAAM,GAAG,IAAI,EACb,QAAQ,GAAG,CAAC,EACZ,cAAc,GAAG,GAAG,EACpB,aAAa,GAAG,GAAG,EACnB,gBAAgB,GAAG,GAAG,KACV,EAAE;IAEf,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE/B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC;IAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC;IAExD,gEAAgE;IAChE,mEAAmE;IACnE,cAAc;IACd,oBAAoB;IACpB,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAEvC,gEAAgE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,gBAAgB,CAAC,CACxB,IAAI,CAAC;SACN;aAAM;YACN,GAAG,IAAI,KAAK,WAAW,IAAI,GAAG,IAAI,SAAS,IAAI,CAAC;SAChD;KACD;IAED,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;AAC3C,CAAC"}
|
80
node_modules/simple-code-frame/dist/esm/index.mjs
generated
vendored
Normal file
80
node_modules/simple-code-frame/dist/esm/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
import * as kl from 'kolorist';
|
||||
/**
|
||||
* Convert tabs indentation to two spaces.
|
||||
*/
|
||||
function tabs2Spaces(str) {
|
||||
return str.replace(/^\t+/, tabs => ' '.repeat(tabs.length));
|
||||
}
|
||||
/**
|
||||
* Generate an excerpt of the location in the source around the
|
||||
* specified position.
|
||||
*/
|
||||
export function createCodeFrame(text, lineNum, columnNum, { before = 2, after = 3, colors = true, maxWidth = 0, lineMarkerChar = '▶', seperatorChar = '│', columnMarkerChar = '▲' } = {}) {
|
||||
const lines = text.split('\n');
|
||||
const start = Math.max(0, lineNum - before);
|
||||
const end = Math.min(lines.length, lineNum + after + 1);
|
||||
// Maximum space needed for line numbering in the current range.
|
||||
// Necessary when the amount of digits of the line numbering grows:
|
||||
// 999 | asdf
|
||||
// 1000 | asdjadfjsa
|
||||
const maxLineNum = String(end).length;
|
||||
const padding = ' '.repeat(maxLineNum);
|
||||
// Normalize all indentation (=tabs) to use 2 spaces. We need to
|
||||
// apply the difference to the marker position to move it back in
|
||||
// place.
|
||||
const spaceLines = [];
|
||||
let maxLineLen = 0;
|
||||
for (let i = start; i < end; i++) {
|
||||
const line = tabs2Spaces(lines[i]);
|
||||
spaceLines.push(line);
|
||||
if (line.length > maxLineLen)
|
||||
maxLineLen = line.length;
|
||||
}
|
||||
const activeLine = spaceLines[lineNum - start];
|
||||
// Move marker into correct place by taking the amount of
|
||||
// normalized tabs into account
|
||||
const count = Math.max(0, activeLine.length - lines[lineNum].length + columnNum);
|
||||
const maxLensWidth = maxWidth - '> '.length - padding.length - ' | '.length;
|
||||
let left = 0;
|
||||
let right = maxLensWidth;
|
||||
if (maxWidth > 0) {
|
||||
const half = Math.floor(maxLensWidth / 2);
|
||||
let winLeft = count - half;
|
||||
if (winLeft > 0) {
|
||||
let winRight = count + half - 1;
|
||||
left = winLeft;
|
||||
right = winRight;
|
||||
if (winRight > maxLensWidth) {
|
||||
const offset = Math.min(0, winRight - maxLensWidth);
|
||||
left -= offset;
|
||||
right -= offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
const sep = kl.dim(seperatorChar);
|
||||
let out = '';
|
||||
for (let i = 0; i < spaceLines.length; i++) {
|
||||
const line = spaceLines[i];
|
||||
const currentLine = kl.dim((padding + (i + start + 1)).slice(-maxLineNum));
|
||||
let formatted = line;
|
||||
if (maxWidth > 0) {
|
||||
formatted = formatted.slice(left, Math.min(right, line.length));
|
||||
if (left > 0) {
|
||||
formatted = '…' + formatted;
|
||||
}
|
||||
if (line.length > right) {
|
||||
formatted += '…';
|
||||
}
|
||||
}
|
||||
// Line where the error occured
|
||||
if (i === lineNum - start) {
|
||||
out += kl.red(lineMarkerChar) + ` ${currentLine} ${sep} ${formatted}\n`;
|
||||
out += ` ${padding} ${sep} ${' '.repeat(count - left)}${kl.bold(kl.red(columnMarkerChar))}\n`;
|
||||
}
|
||||
else {
|
||||
out += ` ${currentLine} ${sep} ${formatted}\n`;
|
||||
}
|
||||
}
|
||||
return colors ? out : kl.stripColors(out);
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
14
node_modules/simple-code-frame/dist/types/index.d.ts
generated
vendored
Normal file
14
node_modules/simple-code-frame/dist/types/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
export interface Options {
|
||||
before?: number;
|
||||
after?: number;
|
||||
colors?: boolean;
|
||||
maxWidth?: number;
|
||||
lineMarkerChar?: string;
|
||||
seperatorChar?: string;
|
||||
columnMarkerChar?: string;
|
||||
}
|
||||
/**
|
||||
* Generate an excerpt of the location in the source around the
|
||||
* specified position.
|
||||
*/
|
||||
export declare function createCodeFrame(text: string, lineNum: number, columnNum: number, { before, after, colors, maxWidth, lineMarkerChar, seperatorChar, columnMarkerChar }?: Options): string;
|
50
node_modules/simple-code-frame/package.json
generated
vendored
Normal file
50
node_modules/simple-code-frame/package.json
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "simple-code-frame",
|
||||
"version": "1.3.0",
|
||||
"description": "A tiny utility to create code frames",
|
||||
"main": "dist/cjs/index.js",
|
||||
"module": "dist/esm/index.js",
|
||||
"types": "dist/types/index.d.ts",
|
||||
"source": "src/index.ts",
|
||||
"scripts": {
|
||||
"test": "TS_NODE_LOG_ERROR=true mocha -r ts-node/register --extension ts,tsx 'tests/**/*.test.ts'",
|
||||
"build": "rimraf dist/ && tsc && tsc -p tsconfig.esm.json && cp dist/esm/index.js dist/esm/index.mjs && check-export-map",
|
||||
"prepublishOnly": "npm run build"
|
||||
},
|
||||
"author": "Marvin Hagemeister <hello@marvinh.dev>",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/marvinhagemeister/simple-code-frame.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@changesets/changelog-github": "^0.4.1",
|
||||
"@changesets/cli": "^2.17.0",
|
||||
"@types/mocha": "^8.2.2",
|
||||
"@types/node": "^14.14.37",
|
||||
"check-export-map": "^1.3.0",
|
||||
"mocha": "^8.3.2",
|
||||
"rimraf": "^3.0.2",
|
||||
"ts-node": "^9.1.1",
|
||||
"typescript": "^4.2.3"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/types/index.d.ts",
|
||||
"import": "./dist/esm/index.mjs",
|
||||
"require": "./dist/cjs/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"dist/"
|
||||
],
|
||||
"prettier": {
|
||||
"useTabs": true,
|
||||
"singleQuote": true,
|
||||
"arrowParens": "avoid"
|
||||
},
|
||||
"dependencies": {
|
||||
"kolorist": "^1.6.0"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user