Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish tests and config build #18

Merged
merged 5 commits into from
May 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
494 changes: 297 additions & 197 deletions .eslintrc.json

Large diffs are not rendered by default.

17 changes: 1 addition & 16 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,4 @@ This is a non exhaustive guide for contributing to this project, and you can con

## Styleguide

I'm constantly trying to improve the overall coding experience, but until we have ES Lint and Prettier fine tunned, there are some rules that should be followed.

Some things may sound obvious to the more experienced developer, but are based on previous pull requests received by this project.

#### Don't use `var`

```javascript
// bad
var something = 'hi'

// good
const something = 'hi'
let otherThing = 'hey'
```

#### Function titles should describe what the function do
Refer to the `eslint` configuration file.
317 changes: 1 addition & 316 deletions dist/sharect.js

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,17 @@ <h2>Sharect 2</h2>
</p>
<script src="dist/sharect.js"></script>
<script>
Sharect.default
Sharect
.config({
twitterUsername: "estevanmaito",
backgroundColor: "#C53364",
iconColor: "#fff",
selectableElements: ['p']
})
.appendCustomShareButtons([
{
icon: '<svg version="1.1" width="24" height="24" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve"><g><g transform="translate(0.000000,511.000000) scale(0.100000,-0.100000)"><path d="M7744.8,4150.2c-192.2-72.1-353.5-181.9-490.8-332.9L7130.5,3680l-298.6,89.2c-243.6,75.5-374.1,92.6-679.5,92.6c-343.2,3.4-398.1-3.4-590.3-92.6c-236.8-109.8-473.6-332.9-593.7-566.2c-96.1-192.2-192.2-576.5-219.6-899.1l-24-260.8l-298.5-24c-624.6-48-1280-226.5-1811.9-490.7l-312.3-154.4l-271.1,130.4c-260.8,130.4-274.5,133.8-645.1,133.8c-367.2,0-387.8-3.4-597.1-116.7c-247.1-133.8-477-370.6-590.2-610.8C81.9,667,68.2,289.6,160.8,39c96.1-254,243.6-452.9,429-586.8l151-102.9l17.2-401.5c24-610.8,175-984.9,583.4-1465.3c662.3-782.4,1691.8-1269.7,2992.4-1424.1c415.2-48.1,1256-24,1664.4,51.5c1911.4,353.5,3225.7,1540.8,3225.7,2920.3V-661l161.3,120.1c219.6,164.7,439.2,494.2,490.7,741.3c113.2,542.2-178.4,1081-720.6,1345.2c-415.2,199.1-895.6,175-1283.4-65.2l-171.6-102.9l-329.4,154.4c-181.9,85.8-477,202.5-655.5,260.8c-339.7,113.2-1005.5,240.2-1238.8,240.2h-140.7l20.6,284.8c20.6,315.7,120.1,624.6,250.5,775.6c192.2,229.9,580,264.2,1063.8,99.5l233.4-78.9l61.8-253.9c72.1-295.1,147.6-429,343.2-604c229.9-209.3,480.4-305.4,782.4-302c470.1,3.4,861.3,233.3,1081,634.9c92.7,164.7,102.9,212.8,102.9,490.7c0,363.8-65.2,538.8-288.3,782.4c-202.4,219.6-429,308.8-809.9,322.6C7974.7,4191.3,7823.7,4181,7744.8,4150.2z M8403.6,3590.8c319.2-161.3,377.5-600.5,120.1-857.9c-223.1-223.1-555.9-226.5-775.5-6.9c-127,127-171.6,226.5-171.6,394.6C7576.6,3532.5,8026.1,3789.8,8403.6,3590.8z M6004.9,1346.5C6979.5,1140.6,7731,739.1,8177.1,183.2c288.3-360.3,429-710.4,432.4-1070.7c3.5-243.6-140.7-689.7-308.8-950.5c-579.9-895.7-1914.9-1482.5-3366.4-1482.5c-1232,0-2271.8,377.5-2971.8,1077.5c-453,456.4-614.3,823.6-590.2,1358.9c24,507.9,181.9,840.8,593.7,1252.6c525,528.5,1400.1,912.8,2357.5,1043.2C4714.6,1463.2,5613.7,1428.9,6004.9,1346.5z M1626.1,1037.7l92.6-37.8L1506,787.1c-223.1-219.6-470.1-566.2-504.5-700C970.7-29.6,932.9-9,830,162.6c-75.5,133.8-89.2,188.7-75.5,353.4c17.2,226.5,82.4,336.3,284.8,466.7C1186.9,1078.8,1447.7,1102.9,1626.1,1037.7z M8904.7,989.6c353.4-164.7,456.4-521.6,247.1-851.1L9041.9-29.6l-92.7,168.1C8812,392.5,8719.3,516,8475.7,770c-147.5,154.4-205.9,236.8-175,247.1c27.5,6.9,72.1,24,99.5,30.9C8527.2,1092.6,8739.9,1065.1,8904.7,989.6z"/><path d="M6293.2,166c-274.5-102.9-463.3-401.5-418.7-662.3c68.6-380.9,439.3-614.3,803-507.9c408.4,123.6,569.7,590.3,332.9,950.6C6862.8,169.5,6554,262.1,6293.2,166z"/><path d="M3201.2,114.6c-247.1-113.2-360.3-295.1-360.3-573.1c0-271.1,157.9-466.7,432.4-549.1c278-78.9,566.2,24,720.6,260.8c78.9,120.1,89.2,161.3,75.5,360.3c-10.3,199.1-27.4,236.8-130.4,346.6C3726.3,183.2,3465.5,238.1,3201.2,114.6z"/><path d="M3228.7-1858.7c-120.1-102.9-133.8-315.7-27.5-432.4c123.5-137.3,676-377.5,1036.4-452.9c463.3-96.1,1153-72.1,1606,54.9c339.7,92.7,662.3,226.5,816.7,336.3c137.3,96,205.9,271.1,161.3,391.2c-89.2,229.9-240.2,236.8-662.3,34.3c-830.5-398.1-1733-384.3-2494.8,44.6C3438-1755.7,3355.7-1752.2,3228.7-1858.7z"/></g></g></svg>',
url: "https://reddit.com/submit?url=PAGE_URL&title=TEXT_SELECTION"
}
])
.appendCustomShareButtons([{
icon: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 478.165 478.165"><path d="M478.165 232.946c0 128.567-105.057 232.966-234.679 232.966-41.102 0-79.814-10.599-113.445-28.969L0 478.165l42.437-125.04c-21.438-35.065-33.77-76.207-33.77-120.159C8.667 104.34 113.763 0 243.485 0c129.623 0 234.68 104.34 234.68 232.946zM243.485 37.098c-108.802 0-197.422 87.803-197.422 195.868 0 42.915 13.986 82.603 37.576 114.879l-24.586 72.542 75.849-23.968c31.121 20.481 68.457 32.296 108.583 32.296 108.723 0 197.323-87.843 197.323-195.908 0-107.886-88.6-195.709-197.323-195.709zM361.931 286.62c-1.395-2.331-5.22-3.746-10.898-6.814-5.917-2.849-34.089-16.497-39.508-18.37-5.16-1.913-8.986-2.849-12.811 2.829-4.005 5.638-14.903 18.629-18.23 22.354-3.546 3.785-6.854 4.264-12.552 1.435-5.618-2.809-24.267-8.866-46.203-28.391-17.055-15.042-28.67-33.711-31.997-39.508-3.427-5.758-.398-8.826 2.471-11.635 2.69-2.59 5.778-6.734 8.627-10.041 2.969-3.287 3.905-5.638 5.798-9.424 1.913-3.905.936-7.192-.478-10.141-1.415-2.849-13.01-30.881-17.752-42.337-4.841-11.416-9.543-9.523-12.871-9.523-3.467 0-7.212-.478-11.117-.478-3.785 0-10.041 1.395-15.381 7.192-5.2 5.658-20.123 19.465-20.123 47.597 0 28.052 20.601 55.308 23.55 59.053 2.869 3.785 39.747 63.197 98.303 86.07 58.476 22.872 58.476 15.321 69.115 14.365 10.38-.956 34.069-13.867 38.811-27.096 4.66-13.45 4.66-24.766 3.246-27.137z"/></svg>',
url: 'https://api.whatsapp.com/send?text=TEXT_SELECTION%20PAGE_URL'
}])
.init();
</script>
</body>
Expand Down
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@
"description": "Share selection text",
"main": "dist/sharect.js",
"author": "Estevan Maito <ejmaito@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/estevanmaito/sharect/issues"
},
"homepage": "https://github.com/estevanmaito/sharect#readme",
"scripts": {
"test": "jest --watch",
"test:coverage": "jest --coverage",
"build": "webpack",
"dev": "webpack --watch"
"dev": "webpack --watch",
"lint": "eslint"
},
"dependencies": {},
"devDependencies": {
"@babel/core": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"babel-loader": "^8.0.6",
"eslint": "^5.16.0",
"jest": "^24.7.1",
"release-it": "^12.2.0",
"webpack": "^4.31.0",
"webpack-cli": "^3.3.2",
"webpack-dev-server": "^3.3.1"
},
"license": "MIT",
"keywords": [
"sharect",
"share",
Expand All @@ -34,5 +33,9 @@
"repository": {
"type": "git",
"url": "git+https://github.com/estevanmaito/sharect.git"
}
},
"bugs": {
"url": "https://github.com/estevanmaito/sharect/issues"
},
"homepage": "https://github.com/estevanmaito/sharect#readme"
}
43 changes: 43 additions & 0 deletions src/__tests__/helpers/getIcons.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import getIcons from '../../helpers/getIcons'

