Skip to content

Commit

Permalink
Support types without enabling esModuleInterop in TypeScript (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja authored Mar 14, 2024
1 parent bd1dca4 commit ad4cdbd
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 42 deletions.
66 changes: 47 additions & 19 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,78 @@
# CHANGELOG

## 1.2.5 - 2024-03-13
## [Unreleased]

## [1.2.6] - 2024-03-14

- Support types without enabling `esModuleInterop` in TypeScript.

## [1.2.5] - 2024-03-13

- Fixed error computing some quadratic Bézier curves cases.

## 1.2.4 - 2023-02-09
## [1.2.4] - 2023-02-09

- Optimized proccesing of segments based on [Simple Icons] data.

[Simple Icons]: https://github.com/simple-icons/simple-icons

## 1.2.3 - 2022-12-23
## [1.2.3] - 2022-12-23

- Fixed CLI not being executed in some versions of Node.js < v16.

## 1.2.2 - 2022-05-26
## [1.2.2] - 2022-05-26

- Fixed edge case computing cubic Bézier curves bounding boxes.

## 1.2.1 - 2022-05-12
## [1.2.1] - 2022-05-12

- Fixed error computing cubic Bézier curves bounding boxes.

## 1.2.0 - 2022-05-07
## [1.2.0] - 2022-05-07

- Use default export for better interoperability.

## 1.1.0 - 2022-05-05
## [1.1.0] - 2022-05-05

- Add support for Typescript.

## 1.0.2 - 2022-01-11
## [1.0.2] - 2022-01-11

- Add basic options `--version` and `--help` to CLI.

## 1.0.1 - 2021-06-21
## [1.0.1] - 2021-06-21

- Fixed error computing limits for cubic Bèzier curves of length 0.

## 1.0.0 - 2021-06-03
## [1.0.0] - 2021-06-03

- Testing with 100% coverage.
- Make `svgPathBbox` function the default export.

## 0.2.0 - 2020-12-22
## [0.2.0] - 2020-12-22

- Removed almost all public API functions (only keep `svgPathBbox` function).
- Removed `polf` dependency.
- Optimized quadratic Bézier curves minimum and maximum values computation.
- Optimized cubic Bézier curves minimum and maximum values computation.
- Optimized lineal segments minimum and maximum values computation.

## 0.1.5 - 2020-11-26
## [0.1.5] - 2020-11-26

- Documentation improved.
- Switch CI to Github Actions.

## 0.1.4 - 2020-11-23
## [0.1.4] - 2020-11-23

- Document and export `quadraticBezierCurveBbox` function.
- Remove development file from NPM package.
- Update acknowledgments.

## 0.1.1 - 2020-11-19
## [0.1.1] - 2020-11-19

- Fix error computing bounding boxes for Q, T and some C commands.

## 0.0.47 - 2020-07-23
## [0.0.47] - 2020-07-23

- Separate point on line functions in another package.
- Replaced svg-path-parser dependency with svgpath to optimize parsing time.
Expand All @@ -75,29 +81,51 @@
- Fix errors in utility functions.
- Add tests for utilities and command line client.

## 0.0.28 - 2020-05-22
## [0.0.28] - 2020-05-22

- Update LICENSE.
- Fix error converting quaratic to Bézier coordinates.
- Add tests for some bounding boxes functions.

## 0.0.26 - 2020-05-21
## [0.0.26] - 2020-05-21

- Removed `quadraticBezierCurveBbox` function.
- Optimized quadratic Bézier curve bounding box computation.
- Optimized cubic Bézier curve bounding box algorithm.
- Fixed error on V and H commands computing SVG path bbox.

## 0.0.20 - 2020-05-17
## [0.0.20] - 2020-05-17

- Add function to obtain an array of numbers from SVG path.
- Multiple paths as arguments for command line script.

## 0.0.13 - 2020-05-17
## [0.0.13] - 2020-05-17

- Add command line interface.
- Add linting.
- Released to NPM.
- Add documentation.
- Add changelog.
- Basic functionalities finished.

[Unreleased]: https://github.com/mondeja/svg-path-bbox/compare/v1.2.6...HEAD
[1.2.6]: https://github.com/mondeja/svg-path-bbox/compare/v1.2.5...v1.2.6
[1.2.5]: https://github.com/mondeja/svg-path-bbox/compare/v1.2.4...v1.2.5
[1.2.4]: https://github.com/mondeja/svg-path-bbox/compare/v1.2.3...v1.2.4
[1.2.3]: https://github.com/mondeja/svg-path-bbox/compare/v1.2.2...v1.2.3
[1.2.2]: https://github.com/mondeja/svg-path-bbox/compare/v1.2.1...v1.2.2
[1.2.1]: https://github.com/mondeja/svg-path-bbox/compare/v1.2.0...v1.2.1
[1.2.0]: https://github.com/mondeja/svg-path-bbox/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/mondeja/svg-path-bbox/compare/v1.0.2...v1.1.0
[1.0.2]: https://github.com/mondeja/svg-path-bbox/compare/v1.0.1...v1.0.2
[1.0.1]: https://github.com/mondeja/svg-path-bbox/compare/v1.0.0...v1.0.1
[1.0.0]: https://github.com/mondeja/svg-path-bbox/compare/v0.2.0...v1.0.0
[0.2.0]: https://github.com/mondeja/svg-path-bbox/compare/v0.1.5...v0.2.0
[0.1.5]: https://github.com/mondeja/svg-path-bbox/compare/v0.1.4...v0.1.5
[0.1.4]: https://github.com/mondeja/svg-path-bbox/compare/v0.1.1...v0.1.4
[0.1.1]: https://github.com/mondeja/svg-path-bbox/compare/v0.0.47...v0.1.1
[0.0.47]: https://github.com/mondeja/svg-path-bbox/compare/v0.0.28...v0.0.47
[0.0.28]: https://github.com/mondeja/svg-path-bbox/compare/v0.0.26...v0.0.28
[0.0.26]: https://github.com/mondeja/svg-path-bbox/compare/v0.0.20...v0.0.26
[0.0.20]: https://github.com/mondeja/svg-path-bbox/compare/v0.0.13...v0.0.20
[0.0.13]: https://github.com/mondeja/svg-path-bbox/releases/tag/v0.0.13
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,4 @@ function svgPathBbox(d) {
}, true);
return [min[0], min[1], max[0], max[1]];
}
exports.default = svgPathBbox;
module.exports = svgPathBbox;
2 changes: 2 additions & 0 deletions dist/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import svgPathBbox from "./index.js";
export default svgPathBbox;
4 changes: 3 additions & 1 deletion dist/index.d.ts → dist/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export type BBox = [minX: number, minY: number, maxX: number, maxY: number];

