Git Product home page Git Product logo

txttransformer's Introduction

txtTransformer

This Golang package is a personal microlibrary to help developing scripts that transforms large numbers of text files. It's being built to make programatic changes to thousands of html files.

Include library

To include the libray on your project, first download it:

go get github.com/osvik/txttransformer

And import it in your code:

import (
    "github.com/osvik/txttransformer"
)

File functions

Functions to read, write, search and filter files and paths.

FindFiles

Finds all files recursively, ignoring folders.

filesInsideFoo := txttransformer.FindFiles("testdata/foo")

FilterPaths

Filters paths by extension. Use without the dot, like html or txt.

listTxtPaths := txttransformer.FilterPaths(filesInsideFoo, "txt")

ReadListPaths

Reads a list of paths from a txt file. One path per line.

listTxtPaths := txttransformer.ReadListPaths("paths.txt")

PrintListPaths

Prints the list of files.

txttransformer.PrintListPaths(listTxtPaths)

CreatePathFolder

Checks if the folder for the current path exists and creates it if not.

txttransformer.CreatePathFolder("testdata/foo/bar/file.txt")

ReadTextFile

Reads a file into a string.

myTxtFile := txttransformer.ReadTextFile("testdata/file.txt")

WriteTextFile

Writes a string as a file.

txttransformer.WriteTextFile("testdata/foo/bar/file.txt", myTxtFile)

Strings (files as strings)

ReplaceAllText

Replaces text in multiline strings.

changedText := txttransformer.ReplaceAllText(originalText, "is", "é")

ReplaceMatchedText

Replaces text that matches the regular expression by new text.

changedText := txttransformer.ReplaceMatchedText(originalText, `do\!`, "Xooer")

ReplaceMatchedTextFunction

Replaces text caught in regularExp by the result of the function.

changedText := txttransformer.ReplaceMatchedTextFunction( originalText, `do\!$`, func(inputExp string) string {
    if (inputExp == "do!") {
        return "Work"
    }
    return "Sleep"
})

txttransformer's People

Contributors

osvik avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.