let _networks = {
twitter: {
isActive: true,
username: '',
url: 'https://twitter.com/intent/tweet?text=TEXT_SELECTION&via=USERNAME&url=PAGE_URL',
icon: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M8.2,20.2c6.5,0,11.7-5.2,11.8-11.6c0-0.1,0-0.1,0-0.2c0-0.2,0-0.4,0-0.5c0.8-0.6,1.5-1.3,2.1-2.2c-0.8,0.3-1.6,0.6-2.4,0.7c0.9-0.5,1.5-1.3,1.8-2.3c-0.8,0.5-1.7,0.8-2.6,1c-1.6-1.7-4.2-1.7-5.9-0.1c-1.1,1-1.5,2.5-1.2,3.9C8.5,8.7,5.4,7.1,3.3,4.6c-1.1,1.9-0.6,4.3,1.3,5.5c-0.7,0-1.3-0.2-1.9-0.5l0,0c0,2,1.4,3.7,3.3,4.1c-0.6,0.2-1.2,0.2-1.9,0.1c0.5,1.7,2.1,2.8,3.9,2.9c-1.7,1.4-3.9,2-6.1,1.7C3.8,19.5,6,20.2,8.2,20.2"/></svg>'
},
facebook: {
isActive: true,
url: 'https://www.facebook.com/sharer/sharer.php?u=PAGE_URL&quote=TEXT_SELECTION',
icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" enable-background="new 0 0 24 24" width="24" height="24" class="sharect__icon"><path d="M20,2H4C2.9,2,2,2.9,2,4v16c0,1.1,0.9,2,2,2h16c1.1,0,2-0.9,2-2V4C22,2.9,21.1,2,20,2z M18.4,7.4H17c-0.9,0-1,0.3-1,1l0,1.3 h2.1L18,12h-1.9v7h-3.2v-7h-1.2V9.6h1.2V8.1c0-2,0.8-3.1,3.1-3.1h2.4V7.4z"/></svg>'
}
}

