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

@betomorrow/clean-wording

v1.0.5

Published

Utility for cleaning up unused wordings.

Downloads

67

Readme

Clean-Wording

Description

Utility for cleaning up unused wordings.

Create configuration

Create wording config file named for exemple '.clean_wording_config.json' at your project root location.

All required config :

{
    "projectSourcePath": "<path_to_source_files>",
    "projectSourceParser": {
        "parser": [
            { "type":"match", "regex": "<regex>" },
        ]
    },
    "wordingsSource": "<path_to_source_wordings_file_or_url>",
}

All configs :

{
    "projectSourcePath": "<path_to_source_files>",
    "projectSourceParser": {
        "parser": [
            {
                "type": "<match/replace>",
                "regex": "<regex_1_1>",
                "position": <match__extract_value_index_default_1>,
                "by": "<replace__value_default_empty>",
                "post_regex": {
                    "type":"<match/replace>",
                    "regex": "<regex_1_2>",
                    "post_regex": {
                        ...
                    }
                }
            },
            ...
        ],
        onlyFilesWithExtensions: ["<extension_1>", ...]
    },
    "wordingsSource": "<path_to_source_wordings_file_or_url>",
    "wordingsSourceParser": {
        "replaces": [
            { "regex": "<regex>", "by": "<value_default_empty>" },
            ...
        ],
    },
    "compare" : {
        "dynamicRegexValue": "<regex>"
    }
}

Exemple for a React project (simple) :

{
    "projectSourcePath": "src/",
    "projectSourceParser": {
        "parser": [{ "type": "match", "regex": "i18n\\.t\\(\"((.|\n)+?)\"" }]
    },
    "wordingsSource": "assets/strings/map.json",
    "wordingsSourceParser": {
        "replaces": [
            {
                "_comment": "remove .zero & .one & .other",
                "regex": "(.zero|.one|.other)$"
            }
        ]
    }
}

Exemple for a React project (more complexe -> trying to manage dynamic wordings) :

{
  "projectSourcePath": "src/",
  "projectSourceParser": {
    "parser": [
      {
        "_comment": "match all I18n.t(*)",
        "type": "match",
        "regex": "I18n\\.t\\(((?:[^()]*|\\((?:[^()]*|\\([^()]*\\))*\\))*)\\)",
        "post_regex": {
          "_comment": "match all \"*\" ",
          "type": "match",
          "regex": "(?:\"|`|')(.*?)(?:\"|`|')",
          "post_regex": {
            "_comment": "replace dynamic value by *",
            "type": "replace",
            "regex": "(\\${.*})",
            "by": "*",
            "post_regex": {
              "_comment": "keep only valid wordings because previous regex can have bad values",
              "type": "replace",
              "regex": "^.*[^a-zA-Z0-9._\\-*].*$",
            }
          }
        }
      }
    ]
  },
  "wordingsSource": "assets/strings/EN-en.json"
  "wordingsSourceParser": {
        "replaces": [
            {
                "_comment": "remove wordings used only for config, store, ...",
                "regex": "(NSCameraUsageDescription)|<...>"
            }
        ]
    }
  "compare" : {
    "dynamicRegexValue": "\\*"
  }
}

Exemple for a Flutter project :

{
    "projectSourcePath": "lib/src/",
    "projectSourceParser": {
        "parser": [
            { "type": "match", "regex": "context\\.curLocalizations\\.([a-zA-Z0-9_]+)" },
            { "type": "match", "regex": "AppLocalizations\\.of\\(context\\)!?\\.([a-zA-Z0-9_]+)" }
        ]
    },
    "wordingsSource": "lib/asset/translations/intl_fr.arb",
    "wordingsSourceParser": {
        "replaces": [
            {
                "_comment": "remove all keys begining by @",
                "regex": "^@.*"
            }
        ]
    }
}

Integration & Run

React

Install it as dev dependencies

# With npm

npm install @betomorrow/clean-wording --save-dev

# With yarn

yarn add @betomorrow/clean-wording --save-dev

Add scripts lines to invoke tools easily with npm in package.json

{
    "scripts": {
        "clean-wording": "clean-wording -c .clean_wording_config.json"
    }
}

Flutter

Use directly this command

npx -p @betomorrow/clean-wording clean-wording -c .clean_wording_config.json

Command options

Options:
    -c, --config <path>                [Required] Path on config json file (ex: .clean_wording_config.json)
    -sp, --showAllProjectWordingKeys   Show all detected project wording-keys
    -sf, --showAllFileWordingKeys      Show all detected file wording-keys
    -spo, --showOrphanProjectKeys      Show project wording-keys not present in the file wording-keys
    -sfo, --showOrphanFileWordingKeys  [Default] Show file wording-keys not present in the project wording-keys
    -v, --verbose                      show verbose logs
    -h, --help                         display help for command