Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose more entry points #436

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ node_modules/
/docs/generated/
/docs/coverage.svg
/src/exponents.ts
/src/units/converters/prefixes.ts
/src/converters/prefixes.ts
/src/units/modifiers/prefixes.ts
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default rsEslint(
ignores: [
// Autogenerated files
"src/exponents.ts",
"src/units/converters/prefixes.ts",
"src/converters/prefixes.ts",
"src/units/modifiers/prefixes.ts",
],
},
Expand Down
10 changes: 8 additions & 2 deletions jsr.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
{
"name": "@rebeccastevens/uom-types",
"version": "0.0.0-development",
"exports": "./src/index.ts",
"exports": {
".": "src/index.ts",
"./converters": "src/converters.ts",
"./math": "src/math.ts",
"./types": "src/types.ts",
"./units": "src/units.ts"
},
"publish": {
"include": ["LICENSE", "README.md", "src/**/*.ts"],
"exclude": [
"**/*.test.ts",
"**/*.test-d.ts",
"!src/exponents.ts",
"!src/units/converters/prefixes.ts",
"!src/converters/prefixes.ts",
"!src/units/modifiers/prefixes.ts"
]
}
Expand Down
2 changes: 1 addition & 1 deletion knip.jsonc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "node_modules/knip/schema-jsonc.json",
"entry": ["src/index.ts!"],
"entry": ["src/index.ts!", "src/converters.ts!", "src/math.ts!", "src/types.ts!", "src/units.ts!"],
"project": ["src/**/*.ts!", "!src/**/*.test-d.ts"],
"ignoreDependencies": ["@eslint/compat", "tsc-files"],
"exclude": ["exports", "nsExports", "types", "nsTypes", "duplicates"],
Expand Down
44 changes: 39 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,46 @@
"sideEffects": false,
"type": "module",
"exports": {
"types": {
"import": "./dist/index.d.mts",
"require": "./dist/index.d.cts"
".": {
"types": {
"import": "./dist/index.d.mts",
"require": "./dist/index.d.cts"
},
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
"./converters": {
"converters": {
"import": "./dist/converters.d.mts",
"require": "./dist/converters.d.cts"
},
"import": "./dist/converters.mjs",
"require": "./dist/converters.cjs"
},
"./math": {
"math": {
"import": "./dist/math.d.mts",
"require": "./dist/math.d.cts"
},
"import": "./dist/math.mjs",
"require": "./dist/math.cjs"
},
"./types": {
"types": {
"import": "./dist/types.d.mts",
"require": "./dist/types.d.cts"
},
"import": "./dist/types.mjs",
"require": "./dist/types.cjs"
},
"./units": {
"units": {
"import": "./dist/units.d.mts",
"require": "./dist/units.d.cts"
},
"import": "./dist/units.mjs",
"require": "./dist/units.cjs"
}
},
"files": [
"dist/",
Expand Down
14 changes: 11 additions & 3 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,25 @@ const externalDependencies = [
];

export default {
input: "src/index.ts",
input: {
converters: "src/converters.ts",
math: "src/math.ts",
types: "src/types.ts",
units: "src/units.ts",
index: "src/index.ts",
},

output: [
{
file: pkg.exports.import,
entryFileNames: "[name].mjs",
dir: "dist",
format: "esm",
sourcemap: false,
importAttributesKey: "with",
},
{
file: pkg.exports.require,
entryFileNames: "[name].cjs",
dir: "dist",
format: "cjs",
sourcemap: false,
},
Expand Down
4 changes: 2 additions & 2 deletions scripts/generate-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function generateSiUnitPrefixesFile() {
}

function generateSiUnitPrefixesConvertionFile() {
const imports = `import type { UnknownUnit, UnitConversionRate } from "../../core.ts";\nimport { mul, div } from "../../math/index.ts";\nimport type { Divide, Multiply } from "../../units-operations/index.ts";\n\n`;
const imports = `import type { UnknownUnit, UnitConversionRate } from "../core.ts";\nimport { mul, div } from "../math/index.ts";\nimport type { Divide, Multiply } from "../units-operations/index.ts";\n\n`;
const main = [...exponents.values()]
.map((exponent) => {
const name = scalar10ToName.get(exponent);
Expand All @@ -98,7 +98,7 @@ function generateSiUnitPrefixesConvertionFile() {
.filter(isNotNull)
.join("\n\n");
const content = `${autogenHeader}${imports}${main}\n`;
return fs.writeFile("src/units/converters/prefixes.ts", content, {
return fs.writeFile("src/converters/prefixes.ts", content, {
encoding: "utf8",
});
}
Expand Down
1 change: 1 addition & 0 deletions src/converters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./converters/index.ts";
6 changes: 3 additions & 3 deletions src/units/converters/angle.ts → src/converters/angle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { UnitConversionRate } from "../../core.ts";
import { div, mul } from "../../math/index.ts";
import type { Degree, Gradian, Radian, Turn } from "../common/index.ts";
import type { UnitConversionRate } from "../core.ts";
import { div, mul } from "../math/index.ts";
import type { Degree, Gradian, Radian, Turn } from "../units/common/index.ts";

/**
* Convert {@link Radian} to {@link Degree}.
Expand Down
8 changes: 4 additions & 4 deletions src/units/converters/area.ts → src/converters/area.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import type { UnitConversionRate } from "../../core.ts";
import { div, mul } from "../../math/index.ts";
import type { Are, Hectare, Meter } from "../common/index.ts";
import type { Square } from "../modifiers/index.ts";
import type { UnitConversionRate } from "../core.ts";
import { div, mul } from "../math/index.ts";
import type { Are, Hectare, Meter } from "../units/common/index.ts";
import type { Square } from "../units/modifiers/index.ts";

/**
* Convert {@link Square}<{@link Meter}> to {@link Are}.
*/
export function squareMetersToAres(area: Square<Meter>): Are {

Check warning on line 9 in src/converters/area.ts

View workflow job for this annotation

GitHub Actions / lint_js

Parameter should have an immutability of at least "ReadonlyShallow" (actual: "Mutable")
return div(area, 100 as UnitConversionRate<{ scalar10: -2 }>);
}

/**
* Convert {@link Square}<{@link Meter}> to {@link Hectare}.
*/
export function squareMetersToHectares(area: Square<Meter>): Hectare {

Check warning on line 16 in src/converters/area.ts

View workflow job for this annotation

GitHub Actions / lint_js

Parameter should have an immutability of at least "ReadonlyShallow" (actual: "Mutable")
return div(area, 10_000 as UnitConversionRate<{ scalar10: -4 }>);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { UnitConversionRate } from "../../core.ts";
import { div, mul } from "../../math/index.ts";
import type { Day, Hour, Minute, Second, Week, Year } from "../common/index.ts";
import type { UnitConversionRate } from "../core.ts";
import { div, mul } from "../math/index.ts";
import type { Day, Hour, Minute, Second, Week, Year } from "../units/common/index.ts";

/**
* Convert {@link Second} to {@link Minute}.
Expand Down
6 changes: 3 additions & 3 deletions src/units/converters/energy.ts → src/converters/energy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { UnitConversionRate } from "../../core.ts";
import { div, mul } from "../../math/index.ts";
import type { Joule, WattHour, WattMinute } from "../common/index.ts";
import type { UnitConversionRate } from "../core.ts";
import { div, mul } from "../math/index.ts";
import type { Joule, WattHour, WattMinute } from "../units/common/index.ts";

/**
* Convert {@link Joule} to {@link WattMinute}.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { UnitConversionRate } from "../../core.ts";
import { div, mul } from "../../math/index.ts";
import type { Hertz, PerDay, PerHour, PerMinute, PerWeek, PerYear } from "../common/index.ts";
import type { UnitConversionRate } from "../core.ts";
import { div, mul } from "../math/index.ts";
import type { Hertz, PerDay, PerHour, PerMinute, PerWeek, PerYear } from "../units/common/index.ts";

/**
* Convert {@link Hertz} to {@link PerMinute}.
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/units/converters/mass.ts → src/converters/mass.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { UnitConversionRate } from "../../core.ts";
import { div, mul } from "../../math/index.ts";
import type { Gram, Tonne } from "../common/index.ts";
import type { UnitConversionRate } from "../core.ts";
import { div, mul } from "../math/index.ts";
import type { Gram, Tonne } from "../units/common/index.ts";

/**
* Convert {@link Gram} to {@link Tonne}.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Celsius, Kelvin } from "../common/index.ts";
import type { Celsius, Kelvin } from "../units/common/index.ts";

/**
* Convert {@link Celsius} to {@link Kelvin}.
Expand Down
8 changes: 4 additions & 4 deletions src/units/converters/volume.ts → src/converters/volume.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { UnitConversionRate } from "../../core.ts";
import { div, mul } from "../../math/index.ts";
import type { Liter, Meter } from "../common/index.ts";
import type { Cubic } from "../modifiers/index.ts";
import type { UnitConversionRate } from "../core.ts";
import { div, mul } from "../math/index.ts";
import type { Liter, Meter } from "../units/common/index.ts";
import type { Cubic } from "../units/modifiers/index.ts";

/**
* Convert {@link Cubic}<{@link Meter}> to {@link Liter}.
*/
export function cubicMetersToLiters(volume: Cubic<Meter>): Liter {

Check warning on line 9 in src/converters/volume.ts

View workflow job for this annotation

GitHub Actions / lint_js

Parameter should have an immutability of at least "ReadonlyShallow" (actual: "Mutable")
return mul(volume, 1000 as UnitConversionRate<{ scalar10: -3 }>);
}

Expand Down
41 changes: 2 additions & 39 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,4 @@
export type {
AbstractUnit,
AbstractUnitFrom,
Unit,
UnitClass,
UnitConversionRate,
UnitConversionRateFrom,
UnitFrom,
UnitMeta,
UnitSubvalues,
UnknownAbstractUnit,
UnknownUnit,
UnknownUnitClass,
UnknownUnitConversionRate,
UnknownUnitMeta,
} from "./core.ts";
export type {
DivideExponents,
Exponent,
MultiplyExponents,
NegateExponent,
NegExponent,
PosExponent,
SubExponents,
SumExponents,
} from "./exponents.ts";
export type {
Divide,
DivideUnitSubvalues,
Inverse,
InverseUnitSubvalues,
Multiply,
MultiplyUnitSubvalues,
Pow,
PowUnitSubvalues,
Root,
RootUnitSubvalues,
} from "./units-operations/index.ts";

export * from "./math/index.ts";
export * from "./types.ts";
export * from "./units/index.ts";
export * from "./converters/index.ts";
1 change: 1 addition & 0 deletions src/math.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./math/index.ts";
38 changes: 38 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export type {
AbstractUnit,
AbstractUnitFrom,
Unit,
UnitClass,
UnitConversionRate,
UnitConversionRateFrom,
UnitFrom,
UnitMeta,
UnitSubvalues,
UnknownAbstractUnit,
UnknownUnit,
UnknownUnitClass,
UnknownUnitConversionRate,
UnknownUnitMeta,
} from "./core.ts";
export type {
DivideExponents,
Exponent,
MultiplyExponents,
NegateExponent,
NegExponent,
PosExponent,
SubExponents,
SumExponents,
} from "./exponents.ts";
export type {
Divide,
DivideUnitSubvalues,
Inverse,
InverseUnitSubvalues,
Multiply,
MultiplyUnitSubvalues,
Pow,
PowUnitSubvalues,
Root,
RootUnitSubvalues,
} from "./units-operations/index.ts";
1 change: 1 addition & 0 deletions src/units.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./units/index.ts";
1 change: 0 additions & 1 deletion src/units/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./base-units.ts";
export * from "./common/index.ts";
export * from "./converters/index.ts";
export * from "./modifiers/index.ts";
Loading