mirror of
https://github.com/flynx/object.js.git
synced 2025-10-29 18:40:08 +00:00
tweaking and refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
0ae32795f1
commit
13fd19abf2
@ -634,7 +634,7 @@ C(<name>, ..)
|
||||
|
||||
## Utilities
|
||||
|
||||
### `normalizeIndent(..)`
|
||||
### `normalizeIndent(..)` / `normalizeTextIndent(..)`
|
||||
|
||||
Align _code_ to shortest leading white-space
|
||||
```
|
||||
@ -647,6 +647,13 @@ normalizeIndent(<text>, <tab-size>, <keep-tabs>)
|
||||
This is used to format `.toString(..)` return values for nested functions
|
||||
to make source printing in console more pleasant to read.
|
||||
|
||||
`tab_size` defaults to `object.TAB_SIZE`
|
||||
|
||||
`keep_tabs` defaults to `object.KEEP_TABS`
|
||||
|
||||
`normalizeTextIndent(..)` is a shorthand optimized for text rather than
|
||||
code -- ignores `object.KEEP_TABS` and `keep_tabs` is 0 by default.
|
||||
|
||||
|
||||
### `match(..)`
|
||||
|
||||
|
||||
20
object.js
20
object.js
@ -19,7 +19,7 @@ var KEEP_TABS =
|
||||
module.KEEP_TABS = 1
|
||||
|
||||
|
||||
// Normalize indent...
|
||||
// Normalize code indent...
|
||||
//
|
||||
// normalizeIndent(text)
|
||||
// -> text
|
||||
@ -47,12 +47,18 @@ module.KEEP_TABS = 1
|
||||
var normalizeIndent =
|
||||
module.normalizeIndent =
|
||||
function(text, tab_size, keep_tabs){
|
||||
tab_size = tab_size || TAB_SIZE
|
||||
keep_tabs = (keep_tabs || KEEP_TABS) * tab_size
|
||||
tab_size = tab_size == null ?
|
||||
TAB_SIZE
|
||||
: tab_size
|
||||
keep_tabs = (keep_tabs == null ?
|
||||
KEEP_TABS
|
||||
: keep_tabs)
|
||||
* tab_size
|
||||
tab_size = ' '.repeat(tab_size)
|
||||
text = tab_size != '' ?
|
||||
text.replace(/\t/g, tab_size)
|
||||
: text
|
||||
|
||||
var lines = text.trim().split(/\n/)
|
||||
var l = lines
|
||||
.reduce(function(l, e, i){
|
||||
@ -69,6 +75,7 @@ function(text, tab_size, keep_tabs){
|
||||
indent
|
||||
// min...
|
||||
: Math.min(l, indent) }, -1)
|
||||
|
||||
return lines
|
||||
.map(function(line, i){
|
||||
return i == 0 ?
|
||||
@ -78,6 +85,13 @@ function(text, tab_size, keep_tabs){
|
||||
.trim() }
|
||||
|
||||
|
||||
// shorthand more suted for text...
|
||||
var normalizeTextIndent =
|
||||
module.normalizeTextIndent =
|
||||
function(text, tab_size, keep_tabs){
|
||||
return module.normalizeIndent(text, tab_size, keep_tabs || 0) }
|
||||
|
||||
|
||||
// Match two objects...
|
||||
//
|
||||
// match(a, b)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ig-object",
|
||||
"version": "3.3.1",
|
||||
"version": "3.3.2",
|
||||
"description": "",
|
||||
"main": "object.js",
|
||||
"scripts": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user