describe('getIcons', () => {
it('should return two icons when there are two active', () => {
const customShareButtons = []
const icons = getIcons({networks: _networks, customShareButtons})

expect(icons.length).toBe(2)
})

it('should return one icon when there are two but only one is active', () => {
_networks.twitter.isActive = false
const customShareButtons = []
const icons = getIcons({networks: _networks, customShareButtons})

expect(icons.length).toBe(1)
})

it('should return three icons when there are two active networks and one custom button', () => {
_networks.twitter.isActive = true
const customShareButtons = [{
icon: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 478.165 478.165"><path d="M478.165 232.946c0 128.567-105.057 232.966-234.679 232.966-41.102 0-79.814-10.599-113.445-28.969L0 478.165l42.437-125.04c-21.438-35.065-33.77-76.207-33.77-120.159C8.667 104.34 113.763 0 243.485 0c129.623 0 234.68 104.34 234.68 232.946zM243.485 37.098c-108.802 0-197.422 87.803-197.422 195.868 0 42.915 13.986 82.603 37.576 114.879l-24.586 72.542 75.849-23.968c31.121 20.481 68.457 32.296 108.583 32.296 108.723 0 197.323-87.843 197.323-195.908 0-107.886-88.6-195.709-197.323-195.709zM361.931 286.62c-1.395-2.331-5.22-3.746-10.898-6.814-5.917-2.849-34.089-16.497-39.508-18.37-5.16-1.913-8.986-2.849-12.811 2.829-4.005 5.638-14.903 18.629-18.23 22.354-3.546 3.785-6.854 4.264-12.552 1.435-5.618-2.809-24.267-8.866-46.203-28.391-17.055-15.042-28.67-33.711-31.997-39.508-3.427-5.758-.398-8.826 2.471-11.635 2.69-2.59 5.778-6.734 8.627-10.041 2.969-3.287 3.905-5.638 5.798-9.424 1.913-3.905.936-7.192-.478-10.141-1.415-2.849-13.01-30.881-17.752-42.337-4.841-11.416-9.543-9.523-12.871-9.523-3.467 0-7.212-.478-11.117-.478-3.785 0-10.041 1.395-15.381 7.192-5.2 5.658-20.123 19.465-20.123 47.597 0 28.052 20.601 55.308 23.55 59.053 2.869 3.785 39.747 63.197 98.303 86.07 58.476 22.872 58.476 15.321 69.115 14.365 10.38-.956 34.069-13.867 38.811-27.096 4.66-13.45 4.66-24.766 3.246-27.137z"/></svg>',
url: 'https://api.whatsapp.com/send?text=TEXT_SELECTION%20PAGE_URL'
}]
const icons = getIcons({networks: _networks, customShareButtons})

expect(icons.length).toBe(3)
})
})
12 changes: 4 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ export default (function() {
twitter: {
isActive: true,
username: '',
url:
'https://twitter.com/intent/tweet?text=TEXT_SELECTION&via=USERNAME&url=PAGE_URL',
icon:
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M8.2,20.2c6.5,0,11.7-5.2,11.8-11.6c0-0.1,0-0.1,0-0.2c0-0.2,0-0.4,0-0.5c0.8-0.6,1.5-1.3,2.1-2.2c-0.8,0.3-1.6,0.6-2.4,0.7c0.9-0.5,1.5-1.3,1.8-2.3c-0.8,0.5-1.7,0.8-2.6,1c-1.6-1.7-4.2-1.7-5.9-0.1c-1.1,1-1.5,2.5-1.2,3.9C8.5,8.7,5.4,7.1,3.3,4.6c-1.1,1.9-0.6,4.3,1.3,5.5c-0.7,0-1.3-0.2-1.9-0.5l0,0c0,2,1.4,3.7,3.3,4.1c-0.6,0.2-1.2,0.2-1.9,0.1c0.5,1.7,2.1,2.8,3.9,2.9c-1.7,1.4-3.9,2-6.1,1.7C3.8,19.5,6,20.2,8.2,20.2"/></svg>'
url: 'https://twitter.com/intent/tweet?text=TEXT_SELECTION&via=USERNAME&url=PAGE_URL',
icon: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M8.2,20.2c6.5,0,11.7-5.2,11.8-11.6c0-0.1,0-0.1,0-0.2c0-0.2,0-0.4,0-0.5c0.8-0.6,1.5-1.3,2.1-2.2c-0.8,0.3-1.6,0.6-2.4,0.7c0.9-0.5,1.5-1.3,1.8-2.3c-0.8,0.5-1.7,0.8-2.6,1c-1.6-1.7-4.2-1.7-5.9-0.1c-1.1,1-1.5,2.5-1.2,3.9C8.5,8.7,5.4,7.1,3.3,4.6c-1.1,1.9-0.6,4.3,1.3,5.5c-0.7,0-1.3-0.2-1.9-0.5l0,0c0,2,1.4,3.7,3.3,4.1c-0.6,0.2-1.2,0.2-1.9,0.1c0.5,1.7,2.1,2.8,3.9,2.9c-1.7,1.4-3.9,2-6.1,1.7C3.8,19.5,6,20.2,8.2,20.2"/></svg>'
},
facebook: {
isActive: true,
url:
'https://www.facebook.com/sharer/sharer.php?u=PAGE_URL&quote=TEXT_SELECTION',
icon:
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" enable-background="new 0 0 24 24" width="24" height="24" class="sharect__icon"><path d="M20,2H4C2.9,2,2,2.9,2,4v16c0,1.1,0.9,2,2,2h16c1.1,0,2-0.9,2-2V4C22,2.9,21.1,2,20,2z M18.4,7.4H17c-0.9,0-1,0.3-1,1l0,1.3 h2.1L18,12h-1.9v7h-3.2v-7h-1.2V9.6h1.2V8.1c0-2,0.8-3.1,3.1-3.1h2.4V7.4z"/></svg>'
url: 'https://www.facebook.com/sharer/sharer.php?u=PAGE_URL&quote=TEXT_SELECTION',
icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" enable-background="new 0 0 24 24" width="24" height="24" class="sharect__icon"><path d="M20,2H4C2.9,2,2,2.9,2,4v16c0,1.1,0.9,2,2,2h16c1.1,0,2-0.9,2-2V4C22,2.9,21.1,2,20,2z M18.4,7.4H17c-0.9,0-1,0.3-1,1l0,1.3 h2.1L18,12h-1.9v7h-3.2v-7h-1.2V9.6h1.2V8.1c0-2,0.8-3.1,3.1-3.1h2.4V7.4z"/></svg>'
}
}
let _icons = {}
Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const path = require("path");

module.exports = {
mode: "development",
mode: "production",
entry: "./src/index.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "sharect.js",
library: "Sharect",
libraryExport: "default",
libraryTarget: "umd"
},
module: {
Expand Down
Loading