npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

word-file-utils

v2.0.3

Published

Word finder and translation/csv utils

Downloads

27

Readme

Word File Utils

v2.0.3 This is a package i made for myself but can surely be helpful to others, feel free to contribute if you like it.

[!WARNING] If you need excel js install fast-js-excel or take a look at utils-stuff wich is the lighter package. DO NOT INSTALL ALL THREE LIBS CAUSE ONE IS THE "PARENT" OF THE OTHER:

  1. utils-stuff
  2. word-file-utils (including utils-stuff)
  3. fast-js-excel (including exceljs, word-file-utils (including utils-stuff))

So if you install word-file utils you can use the classes of utils-stuff and so on, choose the one for your pourpose.

Install:

npm install word-file-utils

The WordFileUtils extends a simple class with a simple function using the statickidz/node-google-translate-skidz api. With this package comes the alessiovelluso/utils-stuff, a package of server/client utilities that can be helpful, be sure to check the library for all the different utilities you can use. This one has basically two different classes GenericUtils & ClientFilters, you can import them just as explained from the lib documentation but using "word-file-utils" like

import { GenericUtils } from "word-file-utils"

At the moment, the interface of the class is as it follows:

interface  IWordFileUtils {
	separator:string;
	errorTranslationValue:string;
	translationColumnName:string;


	parseCsvToObjectList:<T extends Record<string, string | number | boolean | Date> = GenericObject>(csvFilepath:string, separator?:string) => T[];
	parseObjectListToCsv:<T extends  GenericObject = GenericObject>(data:T[], separator?:string) => string
	writeCsv:<T extends GenericObject = GenericObject>(outputCsv:string, data:T[], separator?:string) => Promise<void>

	translateValue:(value:string, localeIn:string, localeOut:string) => Promise<string>;
	translateObjectList:<T extends GenericObject = GenericObject>(data:T[], { translatingCol, cultureFrom, cultureTo }:TranslationConfig) => Promise<T[]>
	translateCsv:(data:TranslateCsvConfig) => Promise<void>;


	findWords: (folderToRead:string, desiredExtensions:string[], excludeDir:string[], wordToFind:RegExp) => string[],
	writeJson:<T extends GenericObject = GenericObject>(outputCsv:string, data:T[]) => void
}

Initialize the class

import { WordFileUtils } from "word-file-utils"

I raccomand you to initialize a new object every file that requires it. The constructor of WordFileUtils follows this interface:

constructor(data?:TranslationMakerConstructor)
interface TranslationMakerConstructor { separator?:string, errorTranslationValue?:string, translationColumnName?:string }

The separator can be defined here or in any method that requires it as an optional parameter. The errorTranslationValue and translationColumnName are specific to the translations method.

A brief explanation of the methods:

1. Parse Csv To Object List
parseCsvToObjectList:<T extends Record<string, string | number | boolean | Date> = GenericObject>(csvFilepath:string, separator?:string) => T[];

Parse a csv in an array of object, having the key as column name:

Col1,Col2
Value1,Value2
Value3,Value4

This is gonna be parsed as

[
	{ Col1:  Value1, Col2:Value2 },
	{ Col1:  Value3, Col2:Value4 },
]
2. Parse Object List To Csv
parseObjectListToCsv:<T extends GenericObject = GenericObject>(data:T[], separator:string) => string

Returns a string ready to be written down with the specific writeCsv<T = GenericObject>(outputCsv:string, data:T, separator?:string)or passed in an api

3. Write Csv
writeCsv:<T extends GenericObject = GenericObject>(outputCsv:string, data:T[], separator?:string) => Promise<void>

Write a csv locally with an object list parameter, having the column as the object keys. It uses the related parseObjectListToCsv method

4. Translate Value
translateObjectList:<T extends GenericObject = GenericObject>(data:T[], { translatingCol, cultureFrom, cultureTo }:TranslationConfig) => Promise<T[]>

Simply translating a word to the desired one

5. Translate Object List
translateObjectList:(data:GenericObject[], { translatingCol, cultureFrom, cultureTo }:TranslationConfig) => Promise<GenericObject[]>

After specifying the target column, the func return the same object list with an added key of the translation

6. Translate Csv
translateCsv:(data:TranslateCsvConfig) => Promise<void>

Take a csv as input and write the same csv with an added translated_value column. It uses the related parseCsvToObjectList, translateObjectList and writeCsv methods

7. Find Words
findWords: (folderToRead:string, desiredExtensions:string[], wordToFind:RegExp) => string[]

This will search along the whole project, in specified extensions files, and return a list of all the words matching a specified RegExp pattern.

8. Write Json
writeJson:<T extends GenericObject = GenericObject>(outputCsv:string, data:T[]) => void

Easily write a local json

Types

import { GoogleTranslateLocales } from  "./translate.types"


export  interface  TranslationConfig { translatingCol:string, cultureFrom:GoogleTranslateLocales, cultureTo:GoogleTranslateLocales }

export  interface  TranslateCsvConfig  extends  TranslationConfig { csvFilepath:string, outFilepath:string, separator?:string }

export  interface  TranslationMakerConstructor { separator?:string, errorTranslationValue?:string, translationColumnName?:string }