Skip to content

Commit 8b3b136

Browse files
author
craig
committed
1.0.0 / 2022-03-17
================== * Initial npm publish - @craigparra
1 parent ed1036a commit 8b3b136

File tree

15 files changed

+15836
-2
lines changed

15 files changed

+15836
-2
lines changed

.eslintrc.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"commonjs": true,
5+
"es2021": true,
6+
"mocha" : true
7+
},
8+
"plugins": [
9+
"cucumber"
10+
],
11+
"extends": [
12+
"airbnb-base"
13+
],
14+
"parserOptions": {
15+
"ecmaVersion": 12,
16+
"requireConfigFile": false
17+
},
18+
"parser": "@babel/eslint-parser",
19+
"rules": {
20+
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
21+
"cucumber/async-then": ["error", { "All": false, "words": [ ] }],
22+
"cucumber/expression-type": 2,
23+
"cucumber/no-restricted-tags": [2, "wip", "broken", "foo"],
24+
"cucumber/no-arrow-functions": 2,
25+
"import/no-extraneous-dependencies": ["error", { "devDependencies": ["test/**/*.js", "features/**/*.js"] }]
26+
}
27+
}

.github/workflows/node.js.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Node.js CI
5+
6+
on:
7+
workflow_dispatch:
8+
push:
9+
branches: [ main ]
10+
pull_request:
11+
branches: [ main ]
12+
13+
jobs:
14+
build:
15+
16+
runs-on: ubuntu-latest
17+
18+
strategy:
19+
matrix:
20+
node-version: [16.x]
21+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
22+
23+
steps:
24+
- uses: actions/checkout@v2
25+
- name: Use Node.js ${{ matrix.node-version }}
26+
uses: actions/setup-node@v2
27+
with:
28+
node-version: ${{ matrix.node-version }}
29+
cache: 'npm'
30+
- run: npm ci
31+
- run: npm run lint
32+
- run: npm run build
33+

.github/workflows/npm-publish.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3+
4+
name: Node.js Package
5+
6+
on:
7+
workflow_dispatch:
8+
release:
9+
types: [created]
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-node@v2
17+
with:
18+
node-version: 16
19+
- run: npm ci
20+
- run: npm run lint
21+
22+
publish-npm:
23+
needs: build
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v2
27+
- uses: actions/setup-node@v2
28+
with:
29+
node-version: 16
30+
registry-url: https://registry.npmjs.org/
31+
- run: npm ci
32+
- run: npm run build
33+
- run: npm publish
34+
env:
35+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

.gitignore

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Diagnostic reports (https://nodejs.org/api/report.html)
7+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
8+
9+
# Runtime data
10+
pids
11+
*.pid
12+
*.seed
13+
*.pid.lock
14+
15+
# Coverage directory used by tools like istanbul
16+
coverage
17+
*.lcov
18+
19+
# nyc test coverage
20+
.nyc_output
21+
22+
# node-waf configuration
23+
.lock-wscript
24+
25+
# Compiled binary addons (https://nodejs.org/api/addons.html)
26+
build/Release
27+
28+
# Dependency directories
29+
node_modules/
30+
31+
# Optional npm cache directory
32+
.npm
33+
34+
# Optional eslint cache
35+
.eslintcache
36+
37+
# Microbundle cache
38+
.rpt2_cache/
39+
.rts2_cache_cjs/
40+
.rts2_cache_es/
41+
.rts2_cache_umd/
42+
43+
# Optional REPL history
44+
.node_repl_history
45+
46+
# Output of 'npm pack'
47+
*.tgz
48+
/.idea/
49+
50+
test-treeshake/*-umd.js
51+
amd
52+
cjs
53+
/alt-javascript-logger-node-*-pre*

.npmignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.nyc_output
2+
/config
3+
/coverage
4+
/features
5+
/test
6+
/node_modules
7+
.*

.nycrc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"cache": false,
3+
"check-coverage": true,
4+
"lines": 95,
5+
"statements": 95,
6+
"functions": 90,
7+
"branches": 90,
8+
"reporter": [
9+
"html",
10+
"text",
11+
"text-summary"
12+
],
13+
"all": true,
14+
"instrument": true,
15+
"exclude": [
16+
"dist/**/*.js",
17+
"coverage/**/*"
18+
]
19+
}

