Skip to content

Commit 8331b69

Browse files
committed
Initial commit
1 parent 5d63589 commit 8331b69

File tree

10 files changed

+611
-2
lines changed

10 files changed

+611
-2
lines changed

.gitignore

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
2+
# Created by https://www.gitignore.io/api/node,react,linux,macos,windows,visualstudiocode
3+
# Edit at https://www.gitignore.io/?templates=node,react,linux,macos,windows,visualstudiocode
4+
5+
### Linux ###
6+
*~
7+
8+
# temporary files which can be created if a process still has a handle open of a deleted file
9+
.fuse_hidden*
10+
11+
# KDE directory preferences
12+
.directory
13+
14+
# Linux trash folder which might appear on any partition or disk
15+
.Trash-*
16+
17+
# .nfs files are created when an open file is removed but is still being accessed
18+
.nfs*
19+
20+
### macOS ###
21+
# General
22+
.DS_Store
23+
.AppleDouble
24+
.LSOverride
25+
26+
# Icon must end with two \r
27+
Icon
28+
29+
# Thumbnails
30+
._*
31+
32+
# Files that might appear in the root of a volume
33+
.DocumentRevisions-V100
34+
.fseventsd
35+
.Spotlight-V100
36+
.TemporaryItems
37+
.Trashes
38+
.VolumeIcon.icns
39+
.com.apple.timemachine.donotpresent
40+
41+
# Directories potentially created on remote AFP share
42+
.AppleDB
43+
.AppleDesktop
44+
Network Trash Folder
45+
Temporary Items
46+
.apdisk
47+
48+
### Node ###
49+
# Logs
50+
logs
51+
*.log
52+
npm-debug.log*
53+
yarn-debug.log*
54+
yarn-error.log*
55+
lerna-debug.log*
56+
57+
# Diagnostic reports (https://nodejs.org/api/report.html)
58+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
59+
60+
# Runtime data
61+
pids
62+
*.pid
63+
*.seed
64+
*.pid.lock
65+
66+
# Directory for instrumented libs generated by jscoverage/JSCover
67+
lib-cov
68+
69+
# Coverage directory used by tools like istanbul
70+
coverage
71+
*.lcov
72+
73+
# nyc test coverage
74+
.nyc_output
75+
76+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
77+
.grunt
78+
79+
# Bower dependency directory (https://bower.io/)
80+
bower_components
81+
82+
# node-waf configuration
83+
.lock-wscript
84+
85+
# Compiled binary addons (https://nodejs.org/api/addons.html)
86+
build/Release
87+
88+
# Dependency directories
89+
node_modules/
90+
jspm_packages/
91+
92+
# TypeScript v1 declaration files
93+
typings/
94+
95+
# TypeScript cache
96+
*.tsbuildinfo
97+
98+
# Optional npm cache directory
99+
.npm
100+
101+
# Optional eslint cache
102+
.eslintcache
103+
104+
# Optional REPL history
105+
.node_repl_history
106+
107+
# Output of 'npm pack'
108+
*.tgz
109+
110+
# Yarn Integrity file
111+
.yarn-integrity
112+
113+
# dotenv environment variables file
114+
.env
115+
.env.test
116+
117+
# parcel-bundler cache (https://parceljs.org/)
118+
.cache
119+
120+
# next.js build output
121+
.next
122+
123+
# nuxt.js build output
124+
.nuxt
125+
126+
# rollup.js default build output
127+
dist/
128+
129+
# Uncomment the public line if your project uses Gatsby
130+
# https://nextjs.org/blog/next-9-1#public-directory-support
131+
# https://create-react-app.dev/docs/using-the-public-folder/#docsNav
132+
# public
133+
134+
# Storybook build outputs
135+
.out
136+
.storybook-out
137+
138+
# vuepress build output
139+
.vuepress/dist
140+
141+
# Serverless directories
142+
.serverless/
143+
144+
# FuseBox cache
145+
.fusebox/
146+
147+
# DynamoDB Local files
148+
.dynamodb/
149+
150+
# Temporary folders
151+
tmp/
152+
temp/
153+
154+
### react ###
155+
.DS_*
156+
**/*.backup.*
157+
**/*.back.*
158+
159+
node_modules
160+
161+
*.sublime*
162+
163+
psd
164+
thumb
165+
sketch
166+
167+
### VisualStudioCode ###
168+
.vscode/*
169+
!.vscode/settings.json
170+
!.vscode/tasks.json
171+
!.vscode/launch.json
172+
!.vscode/extensions.json
173+
174+
### VisualStudioCode Patch ###
175+
# Ignore all local history of files
176+
.history
177+
178+
### Windows ###
179+
# Windows thumbnail cache files
180+
Thumbs.db
181+
Thumbs.db:encryptable
182+
ehthumbs.db
183+
ehthumbs_vista.db
184+
185+
# Dump file
186+
*.stackdump
187+
188+
# Folder config file
189+
[Dd]esktop.ini
190+
191+
# Recycle Bin used on file shares
192+
$RECYCLE.BIN/
193+
194+
# Windows Installer files
195+
*.cab
196+
*.msi
197+
*.msix
198+
*.msm
199+
*.msp
200+
201+
# Windows shortcuts
202+
*.lnk
203+
204+
# End of https://www.gitignore.io/api/node,react,linux,macos,windows,visualstudiocode

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry = "https://registry.npmjs.com/"

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: node_js
2+
node_js:
3+
- '11'
4+
- '10'
5+
- '8'
6+
- '6'

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1-
# react-csv-import
2-
Flexible and easy to use React component to provide CSV (also TSV, ..) import functionality.
1+
# react-dsv-import
2+
Flexible, typed and easy to use React component to provide CSV, TSV and other delimiter-separated values formats (DSV) import functionality.
3+
4+
## Tools
5+
- yarn
6+
- rollup
7+
- React
8+
- typescript
9+
10+
## Resources
11+
- [Template: Rollup Starter Lib (TypeScript)](https://github.com/rollup/rollup-starter-lib/tree/typescript)
12+
- [Article: Creating a React Component library using Rollup, Typescript, Sass and Storybook](https://blog.harveydelaney.com/creating-your-own-react-component-library/) <br> Explains how to create a React component library using Rollup

package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "react-dsv-import",
3+
"version": "0.0.1",
4+
"main": "dist/react-dsv-import.cjs.js",
5+
"module": "dist/react-dsv-import.esm.js",
6+
"browser": "dist/react-dsv-import.umd.js",
7+
"dependencies": {},
8+
"devDependencies": {
9+
"@types/react": "^16.9.34",
10+
"@types/react-dom": "^16.9.6",
11+
"rollup": "^2.4.0",
12+
"rollup-plugin-commonjs": "^10.1.0",
13+
"rollup-plugin-node-resolve": "^5.2.0",
14+
"rollup-plugin-typescript": "^1.0.0",
15+
"ts-node": "^8.8.2",
16+
"tslib": "^1.9.3",
17+
"typescript": "^3.2.2"
18+
},
19+
"scripts": {
20+
"build": "rollup -c",
21+
"dev": "rollup -c -w",
22+
"test": "ts-node test/test.ts",
23+
"pretest": "npm run build"
24+
},
25+
"files": [
26+
"dist"
27+
],
28+
"peerDependencies": {
29+
"react": "^16.13.1",
30+
"react-dom": "^16.13.1"
31+
}
32+
}

rollup.config.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import resolve from 'rollup-plugin-node-resolve';
2+
import commonjs from 'rollup-plugin-commonjs';
3+
import typescript from 'rollup-plugin-typescript';
4+
import pkg from './package.json';
5+
6+
export default [
7+
// browser-friendly UMD build
8+
{
9+
input: 'src/index.tsx',
10+
output: {
11+
name: 'react-dsv-import',
12+
file: pkg.browser,
13+
format: 'umd'
14+
},
15+
plugins: [
16+
resolve(), // so Rollup can find `ms`
17+
commonjs(), // so Rollup can convert `ms` to an ES module
18+
typescript() // so Rollup can convert TypeScript to JavaScript
19+
]
20+
},
21+
22+
// CommonJS (for Node) and ES module (for bundlers) build.
23+
// (We could have three entries in the configuration array
24+
// instead of two, but it's quicker to generate multiple
25+
// builds from a single configuration where possible, using
26+
// an array for the `output` option, where we can specify
27+
// `file` and `format` for each target)
28+
{
29+
input: 'src/main.ts',
30+
external: [],
31+
plugins: [
32+
typescript() // so Rollup can convert TypeScript to JavaScript
33+
],
34+
output: [
35+
{ file: pkg.main, format: 'cjs' },
36+
{ file: pkg.module, format: 'es' }
37+
]
38+
}
39+
];

src/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
3+
export const DSVImport: React.FC = () => {
4+
return <div>Hello</div>;
5+
}

test/test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const assert = require('assert');
2+
const howLongTillLunch = require('..');
3+
4+
class MockDate {
5+
private date = 0;
6+
private hours = 0;
7+
private minutes = 0;
8+
private seconds = 0;
9+
private milliseconds = 0;
10+
11+
getDate (): number { return this.date; }
12+
setDate (date: number): void { this.date = date; }
13+
setHours (h: number) { this.hours = h; }
14+
setMinutes (m: number): void { this.minutes = m; }
15+
setSeconds (s: number): void { this.seconds = s; }
16+
setMilliseconds (ms: number): void { this.milliseconds = ms; }
17+
getTime (): number { return this.valueOf(); }
18+
valueOf (): number {
19+
return (
20+
this.milliseconds +
21+
this.seconds * 1e3 +
22+
this.minutes * 1e3 * 60 +
23+
this.hours * 1e3 * 60 * 60 +
24+
this.date * 1e3 * 60 * 60 * 24
25+
);
26+
}
27+
28+
static now () { return now.valueOf(); }
29+
}
30+
31+
const now = new MockDate();
32+
33+
global.Date = MockDate as any as typeof Date;
34+
35+
function test(hours: number, minutes: number, seconds: number, expected: string): void {
36+
now.setHours(hours);
37+
now.setMinutes(minutes);
38+
now.setSeconds(seconds);
39+
40+
assert.equal(howLongTillLunch(...lunchtime), expected);
41+
console.log(`\u001B[32m✓\u001B[39m ${expected}`);
42+
}
43+
44+
let lunchtime = [ 12, 30 ];
45+
test(11, 30, 0, '1 hour');
46+
test(10, 30, 0, '2 hours');
47+
test(12, 25, 0, '5 minutes');
48+
test(12, 29, 15, '45 seconds');
49+
test(13, 30, 0, '23 hours');
50+
51+
// some of us like an early lunch
52+
lunchtime = [ 11, 0 ];
53+
test(10, 30, 0, '30 minutes');

0 commit comments

Comments
 (0)