Builds dictionary/object from browser cookies string
This repository depends upon Jekyll which is supported by GitHub Pages, further details about setup can be found from documentation published by the Jekyll maintainers regarding GitHub Pages.
This repository encourages the use of Git Submodules to track dependencies
Bash Variables
_module_name='objectify-cookies'
_module_https_url="https://github.com/javascript-utilities/objectify-cookies.git"
_module_base_dir='assets/javascript/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}"
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
git add .gitmodules
git add "${_module_path}"
## Add any changed files too
git commit -F- <<'EOF'
:heavy_plus_sign: Adds `javascript-utilities/objectify-cookies#1` submodule
**Additions**
- `.gitmodules`, tracks submodules AKA Git within Git _fanciness_
- `README.md`, updates installation and updating guidance
- `_modules_/objectify-cookies`, Builds dictionary/object from browser cookies string
EOF
git push origin gh-pages
π Excellent π your project is now ready to begin unitizing code from this repository!
/assets/js/index.js
function calculateCookieExpiration(days = 1) {
days = Number(days);
if (isNaN(days)) {
days = 1;
}
const date = new Date();
const now = date.getTime();
return date.setTime(now + 1 * 24 * 60 * 60 * 1000);
}
window.addEventListener('load', () => {
document.cookies = `key_name=something;expires=${calculateCookieExpiration()};path=/`;
const cookies = objectifyCookies();
console.log(`cookies['key_name'] -> ${cookies['key_name']}`);
});
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Objectify Cookies Example</title>
<script scr="/assets/javascript/modules/objectify-cookies/objectify-cookies.js"
type="text/javascript"
differ></script>
<script scr="/assets/javascript/index.js"
type="text/javascript"
differ></script>
</head>
<body>
<p>Check the JavaScript console log for output</p>
</body>
</html>
This repository may not be feature complete and/or fully functional, Pull Requests that add features or fix bugs are certainly welcomed.
Options for contributing to objectify-cookies and javascript-utilities
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
[email protected]:<NAME>/<REPO>.git
...
cd ~/git/hub/javascript-utilities/objectify-cookies
git remote add fork [email protected]:<NAME>/objectify-cookies.git
- Commit your changes and push to your fork, eg. to fix an issue...
cd ~/git/hub/javascript-utilities/objectify-cookies
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 setfork
as the default remote, eg.git push fork main
however, this will also default thefork
remote for pulling from too! Meaning that pulling updates fromorigin
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.
Builds dictionary/object from browser cookies string
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.