Cookies.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
export default class Cookies {
2+
constructor(logger) {
3+
this.qualifier = '@alt-javascript/cookies';
4+
this.logger = logger;
5+
}
6+
7+
setCookie(cname, cvalue, exdays, samesite) {
8+
const d = new Date();
9+
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
10+
const expires = `expires=${d.toUTCString()}`;
11+
const cookie = `${cname}=${cvalue};${expires};path=/;SameSite=${samesite || 'Strict'}`;
12+
document.cookie = cookie;
13+
this.logger?.debug(`Set document.cookie as: ${cookie}`);
14+
}
15+
16+
deleteCookie(cname) {
17+
const d = new Date();
18+
d.setTime(0);
19+
const expires = `expires=${d.toUTCString()}`;
20+
const cookie = `${cname}=;${expires};path=/`;
21+
document.cookie = cookie;
22+
this.logger?.debug(`Delete (expire) document.cookie as: ${cname}=${cookie}`);
23+
}
24+
25+
getCookie(cname) {
26+
const name = `${cname}=`;
27+
const ca = document.cookie.split(';');
28+
for (let i = 0; i < ca.length; i++) {
29+
let c = ca[i];
30+
while (c.charAt(0) === ' ') {
31+
c = c.substring(1);
32+
}
33+
if (c.indexOf(name) === 0) {
34+
const cookie = c.substring(name.length, c.length);
35+
this.logger?.debug(`Found cookie: ${cname}=${cookie}`);
36+
return c.substring(name.length, c.length);
37+
}
38+
}
39+
this.logger?.debug(`Cookie not found: ${cname}`);
40+
return '';
41+
}
42+
43+
getCookies() {
44+
const result = document.cookie.split(';').reduce((cookies, cookie) => {
45+
const [name, value] = cookie.split('=').map((c) => c.trim());
46+
// eslint-disable-next-line no-param-reassign
47+
cookies[name] = value;
48+
return cookies;
49+
}, {});
50+
this.logger?.debug(`Found cookies: ${result}`);
51+
return result;
52+
}
53+
}

History.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1.0.0 / 2022-03-17
2+
==================
3+
4+
* Initial npm publish - @craigparra

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021,2022 Craig Parravicini
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,51 @@
1-
# cookies
2-
Simple utility to ease the use of browser cookies
1+
A Simple Log Facade for JavaScript
2+
===================================
3+
4+
[![NPM](https://nodei.co/npm/@alt-javascript/logger.svg?downloads=true&downloadRank=true)](https://nodei.co/npm/@alt-javascript/logger/)
5+
<br/>
6+
![Language Badge](https://img.shields.io/github/languages/top/craigparra/alt-logger)
7+
![Package Badge](https://img.shields.io/npm/v/@alt-javascript/logger) <br/>
8+
[release notes](https://github.com/craigparra/alt-logger/blob/main/History.md)
9+
10+
<a name="intro">Introduction</a>
11+
--------------------------------
12+
Simple utility to ease the use of browser cookies.
13+
14+
<a name="usage">Usage</a>
15+
-------------------------
16+
17+
18+
The module is also able to be used directly in the browser, as an IIFE (Immediately Invoked Function Expression),
19+
as follows:
20+
21+
```html
22+
<script src="https://cdn.jsdelivr.net/npm/@alt-javascript/cookies/dist/alt-javascript-cookies-iife.js"></script>
23+
24+
<script>
25+
cookies.setCookie('somecookie','giveitavalue',365,'Strict');// expires in 365 days, SameSite == Strict (default)
26+
cookies.getCookie('somecookie');
27+
cookies.deleteCookie("somecookie");
28+
</script>
29+
```
30+
31+
Or import the ES6 module bundle from a module, as follows:
32+
33+
```javascript
34+
import { Cookies } from 'https://cdn.jsdelivr.net/npm/@alt-javascript/cookies'
35+
36+
let cookies = new Cookies();
37+
38+
//...as above
39+
```
40+
41+
### Logger
42+
43+
The Cookies class optionally accepts an @alt-javascript/logger, an is configured with the '@alt-javascript/cookies/Cookies'
44+
qualifier by default when using with @alt-javascript/boot
45+
46+
<a name="license">License</a>
47+
-----------------------------
48+
49+
May be freely distributed under the [MIT license](https://github.com/alt-javascript/cookies/main/LICENSE).
50+
51+
Copyright (c) 2021-2022 Craig Parravicini

0 commit comments

Comments
 (0)