Skip to content

javascript-utilities/to-chunks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

To Chunks

Chunks input string into array based on RegExp

Byte size of To Chunks Open Issues Open Pull Requests Latest commits to-chunks Demos



Requirements

NodeJS development dependencies may be installed via NPM...

npm install

Note, dependencies are only required if contributing to development of this project; otherwise no external dependencies are required to utilize this repository.


Quick Start

Install via NodeJS

npm install javascript-utilities/to-chunks

Install via Git Modules

If using this project with GitHub Pages, then this repository encourages the use of Git Submodules to track it as a dependency

Bash Variables

_module_name='to-chunks'
_module_https_url="https://github.com/javascript-utilities/to-chunks.git"
_module_base_dir='_layouts/modules'
_module_path="${_module_base_dir}/${_module_name}"

Bash Submodule Commands

cd "<your-git-project-path>"

git checkout gh-pages
mkdir -vp "${_module_base_dir}"

git submodule add\
 -b main --name "${_module_name}"\
 "${_module_https_url}" "${_module_path}"

Your ReadMe File

Suggested additions for your ReadMe.md file so everyone has a good time with submodules

Clone with the following to avoid incomplete downloads


    git clone --recurse-submodules <url-for-your-project>


Update/upgrade submodules via


    git submodule update --init --merge --recursive

Commit and Push

git add .gitmodules
git add "${_module_path}"


## Add any changed files too


git commit -F- <<'EOF'
:heavy_plus_sign: Adds `javascript-utilities/to-chunks#1` submodule



**Additions**


- `.gitmodules`, tracks submodules AKA Git within Git _fanciness_

- `README.md`, updates installation and updating guidance

- `_modules_/to-chunks`, Chunks input string into array based on RegExp
EOF


git push origin gh-pages

πŸŽ‰ Excellent πŸŽ‰ your project is now ready to begin unitizing code from this repository!

Usage

How to utilize this repository


Use With NodeJS

const toChunks = require('to-chunks');

const input = '1.15.4-2Beta';
const regular_expression = new RegExp('\\.|-|[a-zA-Z]+');

const chunks = toChunks(input, regular_expression);

console.log(chunks);
//> ['1', '.', '15', '.', '4', '-', '2', 'Beta']

Use With Web Browser

assets/js/index.js

"use strict";


/**
 * Updates output element after obtaining input element values
 * @param {MouseEvent:click} _event
 * @listens MouseEvent:click
 */
function to_chunks__button(_event) {
  const expression__input__element = document.getElementById('expression__input');
  const stringy__input__element = document.getElementById('stringy__input');
  const to_chunks__output__element = document.getElementById('to_chunks__output');

  const regular_expression = new RegExp(expression__input__element.value);
  const input = stringy__input__element.value;
  const chunks = toChunks(input, expression__input__element.value);

  to_chunks__output__element.value = JSON.stringify(chunks);
}


window.addEventListener('load', (_event) => {
  document.getElementById('to_chunks__button').addEventListener('click', to_chunks__button);
  to_chunks__button(undefined);
});

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>To Chunks JavaScript Example</title>
    <script src="assets/js/modules/to-chunks/to-chunks.js" defer></script>
    <script src="assets/js/index.js" defer></script>
  </head>
  <body>
    <div>
      <label for="expression__input">Regular Expression: </label>
      <input id="expression__input" type="text" value="[0-9]+|[a-zA-Z]+">
      <br>

      <label for="stringy__input">String Like Input: </label>
      <input id="stringy__input" type="text" value="p1.15-2.Beta">
      <br>
    </div>

    <div>
      <input id="to_chunks__button" type="button" value="Re-Chunkify">
      <br>

      <label for="to_chunks__output">toChunks Output: </label>
      <input id="to_chunks__output" type="text" readonly>
    </div>
  </body>
</html>

Notes

This repository may not be feature complete and/or fully functional, Pull Requests that add features or fix bugs are certainly welcomed.


One bit that I found odd between Web Browser and NodeJS is the \\.|-|[a-zA-Z]+ expression with pre1.15.4-2.Beta produces different results, but only when fed from HTML elements, eg...

NodeJS

toChunks('p1.15.4-2.Beta', '\\.|-|[a-zA-Z]+');
//> ['p', '1', '.', '15', '.', '4', '-', '2', '.', 'Beta']

Web Browser

toChunks('p1.15.4-2.Beta', '\\.|-|[a-zA-Z]+');
//> ['p', '1.15', '-', '2.', 'Beta']

Note, this only happens via input from HTML text elements, not from the JavaScript console.

... But adjusting the expression to \.|-|[a-zA-Z]+ within the HTML input element seems to function consistently.


Contributing

Options for contributing to to-chunks and javascript-utilities

Forking

Start making a Fork of this repository to an account that you have write permissions for.

  • Add remote for fork URL. The URL syntax is git@github.com:<NAME>/<REPO>.git...
cd ~/git/hub/javascript-utilities/to-chunks

git remote add fork git@github.com:<NAME>/to-chunks.git
  • Commit your changes and push to your fork, eg. to fix an issue...
cd ~/git/hub/javascript-utilities/to-chunks


git commit -F- <<'EOF'
:bug: Fixes #42 Issue


**Edits**


- `<SCRIPT-NAME>` script, fixes some bug reported in issue
EOF


git push fork main

Note, the -u option may be used to set fork as the default remote, eg. git push fork main however, this will also default the fork remote for pulling from too! Meaning that pulling updates from origin must be done explicitly, eg. git pull origin main

  • Then on GitHub submit a Pull Request through the Web-UI, the URL syntax is https://github.com/<NAME>/<REPO>/pull/new/<BRANCH>

Note; to decrease the chances of your Pull Request needing modifications before being accepted, please check the dot-github repository for detailed contributing guidelines.

Sponsor

Thanks for even considering it!

Via Liberapay you may sponsor__shields_io__liberapay on a repeating basis.

Regardless of if you're able to financially support projects such as to-chunks that javascript-utilities maintains, please consider sharing projects that are useful with others, because one of the goals of maintaining Open Source repositories is to provide value to the community.


Attribution


License

Chunks input string into array based on RegExp
Copyright (C) 2020 S0AndS0

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

For further details review full length version of AGPL-3.0 License.