Comparing version 4.14.1 to 5.0.0
@@ -8,5 +8,5 @@ // This file is read by tools that parse documentation comments conforming to the TSDoc standard. | ||
"packageName": "@microsoft/api-extractor", | ||
"packageVersion": "7.39.1" | ||
"packageVersion": "7.40.2" | ||
} | ||
] | ||
} |
106
package.json
{ | ||
"name": "convert", | ||
"version": "4.14.1", | ||
"version": "5.0.0", | ||
"description": "The smallest & fastest library for really easy, totally type-safe unit conversions in TypeScript & JavaScript", | ||
@@ -30,3 +30,3 @@ "keywords": [ | ||
"name": "Jonah Snider", | ||
"email": "jonah@jonah.pw", | ||
"email": "jonah@jonahsnider.com", | ||
"url": "https://jonahsnider.com" | ||
@@ -39,69 +39,47 @@ }, | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/convert.prod.mjs", | ||
"require": "./dist/index.js" | ||
}, | ||
"./dev": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/convert.dev.mjs", | ||
"require": "./dist/convert.dev.js" | ||
}, | ||
"./prod": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/convert.prod.mjs", | ||
"require": "./dist/convert.prod.js" | ||
"import": "./dist/index.mjs", | ||
"default": "./dist/index.js" | ||
} | ||
}, | ||
"main": "./dist/index.js", | ||
"jsdelivr": "./dist/convert.prod.mjs", | ||
"unpkg": "./dist/convert.prod.mjs", | ||
"module": "./dist/convert.prod.mjs", | ||
"browser": "./dist/convert.prod.mjs", | ||
"react-native": "./dist/convert.prod.js", | ||
"jsdelivr": "./dist/index.mjs", | ||
"unpkg": "./dist/index.mjs", | ||
"module": "./dist/index.mjs", | ||
"browser": "./dist/index.mjs", | ||
"react-native": "./dist/index.js", | ||
"typings": "./dist/index.d.ts", | ||
"files": [ | ||
"dist/", | ||
"!dist/{src,test}/" | ||
"!dist/typings", | ||
"!dist/src", | ||
"!dist/test", | ||
"!dist/scripts", | ||
"!dist/rollup.config.js" | ||
], | ||
"scripts": { | ||
"build": "rollup --config rollup.config.js --bundleConfigAsCjs && (yarn run validate-api || true)", | ||
"docs": "typedoc", | ||
"lint": "xo", | ||
"release": "semantic-release", | ||
"size": "size-limit", | ||
"style": "prettier --check . --ignore-path ../../.prettierignore", | ||
"test": "vitest run", | ||
"validate-api": "api-extractor run", | ||
"validate-api:local": "api-extractor run --local --verbose" | ||
}, | ||
"prettier": "@jonahsnider/prettier-config", | ||
"resolutions": { | ||
"terser": "5.26.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "7.23.7", | ||
"@babel/preset-env": "7.23.8", | ||
"@babel/preset-typescript": "7.23.3", | ||
"@jonahsnider/prettier-config": "1.1.2", | ||
"@babel/core": "7.23.9", | ||
"@babel/preset-env": "7.23.9", | ||
"@biomejs/biome": "1.5.3", | ||
"@jonahsnider/util": "10.3.0", | ||
"@jonahsnider/xo-config": "5.3.0", | ||
"@microsoft/api-extractor": "7.39.1", | ||
"@microsoft/api-extractor": "7.40.2", | ||
"@rollup/plugin-babel": "6.0.4", | ||
"@rollup/plugin-node-resolve": "15.2.3", | ||
"@rollup/plugin-replace": "5.0.5", | ||
"@rollup/plugin-typescript": "11.1.5", | ||
"@size-limit/preset-small-lib": "11.0.1", | ||
"@types/node": "20.10.7", | ||
"@vitest/coverage-v8": "1.1.3", | ||
"prettier": "3.1.1", | ||
"rollup": "4.9.4", | ||
"rollup-plugin-terser": "7.0.2", | ||
"semantic-release": "22.0.12", | ||
"size-limit": "11.0.1", | ||
"terser": "5.26.0", | ||
"typedoc": "0.25.7", | ||
"@rollup/plugin-swc": "0.3.0", | ||
"@rollup/plugin-terser": "0.4.4", | ||
"@size-limit/preset-small-lib": "11.0.2", | ||
"@swc/core": "1.4.2", | ||
"@tsconfig/node20": "20.1.2", | ||
"@tsconfig/strictest": "2.0.3", | ||
"@types/node": "20.11.19", | ||
"@vitest/coverage-v8": "1.2.2", | ||
"@vitest/ui": "^1.2.2", | ||
"bignumber.js": "9.1.2", | ||
"just-install": "2.0.1", | ||
"rollup": "4.12.0", | ||
"size-limit": "11.0.2", | ||
"typedoc": "0.25.8", | ||
"typescript": "5.3.3", | ||
"vitest": "1.1.3", | ||
"xo": "0.56.0" | ||
"vitest": "1.2.2" | ||
}, | ||
"packageManager": "yarn@4.0.2", | ||
"packageManager": "yarn@4.1.0", | ||
"runkitExampleFilename": "./docs/runkit.js", | ||
@@ -111,21 +89,21 @@ "size-limit": [ | ||
"brotli": true, | ||
"limit": "5.5 KiB", | ||
"path": "./dist/convert.prod.js" | ||
"limit": "5.37 KB", | ||
"path": "./dist/index.js" | ||
}, | ||
{ | ||
"gzip": true, | ||
"limit": "6.75 KiB", | ||
"path": "./dist/convert.prod.js" | ||
"limit": "6.81 KB", | ||
"path": "./dist/index.js" | ||
}, | ||
{ | ||
"brotli": true, | ||
"limit": "5.5 KiB", | ||
"path": "./dist/convert.prod.mjs" | ||
"limit": "5.18 KB", | ||
"path": "./dist/index.mjs" | ||
}, | ||
{ | ||
"gzip": true, | ||
"limit": "6.5 KiB", | ||
"path": "./dist/convert.prod.mjs" | ||
"limit": "6.55 KB", | ||
"path": "./dist/index.mjs" | ||
} | ||
] | ||
} |
@@ -14,7 +14,7 @@ # Convert | ||
[**More installation examples below, including browser builds**](#Installation). | ||
[**More installation examples below**](#Installation). | ||
```js | ||
convert(5, 'miles').to('km'); | ||
convertMany('4d 16h').to('minutes'); | ||
convert(5, "miles").to("km"); | ||
convertMany("4d 16h").to("minutes"); | ||
``` | ||
@@ -25,8 +25,6 @@ | ||
- Full build time and runtime validation of conversions | ||
- Using a web framework like Next.js or Nuxt.js? | ||
You get 0-cost build-time conversions. Convert is totally side-effect free, so [**conversions will be precalculated at build-time**](https://github.com/jonahsnider/convert/blob/master/docs/build-time-optimizations.tsx), so absolutely **zero conversion code is sent to clients**! | ||
- Works in browsers and Node.js (UMD and ESM builds will work anywhere) | ||
- Out of the box ES3 backwards-compatibility (CI tests on Node.js v0.9.1) | ||
- Absolutely tiny bundle size and 0 dependencies | ||
- Supports bigints without breaking on old engines | ||
- Web frameworks like Next.js and Vite know that Convert is side-effect free, so [conversions will be precalculated at build-time](https://github.com/jonahsnider/convert/blob/main/docs/build-time-optimizations.tsx), absolutely zero conversion code is sent to clients | ||
- Runs anywhere (browsers, Node, Bun, etc), full ES3 backwards-compatibility | ||
- Tiny bundle size and 0 dependencies | ||
- Supports bigints | ||
@@ -41,24 +39,24 @@ ## Usage | ||
// ESM: | ||
import convert from 'convert'; | ||
import convert from "convert"; | ||
// CJS: | ||
const {convert} = require('convert'); | ||
const { convert } = require("convert"); | ||
// 360 seconds into minutes | ||
convert(360, 'seconds').to('minutes'); | ||
convert(360, "seconds").to("minutes"); | ||
// -> 6 | ||
// BigInt support | ||
convert(20n, 'hours').to('minutes'); | ||
convert(20n, "hours").to("minutes"); | ||
// -> 1200n | ||
// Format to the best unit automatically | ||
convert(5500, 'meters').to('best'); | ||
convert(5500, "meters").to("best"); | ||
// -> { quantity: 5.5, unit: 'km', toString: () => '5.5km' } | ||
// We also do length, data, volume, mass, temperature, and more | ||
convert(5, 'kilometers').to('nautical miles'); | ||
convert(12, 'pounds').to('ounces'); | ||
convert(8192, 'bytes').to('KiB'); | ||
convert(10, 'atmospheres').to('kPa'); | ||
convert(451, 'fahrenheit').to('celsius'); | ||
// You can also do length, data, volume, mass, temperature, and more | ||
convert(5, "kilometers").to("nautical miles"); | ||
convert(12, "pounds").to("ounces"); | ||
convert(8192, "bytes").to("KiB"); | ||
convert(10, "atmospheres").to("kPa"); | ||
convert(451, "fahrenheit").to("celsius"); | ||
``` | ||
@@ -69,7 +67,7 @@ | ||
```ts | ||
import {convertMany} from 'convert'; | ||
const {convertMany} = require('convert'); | ||
import { convertMany } from "convert"; | ||
const { convertMany } = require("convert"); | ||
// Convert 1 day and 8 hours into ms | ||
convertMany('1d8h').to('ms'); | ||
convertMany("1d8h").to("ms"); | ||
``` | ||
@@ -80,17 +78,17 @@ | ||
```ts | ||
import convert from 'convert'; | ||
const {convert} = require('convert'); | ||
import convert from "convert"; | ||
const { convert } = require("convert"); | ||
// Convert into the best unit | ||
const duration = convert(36, 'h').to('best'); | ||
const duration = convert(36, "h").to("best"); | ||
// -> { quantity: 1.5, unit: 'd', toString: () => '1.5d' } | ||
// The toString() method means you can automatically cast the object to a string without any issues | ||
'duration is ' + duration; | ||
"duration is " + duration; | ||
// -> duration is 1.5d | ||
// You can also specify to use a specific kind of units (metric or imperial, metric is default) | ||
convert(3.5, 'km').to('best'); // -> { quantity: 3.5, unit: 'km', toString: () => '3.5km' } | ||
convert(3.5, 'km').to('best', 'metric'); // -> { quantity: 3.5, unit: 'km', toString: () => '3.5km' } | ||
convert(3.5, 'km').to('best', 'imperial'); // -> { quantity: 2.17, unit: 'mi', toString: () => '3.5mi' } | ||
convert(3.5, "km").to("best"); // -> { quantity: 3.5, unit: 'km', toString: () => '3.5km' } | ||
convert(3.5, "km").to("best", "metric"); // -> { quantity: 3.5, unit: 'km', toString: () => '3.5km' } | ||
convert(3.5, "km").to("best", "imperial"); // -> { quantity: 2.17, unit: 'mi', toString: () => '3.5mi' } | ||
``` | ||
@@ -101,7 +99,7 @@ | ||
```ts | ||
import {ms} from 'convert'; | ||
const {ms} = require('convert'); | ||
import { ms } from "convert"; | ||
const { ms } = require("convert"); | ||
// Convert a duration into milliseconds | ||
ms('1d 2h 30min'); | ||
ms("1d 2h 30min"); | ||
// -> 95400000 | ||
@@ -126,24 +124,12 @@ | ||
#### CommonJS | ||
And then import it in your code like this: | ||
```js | ||
// This chooses which build to use depending on NODE_ENV | ||
const {convert} = require('convert'); | ||
// CommonJS | ||
const { convert } = require("convert"); | ||
// You can also specify which build to use | ||
const {convert} = require('convert/dev'); | ||
const {convert} = require('convert/prod'); | ||
// ESM | ||
import convert from "convert"; | ||
``` | ||
#### ES Modules via npm Registry | ||
```js | ||
// The production build is the default | ||
import convert from 'convert'; | ||
// ESM does not have automatic build switching, you must explicitly import the dev build | ||
import convert from 'convert/dev'; | ||
import convert from 'convert/prod'; | ||
``` | ||
### Browsers | ||
@@ -157,6 +143,6 @@ | ||
<script type="module"> | ||
import convert from 'https://cdn.skypack.dev/convert@4'; | ||
import convert from 'https://esm.run/convert@4'; | ||
import convert from 'https://cdn.jsdelivr.net/npm/convert@4'; | ||
import convert from 'https://unpkg.com/convert@4'; | ||
import convert from "https://cdn.skypack.dev/convert@5"; | ||
import convert from "https://esm.run/convert@5"; | ||
import convert from "https://cdn.jsdelivr.net/npm/convert@5"; | ||
import convert from "https://unpkg.com/convert@5"; | ||
</script> | ||
@@ -168,4 +154,4 @@ ``` | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/convert@4/dist/convert.prod.js"></script> | ||
<script src="https://unpkg.com/convert@4/dist/convert.prod.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/convert@5/dist/index.js"></script> | ||
<script src="https://unpkg.com/convert@5/dist/index.js"></script> | ||
``` | ||
@@ -172,0 +158,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
23
0
0
482198
9
1393
171
1