FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodegit.nodegit/lib/utils/lookup_wrapper.js at master · javascript-forks/nodegit.nodegit · GitHub
javascript-forks
nodegit.nodegit
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
nodegit.nodegit
/
lib
/
utils
/
lookup_wrapper.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
40 lines (32 loc) · 1.11 KB
Breadcrumbs
nodegit.nodegit
/
lib
/
utils
/
lookup_wrapper.js
Copy path
File metadata and controls
40 lines (32 loc) · 1.11 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var
Promise
=
require
(
"nodegit-promise"
)
;
var
NodeGit
=
require
(
"../../"
)
;
/**
* Wraps a method so that you can pass in either a string, OID or the object
* itself and you will always get back a promise that resolves to the object.
*
@param
{
Object
} objectType The object type that you're expecting to receive.
*
@param
{
Function
} lookupFunction The function to do the lookup for the
* object. Defaults to `objectType.lookup`.
*
@return
{
Function
}
*/
function
lookupWrapper
(
objectType
,
lookupFunction
)
{
lookupFunction
=
lookupFunction
||
objectType
.
lookup
;
return
function
(
repo
,
id
,
callback
)
{
if
(
id
instanceof
objectType
)
{
return
Promise
.
resolve
(
id
)
.
then
(
function
(
obj
)
{
obj
.
repo
=
repo
;
if
(
typeof
callback
===
"function"
)
{
callback
(
null
,
obj
)
;
}
return
obj
;
}
,
callback
)
;
}
return
lookupFunction
(
repo
,
id
)
.
then
(
function
(
obj
)
{
obj
.
repo
=
repo
;
if
(
typeof
callback
===
"function"
)
{
callback
(
null
,
obj
)
;
}
return
obj
;
}
,
callback
)
;
}
;
}
NodeGit
.
Utils
.
lookupWrapper
=
lookupWrapper
;
Back
|
FazBrowse Home
|
New Git URL