Skip to content

Commit dd565aa

Browse files
authored
Dependencies replace (#98)
* replace itiriri with Array.from * replace dateformat with DateUtils * use forof instead of Array.from
1 parent de82111 commit dd565aa

10 files changed

Lines changed: 64 additions & 70 deletions

File tree

package-lock.json

Lines changed: 1 addition & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
"node": ">=12.16.1"
2323
},
2424
"dependencies": {
25-
"dateformat": "^3.0.3",
2625
"iconv-lite": "^0.6.3",
27-
"itiriri": "^2.0.1",
2826
"os-locale": "^4.0.0",
2927
"uuid": "^8.3.2"
3028
},
@@ -33,7 +31,6 @@
3331
"@testdeck/mocha": "^0.3.3",
3432
"@types/chai": "^4.3.0",
3533
"@types/chai-as-promised": "^7.1.0",
36-
"@types/dateformat": "^3.0.0",
3734
"@types/stream-buffers": "^3.0.2",
3835
"@types/uuid": "^8.3.4",
3936
"@typescript-eslint/eslint-plugin": "^5.15.0",

src/ape/apeTag.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import * as DateFormat from "dateformat";
2-
31
import {ApeTagFooter, ApeTagFooterFlags} from "./apeTagFooter";
42
import {ApeTagItem, ApeTagItemType} from "./apeTagItem";
53
import {ByteVector, StringType} from "../byteVector";
64
import {CorruptFileError} from "../errors";
75
import {File, FileAccessMode} from "../file";
86
import {IPicture, Picture, PictureType} from "../picture";
97
import {Tag, TagTypes} from "../tag";
10-
import {Guards, NumberUtils, StringComparison} from "../utils";
8+
import {DateUtils, Guards, NumberUtils, StringComparison} from "../utils";
119

1210
/**
1311
* Provides a representation of an APEv2 tag which can be read from and written to disk.
@@ -482,12 +480,7 @@ export default class ApeTag extends Tag {
482480
* @remarks Stored in the `DateTagged` item
483481
*/
484482
set dateTagged(value: Date | undefined) {
485-
let strValue: string;
486-
if (value) {
487-
strValue = DateFormat(value, "yyyy-mm-dd HH:MM:ss");
488-
strValue = strValue.replace(" ", "T");
489-
}
490-
this.setStringValue("DateTagged", strValue);
483+
this.setStringValue("DateTagged", DateUtils.format(value));
491484
}
492485

493486
/**

src/id3v2/id3v2Tag.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import * as DateFormat from "dateformat";
2-
import itiriri from "itiriri";
3-
41
import AttachmentFrame from "./frames/attachmentFrame";
52
import CommentsFrame from "./frames/commentsFrame";
63
import FrameFactory from "./frames/frameFactory";
@@ -21,7 +18,7 @@ import {IPicture} from "../picture";
2118
import {Tag, TagTypes} from "../tag";
2219
import {TextInformationFrame, UserTextInformationFrame} from "./frames/textInformationFrame";
2320
import {UrlLinkFrame} from "./frames/urlLinkFrame";
24-
import {Guards} from "../utils";
21+
import {DateUtils, Guards} from "../utils";
2522

2623
/**
2724
* Extends {@link Tag} to provide support for reading and writing tags stored in the ID3v2 format.
@@ -373,9 +370,17 @@ export default class Id3v2Tag extends Tag {
373370
}
374371

375372
// Collapse the instrument lists and return that
376-
this._performersRole = itiriri(map.values())
377-
.map((e: string[]) => e.length > 0 ? e.join("; ") : undefined)
378-
.toArray();
373+
// this._performersRole = Array.from(map.values())
374+
// .map((e: string[]) => e.length > 0 ? e.join("; ") : undefined);
375+
const performersRole = []
376+
for (const roles of map.values()) {
377+
if (roles.length > 0) {
378+
performersRole.push(roles.join('; '))
379+
} else {
380+
performersRole.push(undefined)
381+
}
382+
}
383+
this._performersRole = performersRole
379384
return this._performersRole;
380385
}
381386
/**
@@ -716,12 +721,7 @@ export default class Id3v2Tag extends Tag {
716721
* @remarks Stored in the `TDTG` frame
717722
*/
718723
set dateTagged(value: Date | undefined) {
719-
let strValue: string;
720-
if (value) {
721-
strValue = DateFormat(value, "yyyy-mm-dd HH:MM:ss");
722-
strValue = strValue.replace(" ", "T");
723-
}
724-
this.setTextFrame(FrameIdentifiers.TDTG, strValue);
724+
this.setTextFrame(FrameIdentifiers.TDTG, DateUtils.format(value));
725725
}
726726

