| import { setWordGoal, setTimeGoal } from '../utils/goalSetting'; | ||
| import { startTracking, endTracking, getTrackingTime } from "../utils/timeTracking"; | ||
| import { WordTracking } from "../plugins/wordTracking"; | ||
| export declare const focusing: { | ||
| setWordGoal: typeof setWordGoal; | ||
| setTimeGoal: typeof setTimeGoal; | ||
| startTracking: typeof startTracking; | ||
| endTracking: typeof endTracking; | ||
| getTrackingTime: typeof getTrackingTime; | ||
| wordTracker: WordTracking; | ||
| WordTracking: typeof WordTracking; | ||
| }; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.focusing = void 0; | ||
| const goalSetting_1 = require("../utils/goalSetting"); | ||
| const timeTracking_1 = require("../utils/timeTracking"); | ||
| const wordTracking_1 = require("../plugins/wordTracking"); | ||
| const wordTracker = wordTracking_1.WordTracking.getInstance(); | ||
| exports.focusing = { | ||
| setWordGoal: goalSetting_1.setWordGoal, | ||
| setTimeGoal: goalSetting_1.setTimeGoal, | ||
| startTracking: timeTracking_1.startTracking, | ||
| endTracking: timeTracking_1.endTracking, | ||
| getTrackingTime: timeTracking_1.getTrackingTime, | ||
| wordTracker, | ||
| WordTracking: wordTracking_1.WordTracking | ||
| }; |
| export declare enum CountingMode { | ||
| AllWords = "all", | ||
| UniqueWords = "unique", | ||
| SpecificWordOccurences = "specific" | ||
| } | ||
| export interface WordTrackingEvent { | ||
| data: string; | ||
| context: { | ||
| data: number; | ||
| }; | ||
| } | ||
| type WordCountChangeListener = (count: number) => void; | ||
| /** | ||
| * @name WordTracking | ||
| * @description Tracks the number of words in a given string | ||
| * @example WordTracking.getInstance().getWordCount() | ||
| * | ||
| */ | ||
| export declare class WordTracking { | ||
| private static instance; | ||
| private readonly wordRegex; | ||
| private tracking; | ||
| private wordCountMap; | ||
| private listeners; | ||
| private constructor(); | ||
| static getInstance(wordBoundaryChars?: string[]): WordTracking; | ||
| /** | ||
| * @name startTracking | ||
| * @description Starts tracking the number of words in a given string | ||
| * @example WordTracking.getInstance().startTracking() | ||
| */ | ||
| startTracking(): void; | ||
| stopTracking(): void; | ||
| private handleInput; | ||
| private countWords; | ||
| private updateWordCountMap; | ||
| private calculateTotalWordOccurences; | ||
| updateWordCount(event: WordTrackingEvent, wordCount: number): void; | ||
| getWordCount(mode?: CountingMode): number; | ||
| subscribe(listener: WordCountChangeListener): void; | ||
| unsubscribe(listener: WordCountChangeListener): void; | ||
| private notifyListeners; | ||
| } | ||
| export {}; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.WordTracking = exports.CountingMode = void 0; | ||
| var CountingMode; | ||
| (function (CountingMode) { | ||
| CountingMode["AllWords"] = "all"; | ||
| CountingMode["UniqueWords"] = "unique"; | ||
| CountingMode["SpecificWordOccurences"] = "specific"; | ||
| })(CountingMode || (exports.CountingMode = CountingMode = {})); | ||
| /** | ||
| * @name WordTracking | ||
| * @description Tracks the number of words in a given string | ||
| * @example WordTracking.getInstance().getWordCount() | ||
| * | ||
| */ | ||
| class WordTracking { | ||
| constructor(wordBoundaryChars = [' ', '-', '_']) { | ||
| const wordBoundaryCharsPattern = wordBoundaryChars.map((char) => `\\${char}`).join(''); | ||
| this.wordRegex = new RegExp(`\\b\\w+[${wordBoundaryCharsPattern}]?`, 'gi'); | ||
| this.tracking = false; | ||
| this.wordCountMap = new Map(); | ||
| this.listeners = []; | ||
| } | ||
| static getInstance(wordBoundaryChars) { | ||
| if (!WordTracking.instance) { | ||
| WordTracking.instance = new WordTracking(wordBoundaryChars); | ||
| } | ||
| return WordTracking.instance; | ||
| } | ||
| /** | ||
| * @name startTracking | ||
| * @description Starts tracking the number of words in a given string | ||
| * @example WordTracking.getInstance().startTracking() | ||
| */ | ||
| startTracking() { | ||
| if (this.tracking) { | ||
| this.tracking = true; | ||
| this.wordCountMap.clear(); | ||
| document.addEventListener("input", this.handleInput); | ||
| } | ||
| } | ||
| stopTracking() { | ||
| if (this.tracking) { | ||
| this.tracking = false; | ||
| document.removeEventListener('input', this.handleInput); | ||
| } | ||
| } | ||
| handleInput(event) { | ||
| const target = event.target; | ||
| const inputValue = target.value; | ||
| const wordCount = this.countWords(inputValue, CountingMode.AllWords); // Default to all words | ||
| this.wordCountMap.clear(); | ||
| this.wordCountMap.set(inputValue.toLowerCase(), wordCount); | ||
| // Notify listeners about a change in word count | ||
| this.notifyListeners(this.wordCountMap.get(inputValue.toLowerCase()) || 0); | ||
| } | ||
| countWords(text, mode) { | ||
| const matches = text.match(this.wordRegex); | ||
| if (!matches) | ||
| return 0; | ||
| switch (mode) { | ||
| case CountingMode.AllWords: | ||
| return matches.length; | ||
| case CountingMode.UniqueWords: | ||
| const uniqueWords = new Set(matches.map((word) => word.toLowerCase())); | ||
| return uniqueWords.size; | ||
| case CountingMode.SpecificWordOccurences: | ||
| this.updateWordCountMap(matches.map((word) => word.toLowerCase())); | ||
| return this.calculateTotalWordOccurences(); | ||
| default: | ||
| throw new Error(`Invalid counting mode: ${mode}`); | ||
| } | ||
| } | ||
| updateWordCountMap(words) { | ||
| words.forEach((word) => { | ||
| const count = this.wordCountMap.get(word) || 0; | ||
| this.wordCountMap.set(word, count + 1); | ||
| }); | ||
| } | ||
| calculateTotalWordOccurences() { | ||
| let totalOccurences = 0; | ||
| this.wordCountMap.forEach((count) => { | ||
| totalOccurences += count; | ||
| }); | ||
| return totalOccurences; | ||
| } | ||
| // @ts-ignore | ||
| updateWordCount(event, wordCount) { | ||
| // @ts-ignore | ||
| const wordCount = this.countWords(event.data); | ||
| // @ts-ignore | ||
| event.context.data = wordCount; | ||
| } | ||
| getWordCount(mode = CountingMode.AllWords) { | ||
| return this.countWords([...this.wordCountMap.keys()].join(' '), mode); | ||
| } | ||
| subscribe(listener) { | ||
| this.listeners.push(listener); | ||
| } | ||
| unsubscribe(listener) { | ||
| const index = this.listeners.indexOf(listener); | ||
| if (index !== -1) { | ||
| this.listeners.splice(index, 1); | ||
| } | ||
| } | ||
| notifyListeners(count) { | ||
| this.listeners.forEach((listener) => listener(count)); | ||
| } | ||
| } | ||
| exports.WordTracking = WordTracking; |
| export declare function setWordGoal(goal: number): void; | ||
| export declare function setTimeGoal(goal: number): void; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.setTimeGoal = exports.setWordGoal = void 0; | ||
| let wordGoal = 0; | ||
| let timeGoal = 0; | ||
| function setWordGoal(goal) { | ||
| wordGoal = goal; | ||
| } | ||
| exports.setWordGoal = setWordGoal; | ||
| function setTimeGoal(goal) { | ||
| timeGoal = goal; | ||
| } | ||
| exports.setTimeGoal = setTimeGoal; |
| export declare function startTracking(): void; | ||
| export declare function endTracking(): void; | ||
| export declare function getTrackingTime(): number; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.getTrackingTime = exports.endTracking = exports.startTracking = void 0; | ||
| // @ts-ignore | ||
| let startTime, endTime; | ||
| function startTracking() { | ||
| startTime = new Date(); | ||
| } | ||
| exports.startTracking = startTracking; | ||
| function endTracking() { | ||
| endTime = new Date(); | ||
| } | ||
| exports.endTracking = endTracking; | ||
| function getTrackingTime() { | ||
| // @ts-ignore | ||
| const timeDiff = endTime.getTime() - startTime.getTime(); | ||
| return timeDiff / 1000; | ||
| } | ||
| exports.getTrackingTime = getTrackingTime; |
+1
-1
| { | ||
| "name": "focusing", | ||
| "version": "1.1.1", | ||
| "version": "1.1.2", | ||
| "description": "Focusing tracks your focus and helps you stay on task.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
12289
160.58%10
400%219
Infinity%