-
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.
Merge pull request #21 from evangelion1204/es6-improvements
Further improvements
- Loading branch information
Showing
7 changed files
with
98 additions
and
51 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
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,34 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
|
||
export function lowercase(value) { | ||
return _.isString(value) ? value.toLowerCase() : value; | ||
} | ||
|
||
export function uppercase(value) { | ||
return _.isString(value) ? value.toUpperCase() : value; | ||
} | ||
|
||
export function trim(value) { | ||
return _.isString(value) ? value.trim() : value; | ||
} | ||
|
||
export function constants(value, options) { | ||
if (!_.isString(value) || _.isEmpty(options.constants)) { | ||
return value; | ||
} | ||
|
||
_.forIn(options.constants, (replacement, constant) => { | ||
let matcher = new RegExp(`" ${constant} "`, 'g'); | ||
value = value.replace(matcher, `${replacement}`); | ||
|
||
matcher = new RegExp(`" ${constant}$`, 'g'); | ||
value = value.replace(matcher, `${replacement}"`); | ||
|
||
matcher = new RegExp(`^${constant} "`, 'g'); | ||
value = value.replace(matcher, `"${replacement}`); | ||
}); | ||
|
||
return value; | ||
} |
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,45 +1,23 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
const MultiIni = require('./multi-ini-class'); | ||
const Parser = require('./parser'); | ||
const Serializer = require('./serializer'); | ||
const filters = require('./filters'); | ||
|
||
export { | ||
filters, | ||
MultiIni as Class, | ||
Parser, | ||
Serializer, | ||
}; | ||
|
||
module.exports = { | ||
Class: MultiIni, | ||
|
||
filters: { | ||
lowercase: (value) => _.isString(value) ? value.toLowerCase() : value, | ||
|
||
uppercase: (value) => _.isString(value) ? value.toUpperCase() : value, | ||
|
||
trim: (value) => _.isString(value) ? value.trim() : value, | ||
|
||
constants: (value, options) => { | ||
if (!_.isString(value) || _.isEmpty(options.constants)) { | ||
return value; | ||
} | ||
|
||
_.forIn(options.constants, (replacement, constant) => { | ||
let matcher = new RegExp(`" ${constant} "`, 'g'); | ||
value = value.replace(matcher, `${replacement}`); | ||
|
||
matcher = new RegExp(`" ${constant}$`, 'g'); | ||
value = value.replace(matcher, `${replacement}"`); | ||
|
||
matcher = new RegExp(`^${constant} "`, 'g'); | ||
value = value.replace(matcher, `"${replacement}`); | ||
}); | ||
|
||
return value; | ||
} | ||
}, | ||
|
||
read: (filename, options = {}) => { | ||
const instance = new MultiIni(options); | ||
return instance.read(filename); | ||
}, | ||
export function read(filename, options = {}) { | ||
const instance = new MultiIni(options); | ||
return instance.read(filename); | ||
} | ||
|
||
write: (filename, content, options = {}) => { | ||
const instance = new MultiIni(options); | ||
return instance.write(filename, content); | ||
}, | ||
}; | ||
export function write(filename, content, options = {}) { | ||
const instance = new MultiIni(options); | ||
return instance.write(filename, content); | ||
} |
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