Skip to content

Commit a99c72d

Browse files
committed
transpile lib
1 parent 98b724f commit a99c72d

File tree

11 files changed

+52
-35
lines changed

11 files changed

+52
-35
lines changed

.github/workflows/npm-publish.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v2
15+
1516
- uses: actions/setup-node@v1
1617
with:
1718
node-version: 14.17.6
1819
registry-url: https://registry.npmjs.org/
20+
21+
- name: Install
22+
run: npm install
23+
24+
- name: Build
25+
run: npm run build
26+
1927
- run: npm publish --access public
2028
env:
2129
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
package-lock.json
3+
dist/
4+

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ npm-debug.log
44

55
# Dependency directory
66
node_modules
7+
package-lock.json
8+
example/
79

810
# Runtime data
911
tmp

babel.config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["@babel/preset-react", "@babel/preset-env"]
3+
}

example/src/App.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
import React from "react";
2-
import ImageCrush from "./ImageCrush";
3-
import { setKey } from "./key";
1+
import React from 'react';
2+
import { ImageCrush, setKey } from './modules';
43

5-
setKey("test-key");
4+
setKey('test-key');
65

7-
const testUrl =
8-
"https://cdn.pixabay.com/photo/2021/12/11/07/59/hotel-6862159__340.jpg";
6+
const testUrl = 'https://cdn.pixabay.com/photo/2021/12/11/07/59/hotel-6862159__340.jpg';
97

108
function App() {
119
return (
1210
<div style={{ width: 50, height: 50 }}>
1311
<ImageCrush
14-
url={
15-
"https://cdn.pixabay.com/photo/2021/12/11/07/59/hotel-6862159__340.jpg"
16-
}
12+
url={testUrl}
1713
width={50}
1814
height={50}
1915
/>

example/src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import React from "react";
2-
import ReactDOM from "react-dom";
3-
import App from "./App";
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import App from './App';
44

55
ReactDOM.render(
66
<React.StrictMode>
77
<App />
88
</React.StrictMode>,
9-
document.getElementById("root")
9+
document.getElementById('root')
1010
);
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
1-
import React, { memo, useEffect, useState } from "react";
2-
import { getKey } from "./key";
1+
import React, { memo, useEffect, useState } from 'react';
2+
import { getKey } from './key';
33

4-
const baseServiceUrl = "https://service.assetcrush.com";
4+
const baseServiceUrl = 'https://service.assetcrush.com';
55

66
const ImageCrush = ({ url, width, height, ...props }) => {
7-
const [image, setImage] = useState("");
8-
const key = getKey();
9-
10-
const imageUrl = `https://service.assetcrush.com?width=${
11-
width || "auto"
12-
}&height=${height || "auto"}&original_uri=${encodeURIComponent(url)}`;
7+
const [image, setImage] = useState('');
138

149
useEffect(() => {
1510
if (!url) return;
1611

17-
const _width = width || "auto";
18-
const _height = height || "auto";
12+
const _width = width || 'auto';
13+
const _height = height || 'auto';
1914
const imageUrl = `${baseServiceUrl}?width=${_width}&height=${_height}&original_uri=${encodeURIComponent(
2015
url
2116
)}`;
2217
const key = getKey();
2318

24-
fetch(imageUrl, { headers: { "assetcrush-key": key } })
19+
fetch(imageUrl, { headers: { 'assetcrush-key': key } })
2520
.then((r) => r.blob())
2621
.then((d) => {
2722
if (typeof window === undefined) return;
@@ -32,7 +27,7 @@ const ImageCrush = ({ url, width, height, ...props }) => {
3227

3328
if (!image) return null;
3429

35-
return <img src={image} alt={"resized"} {...props} />;
30+
return <img src={image} {...props} />;
3631
};
3732

3833
export default memo(ImageCrush);

example/src/modules/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import ImageCrush from './ImageCrush';
2+
import { setKey } from './key';
3+
4+
export {
5+
setKey,
6+
ImageCrush
7+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
let key = "";
2-
1+
let key = '';
32
export const setKey = (_key) => (key = _key);
43
export const getKey = () => key;

index.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)