727727
/**

src/mpeg4/appleTag.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as DateFormat from "dateformat";
21
import AppleItemListBox from "./boxes/appleItemListBox";
32
import Genres from "../genres";
43
import IsoMetaBox from "./boxes/isoMetaBox";
@@ -9,7 +8,7 @@ import {AppleDataBox, AppleDataBoxFlagType} from "./boxes/appleDataBox";
98
import {ByteVector, StringType} from "../byteVector";
109
import {IPicture, Picture} from "../picture";
1110
import {Tag, TagTypes} from "../tag";
12-
import {ArrayUtils, Guards, NumberUtils} from "../utils";
11+
import {ArrayUtils, DateUtils, Guards, NumberUtils} from "../utils";
1312

1413
export default class AppleTag extends Tag {
1514
/**
@@ -231,15 +230,8 @@ export default class AppleTag extends Tag {
231230
return undefined;
232231
}
233232
/** @inheritDoc */
234-
public set dateTagged(v: Date|undefined) {
235-
let strValue: string;
236-
237-
if (v) {
238-
strValue = DateFormat(v, "yyyy-mm-dd HH:MM:ss");
239-
strValue = strValue.replace(" ", "T");
240-
}
241-
242-
this.setQuickTimeString(Mpeg4BoxType.DTAG, strValue);
233+
public set dateTagged(value: Date|undefined) {
234+
this.setQuickTimeString(Mpeg4BoxType.DTAG, DateUtils.format(value));
243235
}
244236

245237
/** @inheritDoc */

src/ogg/oggPage.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import itiriri from "itiriri";
21
import {ByteVector} from "../byteVector";
32
import {File} from "../file";
43
import {OggPageHeader} from "./oggPageHeader";
@@ -92,8 +91,13 @@ export default class OggPage {
9291
Guards.safeUint(position, "position");
9392

9493
// Check to see if there are any changes to be made
95-
if (itiriri(shiftTable.values()).every((e) => e === 0)) {
96-
return;
94+
// if (Array.from(shiftTable.values()).every((e) => e === 0)) {
95+
// return;
96+
// }
97+
for (const value of shiftTable.values()) {
98+
if (value !== 0) {
99+
return
100+
}
97101
}
98102

99103
while (position < file.length - OggPageHeader.MINIMUM_SIZE) {

src/ogg/oggTag.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import itiriri from "itiriri";
2-
31
import CombinedTag from "../combinedTag";
42
import OggFileSettings from "./oggFileSettings";
53
import XiphComment from "../xiph/xiphComment";
@@ -79,7 +77,12 @@ export default class OggTag extends CombinedTag {
7977
/** @inheritDoc */
8078
// TODO: This value is never updated after a save!!
8179
public get sizeOnDisk(): number {
82-
return itiriri(this._comments.values()).reduce((accum, c) => accum + c.sizeOnDisk, 0);
80+
// return Array.from(this._comments.values()).reduce((accum, c) => accum + c.sizeOnDisk, 0);
81+
let sum = 0
82+
for (const comments of this._comments.values()) {
83+
sum += comments.sizeOnDisk
84+
}
85+
return sum
8386
}
8487

8588
/**

src/riff/riffFile.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import itiriri from "itiriri";
21
import AviFileSettings from "./aviFileSettings";
32
import AviHeader from "./avi/aviHeader";
43
import DivxTag from "./divxTag";
@@ -151,10 +150,16 @@ export default class RiffFile extends File {
151150
const renderedTagBytes = ByteVector.concatenate(... renderedTags);
152151

153152
// Determine the boundaries of the tagging chunks
154-
const taggingChunkIndexes = itiriri(this._taggingChunkIndexes.values())
155-
.filter((i) => i >= 0)
156-
.sort()
157-
.toArray();
153+
// Array.from(this._taggingChunkIndexes.values())
154+
// .filter((i) => i >= 0)
155+
// .sort();
156+
const taggingChunkIndexes: number[] = []
157+
for (const index of this._taggingChunkIndexes.values()) {
158+
if (index >= 0) {
159+
taggingChunkIndexes.push(index)
160+
}
161+
}
162+
taggingChunkIndexes.sort()
158163

159164
let taggingChunkStartIndex: number;
160165
let taggingChunkStart: number;

src/utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,22 @@ export class StringUtils {
345345
return toTrim;
346346
}
347347
}
348+
349+
export class DateUtils {
350+
public static format(date: Date | undefined): string | undefined {
351+
if (!date) {
352+
return undefined
353+
}
354+
355+
const pad = (num: number) => `${num}`.padStart(2, '0')
356+
357+
const year = date.getFullYear();
358+
const month = pad(date.getMonth() + 1);
359+
const day = pad(date.getDate());
360+
const hours = pad(date.getHours());
361+
const minutes = pad(date.getMinutes());
362+
const seconds = pad(date.getSeconds());
363+
364+
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`;
365+
}
366+
}

src/xiph/xiphComment.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import * as DateFormat from "dateformat";
21
import XiphPicture from "./xiphPicture";
32
import XiphSettings from "./xiphSettings";
43
import {ByteVector, StringType} from "../byteVector";
54
import {IPicture, Picture} from "../picture";
65
import {Tag, TagTypes} from "../tag";
7-
import {Guards} from "../utils";
6+
import {DateUtils, Guards} from "../utils";
87

98
/**
109
* Provides support for reading and writing Xiph comment-style tags.
@@ -568,13 +567,11 @@ export default class XiphComment extends Tag {
568567
* @inheritDoc
569568
* @remarks Stored in the `DATETAGGED` field
570569
*/
571-
public set dateTagged(value: Date) {
570+
public set dateTagged(value: Date | undefined) {
572571
if (!value || Number.isNaN(value.getTime())) {
573572
this.removeField("DATETAGGED");
574573
} else {
575-
let dateString = DateFormat(value, "yyyy-mm-dd HH:MM:ss");
576-
dateString = dateString.replace(" ", "T");
577-
this.setFieldAsStrings("DATETAGGED", dateString);
574+
this.setFieldAsStrings("DATETAGGED", DateUtils.format(value));
578575
}
579576
}
580577

0 commit comments

Comments
 (0)