Skip to content

feat: migrate test suite to Node.js native tests and ESM #44

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 3 additions & 4 deletions bin/wavefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
* @fileoverview wavefile CLI.
* @see https://github.com/rochars/wavefile
*/

const WaveFile = require('../dist/wavefile.js').WaveFile;
const fs = require('fs');
import { WaveFile } from '../index.js';
import fs from 'fs';

/** @type {string} */
const presentation = " WaveFile 8.1.0\n" +
Expand Down Expand Up @@ -148,7 +147,7 @@ for (let command in commands) {
// --list-tag
} else if (command == '--list-tags') {
/** @type {!Object} */
tags = wav.listTags();
const tags = wav.listTags();
for (var tag in tags) {
if (tags.hasOwnProperty(tag)) {
console.log(tag + ': ' + tags[tag]);
Expand Down
15 changes: 15 additions & 0 deletions dist/wavefile.cjs.cjs

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions dist/wavefile.esm.js

Large diffs are not rendered by default.

84 changes: 0 additions & 84 deletions dist/wavefile.js

This file was deleted.

3 changes: 1 addition & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ <h3> </h3>
https://github.com/rochars/wavefile</p>
<p><a href="https://www.npmjs.com/package/wavefile"><img src="https://img.shields.io/npm/v/wavefile.svg?style=for-the-badge" alt="NPM version"></a> <a href="https://rochars.github.io/wavefile/docs"><img src="https://img.shields.io/badge/API-docs-blue.svg?style=for-the-badge" alt="Docs"></a> <a href="https://rochars.github.io/wavefile/test/browser.html"><img src="https://img.shields.io/badge/tests-online-blue.svg?style=for-the-badge" alt="Tests"></a><br>
<a href="https://codecov.io/gh/rochars/wavefile"><img src="https://img.shields.io/codecov/c/github/rochars/wavefile.svg?style=flat-square" alt="Codecov"></a> <a href="https://travis-ci.org/rochars/wavefile"><img src="https://img.shields.io/travis/rochars/wavefile.svg?style=flat-square" alt="Unix Build"></a> <a href="https://ci.appveyor.com/project/rochars/wavefile"><img src="https://img.shields.io/appveyor/ci/rochars/wavefile.svg?style=flat-square&amp;logo=appveyor" alt="Windows Build"></a> <a href="https://scrutinizer-ci.com/g/rochars/wavefile/"><img src="https://img.shields.io/scrutinizer/g/rochars/wavefile.svg?style=flat-square&amp;logo=scrutinizer" alt="Scrutinizer"></a> <a href="https://bestpractices.coreinfrastructure.org/projects/1880"><img src="https://bestpractices.coreinfrastructure.org/projects/1880/badge" alt="CII Best Practices"></a></p>
<h2>Notice</h2>
<p>My country, Brazil, is under a fascist government that is hunting and killing its opponents. I've been threatened too.</p>
<h1>wavefile</h1>
<p>Create, read and write wav files according to the specs.</p>
<ul>
<li><strong>MIT licensed</strong></li>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h1 class="page-title">index.js</h1>
/** @module wavefile */

import { encode, decode } from './lib/parsers/base64-arraybuffer.js';
import { WaveFileConverter } from './lib/wavefile-converter';
import { WaveFileConverter } from './lib/wavefile-converter.js';

/**
* A class to manipulate wav files.
Expand Down
16 changes: 8 additions & 8 deletions docs/lib_wavefile-converter.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ <h1 class="page-title">lib/wavefile-converter.js</h1>
* @see https://github.com/rochars/wavefile
*/

import { changeBitDepth } from './codecs/bitdepth';
import * as imaadpcm from './codecs/imaadpcm';
import * as alaw from './codecs/alaw';
import * as mulaw from './codecs/mulaw';
import { unpackArrayTo } from './parsers/binary';
import { WaveFileCueEditor } from './wavefile-cue-editor';
import { validateSampleRate } from './validators/validate-sample-rate';
import { resample } from './resampler';
import { changeBitDepth } from './codecs/bitdepth.js';
import * as imaadpcm from './codecs/imaadpcm.js';
import * as alaw from './codecs/alaw.js';
import * as mulaw from './codecs/mulaw.js';
import { unpackArrayTo } from './parsers/binary/index.js';
import { WaveFileCueEditor } from './wavefile-cue-editor.js';
import { validateSampleRate } from './validators/validate-sample-rate.js';
import { resample } from './resampler/index.js';

/**
* A class to convert wav files to other types of wav files.
Expand Down
10 changes: 5 additions & 5 deletions docs/lib_wavefile-creator.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ <h1 class="page-title">lib/wavefile-creator.js</h1>
* @see https://github.com/rochars/wavefile
*/

import { WaveFileParser } from './wavefile-parser';
import { interleave, deInterleave } from './parsers/interleave';
import { validateNumChannels } from './validators/validate-num-channels';
import { validateSampleRate } from './validators/validate-sample-rate';
import { packArrayTo, unpackArrayTo, packTo, unpack } from './parsers/binary';
import { WaveFileParser } from './wavefile-parser.js';
import { interleave, deInterleave } from './parsers/interleave.js';
import { validateNumChannels } from './validators/validate-num-channels.js';
import { validateSampleRate } from './validators/validate-sample-rate.js';
import { packArrayTo, unpackArrayTo, packTo, unpack } from './parsers/binary/index.js';

/**
* A class to read, write and create wav files.
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_wavefile-cue-editor.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h1 class="page-title">lib/wavefile-cue-editor.js</h1>
* @see https://github.com/rochars/wavefile
*/

import { WaveFileTagEditor } from './wavefile-tag-editor';
import { WaveFileTagEditor } from './wavefile-tag-editor.js';

/**
* A class to edit meta information in wav files.
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_wavefile-tag-editor.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h1 class="page-title">lib/wavefile-tag-editor.js</h1>
* @see https://github.com/rochars/wavefile
*/

import { WaveFileCreator } from './wavefile-creator';
import { WaveFileCreator } from './wavefile-creator.js';

/**
* A class to edit meta information in wav files.
Expand Down
88 changes: 71 additions & 17 deletions docs/module-wavefile.WaveFile.html
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,9 @@ <h5 class="subsection-title">Properties:</h5>


<div class="description">
Audio formats.Formats not listed here should be set to 65534,the code for WAVE_FORMAT_EXTENSIBLE
Audio formats.
Formats not listed here should be set to 65534,
the code for WAVE_FORMAT_EXTENSIBLE
</div>


Expand Down Expand Up @@ -932,7 +934,8 @@ <h5>Parameters:</h5>



<td class="description last">the index of the point. First is 1, second is 2, and so on.</td>
<td class="description last">the index of the point. First is 1,
second is 2, and so on.</td>
</tr>


Expand Down Expand Up @@ -1256,7 +1259,8 @@ <h5>Parameters:</h5>
</td>


<td class="description last">The new bit depth of the samples. One of '8' ... '32' (integers), '32f' or '64' (floats).</td>
<td class="description last">The new bit depth of the samples.
One of '8' ... '32' (integers), '32f' or '64' (floats).</td>
</tr>


Expand Down Expand Up @@ -2053,7 +2057,8 @@ <h5>Parameters:</h5>
</td>


<td class="description last">The new bit depth of the samples. One of '8' ... '32' (integers), '32f' or '64' (floats).</td>
<td class="description last">The new bit depth of the samples.
One of '8' ... '32' (integers), '32f' or '64' (floats).</td>
</tr>


Expand Down Expand Up @@ -2214,7 +2219,8 @@ <h5>Parameters:</h5>
</td>


<td class="description last">The new bit depth of the samples. One of '8' ... '32' (integers), '32f' or '64' (floats).</td>
<td class="description last">The new bit depth of the samples.
One of '8' ... '32' (integers), '32f' or '64' (floats).</td>
</tr>


Expand Down Expand Up @@ -2301,7 +2307,8 @@ <h4 class="name" id="fromScratch"><span class="type-signature"></span>fromScratc


<div class="description">
Set up the WaveFileCreator object based on the arguments passed.Existing chunks are reset.
Set up the WaveFileCreator object based on the arguments passed.
Existing chunks are reset.
</div>


Expand Down Expand Up @@ -2396,7 +2403,8 @@ <h5>Parameters:</h5>



<td class="description last">The sample rate. Integers like 8000, 44100, 48000, 96000, 192000.</td>
<td class="description last">The sample rate.
Integers like 8000, 44100, 48000, 96000, 192000.</td>
</tr>


Expand Down Expand Up @@ -2427,7 +2435,9 @@ <h5>Parameters:</h5>



<td class="description last">The audio bit depth code. One of '4', '8', '8a', '8m', '16', '24', '32', '32f', '64' or any value between '8' and '32' (like '12').</td>
<td class="description last">The audio bit depth code.
One of '4', '8', '8a', '8m', '16', '24', '32', '32f', '64'
or any value between '8' and '32' (like '12').</td>
</tr>


Expand Down Expand Up @@ -2494,7 +2504,8 @@ <h5>Parameters:</h5>



<td class="description last">Optional. Used to force the container as RIFX with {'container': 'RIFX'}</td>
<td class="description last">Optional. Used to force the container
as RIFX with {'container': 'RIFX'}</td>
</tr>


Expand Down Expand Up @@ -3263,7 +3274,8 @@ <h5>Parameters:</h5>
</td>


<td class="description last">True to return interleaved samples, false to return the samples de-interleaved.</td>
<td class="description last">True to return interleaved samples,
false to return the samples de-interleaved.</td>
</tr>


Expand Down Expand Up @@ -3577,7 +3589,26 @@ <h4 class="name" id="listCuePoints"><span class="type-signature"></span>listCueP


<div class="description">
Return an array with all cue points in the file, in the order they appearin the file.Objects representing cue points/regions look like this: { position: 500, // the position in milliseconds label: 'cue marker 1', end: 1500, // the end position in milliseconds dwName: 1, dwPosition: 0, fccChunk: 'data', dwChunkStart: 0, dwBlockStart: 0, dwSampleOffset: 22050, // the position as a sample offset dwSampleLength: 3646827, // length as a sample count, 0 if not a region dwPurposeID: 544106354, dwCountry: 0, dwLanguage: 0, dwDialect: 0, dwCodePage: 0, }
Return an array with all cue points in the file, in the order they appear
in the file.
Objects representing cue points/regions look like this:
{
position: 500, // the position in milliseconds
label: 'cue marker 1',
end: 1500, // the end position in milliseconds
dwName: 1,
dwPosition: 0,
fccChunk: 'data',
dwChunkStart: 0,
dwBlockStart: 0,
dwSampleOffset: 22050, // the position as a sample offset
dwSampleLength: 3646827, // length as a sample count, 0 if not a region
dwPurposeID: 544106354,
dwCountry: 0,
dwLanguage: 0,
dwDialect: 0,
dwCodePage: 0,
}
</div>


Expand Down Expand Up @@ -4025,7 +4056,25 @@ <h5>Parameters:</h5>



<td class="description last">A object with the data of the cue point.# Only required attribute to create a cue point:pointData.position: The position of the point in milliseconds# Optional attribute for cue points:pointData.label: A string label for the cue point# Extra data used for regionspointData.end: A number representing the end of the region, in milliseconds, counting from the start of the file. If no end attr is specified then no region is created.# You may also specify the following attrs for regions, all optional:pointData.dwPurposeIDpointData.dwCountrypointData.dwLanguagepointData.dwDialectpointData.dwCodePage</td>
<td class="description last">A object with the data of the cue point.

# Only required attribute to create a cue point:
pointData.position: The position of the point in milliseconds

# Optional attribute for cue points:
pointData.label: A string label for the cue point

# Extra data used for regions
pointData.end: A number representing the end of the region,
in milliseconds, counting from the start of the file. If
no end attr is specified then no region is created.

# You may also specify the following attrs for regions, all optional:
pointData.dwPurposeID
pointData.dwCountry
pointData.dwLanguage
pointData.dwDialect
pointData.dwCodePage</td>
</tr>


Expand Down Expand Up @@ -4475,7 +4524,8 @@ <h4 class="name" id="setTag"><span class="type-signature"></span>setTag<span cla


<div class="description">
Write a RIFF tag in the INFO chunk. If the tag do not exist,then it is created. It if exists, it is overwritten.
Write a RIFF tag in the INFO chunk. If the tag do not exist,
then it is created. It if exists, it is overwritten.
</div>


Expand Down Expand Up @@ -4968,7 +5018,8 @@ <h5>Parameters:</h5>
</td>


<td class="description last">The new bit depth of the samples. One of '8' ... '32' (integers), '32f' or '64' (floats)</td>
<td class="description last">The new bit depth of the samples.
One of '8' ... '32' (integers), '32f' or '64' (floats)</td>
</tr>


Expand Down Expand Up @@ -5007,7 +5058,8 @@ <h5>Parameters:</h5>
</td>


<td class="description last">A boolean indicating if the resolution of samples should be actually changed or not.</td>
<td class="description last">A boolean indicating if the
resolution of samples should be actually changed or not.</td>
</tr>


Expand Down Expand Up @@ -5123,7 +5175,8 @@ <h4 class="name" id="toBuffer"><span class="type-signature"></span>toBuffer<span


<div class="description">
Return a byte buffer representig the WaveFileParser object as a .wav file.The return value of this method can be written straight to disk.
Return a byte buffer representig the WaveFileParser object as a .wav file.
The return value of this method can be written straight to disk.
</div>


Expand Down Expand Up @@ -5315,7 +5368,8 @@ <h4 class="name" id="toDataURI"><span class="type-signature"></span>toDataURI<sp


<div class="description">
Return a DataURI string representig the WaveFile object as a .wav file.The return of this method can be used to load the audio in browsers.
Return a DataURI string representig the WaveFile object as a .wav file.
The return of this method can be used to load the audio in browsers.
</div>


Expand Down
20 changes: 20 additions & 0 deletions esbuild.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import esbuild from 'esbuild';
import fs from 'fs';
// Polyfills
const polyfills = fs.readFileSync('./scripts/polyfills.js', 'utf8');

const formats = ['esm', 'cjs']

for await (const format of formats) {
await esbuild.build({
entryPoints: ['index.js'],
bundle: true,
minify: true,
banner: {
js: polyfills,
},
format,
outfile: `dist/wavefile.${format}.${format === 'esm' ? 'js' : 'cjs'}`,
})
}

Loading