This repository has been archived by the owner on May 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
727 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Checklist to release a new build to NPM: | ||
* Clone the repository if needed | ||
* Checkout develop branch and make sure develop branch is up-to-date with remote | ||
* If git flow is not initialized yet, Run: git flow init | ||
* Create a new release branch, Run: git flow release start <new_version_with_v_character> | ||
* Delete all existing npm dependencies, Run: rm -rf node_modules package-lock.json | ||
* Install dependencies again, Run: npm install | ||
* Update package version with new release version in package.json | ||
* Update LICENSE file if needed | ||
* Update README.md file if needed | ||
* Now, create a release-ready build, Run: npm run build | ||
* Test the dist/* files if needed | ||
* Now commit all the changes with this message: "Make a build and bump version" | ||
* Then finish the release, Run: git flow release finish [-s] <new_version_with_v_character> and enter release notes | ||
* Push all changes and tags to remote, Run: git push origin master && git push origin develop && git push origin --tags | ||
* Edit the title of the released tag in Github | ||
* When everything is fine, it's ready to release | ||
* Checkout master branch | ||
* Now if everything is fine, release it to npm, Run: npm publish |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import DataConverter from './model/dataConverter'; | ||
import { DSVStringConverter, DSVArrayConverter, JSONConverter, AutoDataConverter } from './defaultConverters'; | ||
|
||
class DataConverterStore { | ||
constructor() { | ||
this.store = new Map(); | ||
this.converters(this._getDefaultConverters()); | ||
} | ||
|
||
_getDefaultConverters() { | ||
return [ | ||
new DSVStringConverter(), | ||
new DSVArrayConverter(), | ||
new JSONConverter(), | ||
new AutoDataConverter() | ||
]; | ||
} | ||
|
||
/** | ||
* Sets the given converters in the store and returns the store | ||
* @param {Array<DataConverter>} converters : contains array of converter instance | ||
* @return { Map<String,DataConverter> } | ||
*/ | ||
converters(converters = []) { | ||
converters.forEach(converter => this.store.set(converter.type, converter)); | ||
return this.store; | ||
} | ||
|
||
/** | ||
* Registers a Converter of type DataConverter | ||
* @param {DataConverter} converter : converter Instance | ||
* @returns self | ||
*/ | ||
register(converter) { | ||
if (converter instanceof DataConverter) { | ||
this.store.set(converter.type, converter); | ||
return this; | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Rempves a converter from store | ||
* @param {DataConverter} converter : converter Instance | ||
* @returns self | ||
*/ | ||
|
||
unregister(converter) { | ||
this.store.delete(converter.type); | ||
return this; | ||
} | ||
|
||
get(name) { | ||
if (this.store.has(name)) { | ||
return this.store.get(name); | ||
} | ||
return null; | ||
} | ||
|
||
} | ||
|
||
const converterStore = (function () { | ||
let store = null; | ||
|
||
function getStore () { | ||
store = new DataConverterStore(); | ||
return store; | ||
} | ||
return store || getStore(); | ||
}()); | ||
|
||
export default converterStore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* global describe, it */ | ||
/* eslint-disable no-unused-expressions */ | ||
|
||
import { expect } from 'chai'; | ||
import converterStore from './dataConverterStore'; | ||
import DataConverter from '../converter/model/dataConverter'; | ||
|
||
describe('#DataConverterStore', () => { | ||
it('should register and unregister converter', () => { | ||
class JSONConverter2 extends DataConverter { | ||
constructor() { | ||
super('json2'); | ||
} | ||
|
||
convert() { | ||
return ''; | ||
} | ||
} | ||
|
||
const converter = new JSONConverter2(); | ||
converterStore.register(converter); | ||
expect(converterStore.get('json2')).to.not.null; | ||
|
||
converterStore.unregister(converter); | ||
expect(converterStore.get('json2')).to.null; | ||
}); | ||
|
||
it('should not register invalid Coverter', () => { | ||
expect(converterStore.register(() => {})).to.null; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import DataConverter from '../model/dataConverter'; | ||
import AUTO from '../utils/auto-resolver'; | ||
import DataFormat from '../../enums/data-format'; | ||
|
||
export default class AutoDataConverter extends DataConverter { | ||
constructor() { | ||
super(DataFormat.AUTO); | ||
} | ||
|
||
convert(data, schema, options) { | ||
return AUTO(data, schema, options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import DataConverter from '../model/dataConverter'; | ||
import DSVArr from '../utils/dsv-arr'; | ||
import DataFormat from '../../enums/data-format'; | ||
|
||
export default class DSVArrayConverter extends DataConverter { | ||
constructor() { | ||
super(DataFormat.DSV_ARR); | ||
} | ||
|
||
convert(data, schema, options) { | ||
return DSVArr(data, schema, options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import DataConverter from '../model/dataConverter'; | ||
import DSVStr from '../utils/dsv-str'; | ||
import DataFormat from '../../enums/data-format'; | ||
|
||
export default class DSVStringConverter extends DataConverter { | ||
constructor() { | ||
super(DataFormat.DSV_STR); | ||
} | ||
|
||
convert(data, schema, options) { | ||
return DSVStr(data, schema, options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { default as DSVStringConverter } from './dsvStringConverter'; | ||
export { default as JSONConverter } from './jsonConverter'; | ||
export { default as DSVArrayConverter } from './dsvArrayConverter'; | ||
export { default as AutoDataConverter } from './autoConverter'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import DataConverter from '../model/dataConverter'; | ||
import FlatJSON from '../utils/flat-json'; | ||
import DataFormat from '../../enums/data-format'; | ||
|
||
export default class JSONConverter extends DataConverter { | ||
constructor() { | ||
super(DataFormat.FLAT_JSON); | ||
} | ||
|
||
convert(data, schema, options) { | ||
return FlatJSON(data, schema, options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* global describe, it ,beforeEach */ | ||
/* eslint-disable no-unused-expressions */ | ||
|
||
import { expect } from 'chai'; | ||
import JSONConverter from './jsonConverter'; | ||
|
||
describe('JSON Converter', () => { | ||
let data; | ||
let converter = new JSONConverter(); | ||
beforeEach(() => { | ||
data = [ | ||
{ | ||
a: 1, | ||
b: 2, | ||
c: 3 | ||
}, | ||
{ | ||
a: 4, | ||
b: 5, | ||
c: 6 | ||
}, | ||
{ | ||
a: 7, | ||
b: 8, | ||
c: 9 | ||
} | ||
]; | ||
}); | ||
|
||
describe('#JSON', () => { | ||
it('should convert to JSON data', () => { | ||
const schema = [ | ||
{ | ||
name: 'a', | ||
type: 'measure', | ||
subtype: 'continuous' | ||
}, | ||
{ | ||
name: 'b', | ||
type: 'measure', | ||
subtype: 'continuous' | ||
}, | ||
{ | ||
name: 'c', | ||
type: 'measure', | ||
subtype: 'continuous' | ||
} | ||
]; | ||
|
||
const parsedData = converter.convert(data, schema); | ||
const expected = [['a', 'b', 'c'], [[1, 4, 7], [2, 5, 8], [3, 6, 9]]]; | ||
|
||
expect(parsedData).to.deep.equal(expected); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { default as DSVArr } from './dsv-arr'; | ||
export { default as DSVStr } from './dsv-str'; | ||
export { default as FlatJSON } from './flat-json'; | ||
export { default as Auto } from './auto-resolver'; | ||
import converterStore from './dataConverterStore'; | ||
import DataConverter from './model/dataConverter'; | ||
|
||
export { DataConverter, converterStore }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Interface for all data converters | ||
*/ | ||
export default class DataConverter { | ||
constructor(type) { | ||
this._type = type; | ||
} | ||
|
||
get type() { | ||
return this._type; | ||
} | ||
|
||
convert() { | ||
throw new Error('Convert method not implemented.'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* global describe, it */ | ||
/* eslint-disable no-unused-expressions */ | ||
|
||
import { expect } from 'chai'; | ||
import DataConverter from './dataConverter'; | ||
|
||
describe('#DataConverterModel', () => { | ||
it('should throw error', () => { | ||
expect(new DataConverter().convert).to.throw(Error, 'Convert method not implemented'); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
src/converter/auto-resolver.js → src/converter/utils/auto-resolver.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.