Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sfm-js
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TransFem.org
sfm-js
Commits
044acbfe
Commit
044acbfe
authored
3 years ago
by
marihachi
Browse files
Options
Downloads
Patches
Plain Diff
refactor(api): APIのコードを移動
parent
72d85e79
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/api.ts
+58
-0
58 additions, 0 deletions
src/api.ts
src/index.ts
+7
-57
7 additions, 57 deletions
src/index.ts
with
65 additions
and
57 deletions
src/api.ts
0 → 100644
+
58
−
0
View file @
044acbfe
import
peg
from
'
pegjs
'
;
import
{
MfmNode
,
MfmPlainNode
}
from
'
./node
'
;
import
{
stringifyNode
,
stringifyTree
}
from
'
./util
'
;
const
parser
:
peg
.
Parser
=
require
(
'
./parser
'
);
export
function
parse
(
input
:
string
):
MfmNode
[]
{
const
nodes
=
parser
.
parse
(
input
,
{
startRule
:
'
fullParser
'
});
return
nodes
;
}
export
function
parsePlain
(
input
:
string
):
MfmPlainNode
[]
{
const
nodes
=
parser
.
parse
(
input
,
{
startRule
:
'
plainParser
'
});
return
nodes
;
}
export
function
toString
(
tree
:
MfmNode
[]):
string
export
function
toString
(
node
:
MfmNode
):
string
export
function
toString
(
node
:
MfmNode
|
MfmNode
[]):
string
{
if
(
Array
.
isArray
(
node
))
{
return
stringifyTree
(
node
);
}
else
{
return
stringifyNode
(
node
);
}
}
export
function
inspect
(
tree
:
MfmNode
[],
action
:
(
node
:
MfmNode
)
=>
void
):
void
{
for
(
const
node
of
tree
)
{
action
(
node
);
if
(
node
.
children
!=
null
)
{
inspect
(
node
.
children
,
action
);
}
}
}
export
function
extract
(
nodes
:
MfmNode
[],
type
:
(
MfmNode
[
'
type
'
]
|
MfmNode
[
'
type
'
][])):
MfmNode
[]
{
function
predicate
(
node
:
MfmNode
,
type
:
(
MfmNode
[
'
type
'
]
|
MfmNode
[
'
type
'
][])):
boolean
{
if
(
Array
.
isArray
(
type
))
{
return
(
type
.
some
(
i
=>
i
==
node
.
type
));
}
else
{
return
(
type
==
node
.
type
);
}
}
const
dest
=
[]
as
MfmNode
[];
for
(
const
node
of
nodes
)
{
if
(
predicate
(
node
,
type
))
{
dest
.
push
(
node
);
}
if
(
node
.
children
!=
null
)
{
dest
.
push
(...
extract
(
node
.
children
,
type
));
}
}
return
dest
;
}
This diff is collapsed.
Click to expand it.
src/index.ts
+
7
−
57
View file @
044acbfe
import
peg
from
'
pegjs
'
;
import
{
MfmNode
,
MfmPlainNode
}
from
'
./node
'
;
import
{
stringifyNode
,
stringifyTree
}
from
'
./util
'
;
const
parser
:
peg
.
Parser
=
require
(
'
./parser
'
);
export
function
parse
(
input
:
string
):
MfmNode
[]
{
const
nodes
=
parser
.
parse
(
input
,
{
startRule
:
'
fullParser
'
});
return
nodes
;
}
export
function
parsePlain
(
input
:
string
):
MfmPlainNode
[]
{
const
nodes
=
parser
.
parse
(
input
,
{
startRule
:
'
plainParser
'
});
return
nodes
;
}
export
function
toString
(
tree
:
MfmNode
[]):
string
export
function
toString
(
node
:
MfmNode
):
string
export
function
toString
(
node
:
MfmNode
|
MfmNode
[]):
string
{
if
(
Array
.
isArray
(
node
))
{
return
stringifyTree
(
node
);
}
else
{
return
stringifyNode
(
node
);
}
}
export
function
inspect
(
tree
:
MfmNode
[],
action
:
(
node
:
MfmNode
)
=>
void
):
void
{
for
(
const
node
of
tree
)
{
action
(
node
);
if
(
node
.
children
!=
null
)
{
inspect
(
node
.
children
,
action
);
}
}
}
export
function
extract
(
nodes
:
MfmNode
[],
type
:
(
MfmNode
[
'
type
'
]
|
MfmNode
[
'
type
'
][])):
MfmNode
[]
{
function
predicate
(
node
:
MfmNode
,
type
:
(
MfmNode
[
'
type
'
]
|
MfmNode
[
'
type
'
][])):
boolean
{
if
(
Array
.
isArray
(
type
))
{
return
(
type
.
some
(
i
=>
i
==
node
.
type
));
}
else
{
return
(
type
==
node
.
type
);
}
}
const
dest
=
[]
as
MfmNode
[];
for
(
const
node
of
nodes
)
{
if
(
predicate
(
node
,
type
))
{
dest
.
push
(
node
);
}
if
(
node
.
children
!=
null
)
{
dest
.
push
(...
extract
(
node
.
children
,
type
));
}
}
return
dest
;
}
export
{
parse
,
parsePlain
,
toString
,
inspect
,
extract
}
from
'
./api
'
;
export
{
NodeType
}
from
'
./node
'
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment