Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
24b9bc1e
Commit
24b9bc1e
authored
Nov 23, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(missing files): added missing files, oops
parent
cf1e1674
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
0 deletions
+63
-0
public/app/core/utils/flatten.ts
+39
-0
public/test/core/utils/flatten_specs.ts
+24
-0
No files found.
public/app/core/utils/flatten.ts
0 → 100644
View file @
24b9bc1e
// Copyright (c) 2014, Hugh Kennedy
// Based on code from https://github.com/hughsk/flat/blob/master/index.js
//
function
flatten
(
target
,
opts
):
any
{
opts
=
opts
||
{};
var
delimiter
=
opts
.
delimiter
||
'.'
;
var
maxDepth
=
opts
.
maxDepth
||
3
;
var
currentDepth
=
1
;
var
output
=
{};
function
step
(
object
,
prev
)
{
Object
.
keys
(
object
).
forEach
(
function
(
key
)
{
var
value
=
object
[
key
];
var
isarray
=
opts
.
safe
&&
Array
.
isArray
(
value
);
var
type
=
Object
.
prototype
.
toString
.
call
(
value
);
var
isobject
=
type
===
"[object Object]"
;
var
newKey
=
prev
?
prev
+
delimiter
+
key
:
key
;
if
(
!
opts
.
maxDepth
)
{
maxDepth
=
currentDepth
+
1
;
}
if
(
!
isarray
&&
isobject
&&
Object
.
keys
(
value
).
length
&&
currentDepth
<
maxDepth
)
{
++
currentDepth
;
return
step
(
value
,
newKey
);
}
output
[
newKey
]
=
value
;
});
}
step
(
target
,
null
);
return
output
;
}
export
=
flatten
;
public/test/core/utils/flatten_specs.ts
0 → 100644
View file @
24b9bc1e
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
}
from
'test/lib/common'
import
flatten
=
require
(
'app/core/utils/flatten'
)
describe
(
"flatten"
,
()
=>
{
it
(
'should return flatten object'
,
()
=>
{
var
flattened
=
flatten
({
level1
:
'level1-value'
,
deeper
:
{
level2
:
'level2-value'
,
deeper
:
{
level3
:
'level3-value'
}
}
},
null
);
expect
(
flattened
[
'level1'
]).
to
.
be
(
'level1-value'
);
expect
(
flattened
[
'deeper.level2'
]).
to
.
be
(
'level2-value'
);
expect
(
flattened
[
'deeper.deeper.level3'
]).
to
.
be
(
'level3-value'
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment