Skip to content

Commit

Permalink
fix: Export Note.distance (#438)
Browse files Browse the repository at this point in the history
* chore: remove core dependency

* feat: re-export distance

* chore: build

* feat: add changeset
  • Loading branch information
danigb authored Jul 23, 2024
1 parent 4dd40aa commit 3cd5f16
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 16 deletions.
29 changes: 29 additions & 0 deletions .changeset/curly-adults-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
"tonal": patch
"@tonaljs/note": patch
---

#### Fix: add `Note.distance` back

The documentation said `Note.distance` was available, but was not.

Now you can do:

```js
import { Note } from "tonal";
Note.distance("c4", "e7"); // => "24M"
```

#### Note `default` export is deprecated

Using default exports for single packages are discouraged. For `note` module is now deprecated, so instead of:

```js
import Note from "@tonaljs/note";
```

You should do this:

```js
import * as Note from "@tonaljs/note";
```
13 changes: 8 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/note/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ nodejs:
const { Note } = require("tonal");
```

single module:

```js
import { get } from "@tonaljs/note";
```

## API

### Note properties
Expand Down
14 changes: 9 additions & 5 deletions packages/note/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { freqToMidi, midiToNoteName } from "@tonaljs/midi";
import { Pitch } from "@tonaljs/pitch";
import { distance as _dist, transpose as _tr } from "@tonaljs/pitch-distance";
import { IntervalName } from "@tonaljs/pitch-interval";
import {
IntervalName,
Note,
NoteLiteral,
NoteName,
Pitch,
transpose as _tr,
note as props,
} from "@tonaljs/core";
import { freqToMidi, midiToNoteName } from "@tonaljs/midi";
} from "@tonaljs/pitch-note";

const NAMES = ["C", "D", "E", "F", "G", "A", "B"];

Expand Down Expand Up @@ -124,6 +124,8 @@ export function fromMidiSharps(midi: number) {
return midiToNoteName(midi, { sharps: true });
}

export const distance = _dist;

/**
* Transpose a note by an interval
*/
Expand Down Expand Up @@ -275,6 +277,7 @@ export function enharmonic(noteName: string, destName?: string) {
return dest.pc + destOct;
}

/** @deprecated */
export default {
names,
get,
Expand All @@ -285,6 +288,7 @@ export default {
midi,
ascending,
descending,
distance,
sortedNames,
sortedUniqNames,
fromMidi,
Expand Down
5 changes: 4 additions & 1 deletion packages/note/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
],
"types": "dist/index.d.ts",
"dependencies": {
"@tonaljs/core": "5.0.0",
"@tonaljs/pitch": "5.0.2",
"@tonaljs/pitch-interval": "6.0.0",
"@tonaljs/pitch-distance": "5.0.3",
"@tonaljs/pitch-note": "6.0.0",
"@tonaljs/midi": "4.9.3"
},
"author": "[email protected]",
Expand Down
2 changes: 2 additions & 0 deletions packages/tonal/__snapshots__/test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ exports[`tonal Modules exports functions 1`] = `
"accidentals",
"ascending",
"chroma",
"default",
"descending",
"distance",
"enharmonic",
"freq",
"fromFreq",
Expand Down
2 changes: 1 addition & 1 deletion packages/tonal/browser/tonal.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/tonal/browser/tonal.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/tonal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Interval from "@tonaljs/interval";
import Key from "@tonaljs/key";
import Midi from "@tonaljs/midi";
import Mode from "@tonaljs/mode";
import Note from "@tonaljs/note";
import * as Note from "@tonaljs/note";
import Pcset from "@tonaljs/pcset";
import Progression from "@tonaljs/progression";
import Range from "@tonaljs/range";
Expand Down

0 comments on commit 3cd5f16

Please sign in to comment.