/**
* Compute bounding boxes of SVG paths.
* @param {String} d SVG path for which their bounding box will be computed.
* @returns {BBox}
*/
export default function svgPathBbox(d: string): BBox;
declare function svgPathBbox(d: string): BBox;
export = svgPathBbox;
1 change: 0 additions & 1 deletion dist/wrapper.js

This file was deleted.

2 changes: 1 addition & 1 deletion examples/common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const util = require("util")
const svgPathBbox = require("../dist/wrapper.js");
const svgPathBbox = require("../dist/index.js");

const bbox = svgPathBbox("M0 0H3V6Z");
process.stdout.write(`${util.inspect(bbox)}\n`)
2 changes: 1 addition & 1 deletion examples/esm.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inspect } from "node:util";
import svgPathBbox from "../dist/wrapper.js";
import svgPathBbox from "../dist/index.mjs";

const bbox = svgPathBbox("M0 0H3V6Z");
process.stdout.write(`${inspect(bbox)}\n`)
32 changes: 25 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
{
"name": "svg-path-bbox",
"version": "1.2.5",
"version": "1.2.6",
"description": "Compute bounding boxes of SVG paths.",
"keywords": [
"svg",
"path",
"bbox"
],
"main": "dist/wrapper.js",
"browser": "dist/wrapper.js",
"module": "dist/wrapper.js",
"types": "dist/index.d.ts",
"type": "commonjs",
"exports": {
".": {
"import": {
"types": "./dist/types.d.ts",
"default": "./dist/index.mjs"
},
"module": {
"types": "./dist/types.d.ts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/types.d.ts",
"default": "./dist/index.js"
},
"default": {
"types": "./dist/types.d.ts",
"default": "./dist/index.js"
}
}
},
"bin": {
"svg-path-bbox": "src/cli.js"
},
"scripts": {
"coveralls": "cat ./tests/coverage/lcov.info | coveralls",
"prebuild": "run-s build:index lint:fix dist:prepare",
"build": "run-p build:ts build:cjs:wrapper",
"build": "run-p build:ts build:patch-dist-indexjs build:create-index-mjs build:copy-types",
"build:index": "ts-node scripts/build/index.ts",
"build:ts": "tsc",
"build:cjs:wrapper": "ts-node scripts/build/cjs-wrapper.ts",
"build:patch-dist-indexjs": "ts-node scripts/build/patch-dist-indexjs.ts",
"build:create-index-mjs": "ts-node scripts/build/create-index-mjs.ts",
"build:copy-types": "ts-node scripts/build/copy-types.ts",
"examples": "run-s example:*",
"example:cjs": "node examples/common.js",
"example:esm": "node examples/esm.mjs",
Expand Down
8 changes: 0 additions & 8 deletions scripts/build/cjs-wrapper.ts

This file was deleted.

3 changes: 3 additions & 0 deletions scripts/build/copy-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as fs from "node:fs";

fs.copyFileSync("src/types.d.ts", "dist/types.d.ts");
8 changes: 8 additions & 0 deletions scripts/build/create-index-mjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as fs from "node:fs";

fs.writeFileSync(
"dist/index.mjs",
`import svgPathBbox from "./index.js";
export default svgPathBbox;
`
);
11 changes: 11 additions & 0 deletions scripts/build/patch-dist-indexjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as fs from "node:fs";

fs.writeFileSync(
"dist/index.js",
fs
.readFileSync("dist/index.js", "utf8")
.replace(
'exports.default = svgPathBbox;',
'module.exports = svgPathBbox;'
)
);
2 changes: 1 addition & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if (require.main === module) {
process.exit(1);
}

const svgPathBbox = require("../dist/wrapper");
const svgPathBbox = require("../dist/index.js");
for (let a = 0; a < args.length; a++) {
console.log(svgPathBbox(args[a]).join(" "));
}
Expand Down
9 changes: 9 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type BBox = [minX: number, minY: number, maxX: number, maxY: number];

/**
* Compute bounding boxes of SVG paths.
* @param {String} d SVG path for which their bounding box will be computed.
* @returns {BBox}
*/
declare function svgPathBbox(d: string): BBox;
export = svgPathBbox;
2 changes: 1 addition & 1 deletion tests/changelog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ test("Current version has a CHANGELOG entry", () => {

const changelogEntry = changelog
.split("\n")
.find((line: string) => line.startsWith(`## ${packageJson.version}`));
.find((line: string) => line.startsWith(`## [${packageJson.version}]`));
expect(changelogEntry).toBeDefined();
});
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"module": "commonjs",
"moduleResolution": "node",
"strict": true,
"declaration": true,
"outDir": "dist",
"skipLibCheck": true
},
Expand Down

0 comments on commit ad4cdbd

Please sign in to comment.