diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c675537 --- /dev/null +++ b/LICENSE @@ -0,0 +1,8 @@ + +ISC License (ISC) + +Copyright 2021 Will Foxall + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/Readme.md b/Readme.md index 7d01c4d..48ae099 100644 --- a/Readme.md +++ b/Readme.md @@ -12,9 +12,22 @@ npm install @wfoxall/timeframe ### Timecode Class +Import the `Timecode` class and create an instance. + ```typescript import {Timecode} from '@wfoxall/timeframe'; +const tc = new Timecode('00:01:02:03',"29.97DF"); + +console.log(tc.toString()); +// 00;01;02;03 +``` + +A `TimecodeError` is thrown if the supplied string or framerate are invalid or incompatible. And the `toString()` class will take care of formatting the timecode correctly (e.g. semicolons for drop timecode). + +Timecodes can be instantiated from a string or framecount, and the framerate can be expressed in any of several ways too (see [Framerate class](#Framerate-Class)): + +```typescript const tc1 = new Timecode('00:01:01:00',"29.97DF"); console.log(tc1.toString()); // 00;01;01;00 @@ -26,7 +39,11 @@ console.log(tc2.toString()); const tc3 = new Timecode(12345,29.97); // 29.97 and 59.94 numbers are interpretted as drop-frame by default console.log(tc3.toString()); // 00;06;51;27 +``` +You can add and subtract timecodes (with matching framerates) using the static method on the Timecode class, or with the method on an existing timecode object: + +```typescript let sum = Timecode.add(tc1,tc2); // Immutable - tc1 and tc2 remain unchanged. console.log(sum.toString()); // 00;02;03;15 @@ -38,7 +55,17 @@ console.log(tc1.toString()); ### Framerate Class -Framerate objects can be instantiated by passing a FramerateLike value. The resulting object can then be used to initialize a Timecode instance. +Framerate objects can be instantiated by passing a `FramerateLike` value. This can be a string, number or object as follows: + +```typescript +let fr1 = "59.94DF" +let fr2 = 59.94 +let fr3 = {numer:60000,denom:1001,drop:true} +``` + +This is particularly useful when marshalling framerates from various formats. For example, some video APIs like to express framerates as a fraction (eg. 29.97 is expressed as 30000/1001). + +The resulting Framerate instance can then be used to initialize a Timecode instance. ```typescript import {Framerate} from '@wfoxall/timeframe'; @@ -52,12 +79,6 @@ console.log(tc.toString()); // 01;59;59;28 ``` -As framerates can be expressed in multiple formats, this is useful for marshelling the same framerate into the same uniform type. For example, the following are the same framerate: -```typescript -let fr1 = "59.94DF" -let fr2 = 59.94 -let fr3 = {numer:60000,denom:1001,drop:true} -``` ## Credit diff --git a/package.json b/package.json index 4454eef..c014eac 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@wfoxall/timeframe", "version": "1.0.1", - "description": "A javascript library for parsing and manipulatio of SMPTE/EBU/Generic timecodes, framerates and framecounts.", + "description": "A javascript library for parsing and manipulation of SMPTE/EBU/Generic timecodes, framerates and framecounts.", "main": "./dist/index.js", "types": "./dist/index.d.ts", "scripts": {