-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: #33
- Loading branch information
Showing
6 changed files
with
1,021 additions
and
80 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
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,35 +1,38 @@ | ||
import * as _httpquery from './modules/httpquery' | ||
import * as _camelcase from './modules/camelcase' | ||
import * as _html from './modules/html' | ||
import * as _spaces from './modules/spaces' | ||
import * as _truncate from './modules/truncate' | ||
import * as _slug from './modules/slug' | ||
// import * as _httpquery from './modules/httpquery' | ||
// import * as _camelcase from './modules/camelcase' | ||
// import * as _html from './modules/html' | ||
// import * as _spaces from './modules/spaces' | ||
// import * as _truncate from './modules/truncate' | ||
// import * as _slug from './modules/slug' | ||
// import * as _currency from './modules/currency' | ||
|
||
function StringManager(str) { | ||
this.data = str | ||
return this.data | ||
} | ||
// function StringManager(str) { | ||
// this.data = str | ||
// return this.data | ||
// } | ||
|
||
function prototypeBuilder(module) { | ||
return function(...args) { | ||
return new StringManager(module(this.data, ...args)) | ||
} | ||
} | ||
// function prototypeBuilder(module) { | ||
// return function(...args) { | ||
// return new StringManager(module(this.data, ...args)) | ||
// } | ||
// } | ||
|
||
StringManager.prototype.toString = (...args) => { return this.data } | ||
StringManager.prototype.objToQuery = prototypeBuilder(_httpquery.objToQuery) | ||
StringManager.prototype.queryToObj = prototypeBuilder(_httpquery.queryToObj) | ||
StringManager.prototype.toCamelCase = prototypeBuilder(_camelcase.toCamelCase) | ||
StringManager.prototype.stripTags = prototypeBuilder(_html.stripTags) | ||
StringManager.prototype.toSingleSpace = prototypeBuilder(_spaces.toSingleSpace) | ||
// StringManager.prototype.toString = (...args) => { return this.data } | ||
// StringManager.prototype.objToQuery = prototypeBuilder(_httpquery.objToQuery) | ||
// StringManager.prototype.queryToObj = prototypeBuilder(_httpquery.queryToObj) | ||
// StringManager.prototype.toCamelCase = prototypeBuilder(_camelcase.toCamelCase) | ||
// StringManager.prototype.stripTags = prototypeBuilder(_html.stripTags) | ||
// StringManager.prototype.toSingleSpace = prototypeBuilder(_spaces.toSingleSpace) | ||
// StringManager.prototype.truncate = prototypeBuilder(_truncate.truncate) | ||
StringManager.prototype.toSlug = prototypeBuilder(_slug.toSlug) | ||
// StringManager.prototype.toSlug = prototypeBuilder(_slug.toSlug) | ||
// StringManager.prototype.currencyFormat = prototypeBuilder(_currency.currencyFormat) | ||
|
||
export {toCamelCase} from './modules/camelcase' | ||
export {objToQuery, queryToObj} from './modules/httpquery' | ||
export {stripTags} from './modules/html' | ||
export {toSingleSpace} from './modules/spaces' | ||
export {truncate} from './modules/truncate' | ||
export {toSlug} from './modules/slug' | ||
export { toCamelCase } from './modules/camelcase' | ||
export { objToQuery, queryToObj } from './modules/httpquery' | ||
export { stripTags } from './modules/html' | ||
export { toSingleSpace } from './modules/spaces' | ||
export { truncate } from './modules/truncate' | ||
export { toSlug } from './modules/slug' | ||
export { currencyFormat } from './modules/currency' | ||
|
||
export default str => { return new StringManager(str)} | ||
// export default str => { return new StringManager(str)} |
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,9 @@ | ||
export function currencyFormat(number, symbol ='') { | ||
try { | ||
// convert number to string | ||
number = number.toString() | ||
return `${symbol ? `${symbol} ` : ''}${number.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1.")}` | ||
} catch(e) { | ||
console.error(e) | ||
} | ||
} |
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,16 @@ | ||
import {expect} from 'chai' | ||
import {currencyFormat} from '../src/index' | ||
|
||
describe("Currency Module", () => { | ||
describe('currencyFormat()', () => { | ||
it("normal use", () => { | ||
const res = currencyFormat(456679, 'Rp') | ||
expect(res).to.deep.equal('Rp 456.679') | ||
}) | ||
it("format not number", () => { | ||
const res = currencyFormat('string', '') | ||
expect(res).to.deep.equal('string') | ||
}) | ||
}) | ||
}) | ||
// }) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.