提交 84cc6677 编写于 作者: D DCloud_LXH

feat: css、uni-app x

上级 d4022915
...@@ -90,6 +90,12 @@ const config = { ...@@ -90,6 +90,12 @@ const config = {
leftDelimiter: '#{', leftDelimiter: '#{',
rightDelimiter: '}' rightDelimiter: '}'
}]) }])
.end()
.plugin('task-lists')
.use(require('markdown-it-task-lists'))
.end()
.plugin('inject-json-to-md')
.use(require('./markdown/inject-json-to-md'))
} }
}, },
chainWebpack (config, isServer) { chainWebpack (config, isServer) {
......
...@@ -42,6 +42,11 @@ export const navbar = [ ...@@ -42,6 +42,11 @@ export const navbar = [
type: 'link', type: 'link',
link: '/uts/' link: '/uts/'
}, },
{
text: 'uni-app x',
type: 'link',
link: '/uni-app-x/'
},
{ {
text: '插件', text: '插件',
type: 'link', type: 'link',
......
let cssJson = {};
let utsJson = {};
try {
cssJson = require('../utils/cssJson.json');
} catch (error) {}
try {
utsJson = require('../utils/utsJson.json');
} catch (error) {}
const getJSON = text => {
let match = text.match(/<!--\s*CSSJSON.([\w\W]+[^\s])\s*-->/);
if (match) {
return {
match,
json: cssJson,
};
}
match = text.match(/<!--\s*UTSJSON.([\w\W]+[^\s])\s*-->/);
if (match) {
return {
match,
json: utsJson,
};
}
return {
match: null,
json: {},
};
};
module.exports = function (md, opts) {
if (Object.keys(cssJson) === 0) return false;
md.core.ruler.after('inline', 'merge-css', function (state) {
/* const ids = []
let idIdx = 1 */
for (let index = 0; index < state.tokens.length; index++) {
const blockToken = state.tokens[index];
if (blockToken.type === 'html_block') {
const { match, json } = getJSON(blockToken.content);
if (match) {
const jsonPath = match[1];
const path = jsonPath.split('.');
let temp = json;
path.forEach(key => {
temp = temp[key];
});
const parseTokens = md.parse(temp);
/* parseTokens.forEach(token => {
if (token.type === 'heading_open') {
const id = token.attrGet('id')
if(ids.includes(id)) {
token.attrSet('id', `${id}_${idIdx++}`)
} else {
ids.push(id)
}
}
}) */
state.tokens.splice(index, 1, ...parseTokens);
index = index + parseTokens.length - 1;
// blockToken.content = temp
}
}
}
return false;
});
};
此差异已折叠。
...@@ -14,7 +14,7 @@ function simplifySlugText(text) { ...@@ -14,7 +14,7 @@ function simplifySlugText(text) {
return text; return text;
} }
const tabs = ['/uniCloud/', '/plugin/', '/worktile/', '/tutorial/', '/collocation/', '/component/', '/api/', '/uts/', '/'] const tabs = ['/uniCloud/', '/plugin/', '/worktile/', '/tutorial/', '/collocation/', '/component/', '/api/', '/uts/', '/uni-app-x/', '/']
module.exports = { module.exports = {
isExternal, isExternal,
......
此差异已折叠。
* [概述](README.md) * [概述](README.md)
* [新建项目]() * CSS
* [align-content](css/align-content.md)
* [align-items](css/align-items.md)
* [background](css/background.md)
* [background-clip](css/background-clip.md)
* [background-color](css/background-color.md)
* [background-image](css/background-image.md)
* [border](css/border.md)
* [border-bottom-color](css/border-bottom-color.md)
* [border-bottom-left-radius](css/border-bottom-left-radius.md)
* [border-bottom-right-radius](css/border-bottom-right-radius.md)
* [border-bottom-style](css/border-bottom-style.md)
* [border-bottom-width](css/border-bottom-width.md)
* [border-color](css/border-color.md)
* [border-left-color](css/border-left-color.md)
* [border-left-style](css/border-left-style.md)
* [border-left-width](css/border-left-width.md)
* [border-radius](css/border-radius.md)
* [border-right-color](css/border-right-color.md)
* [border-right-style](css/border-right-style.md)
* [border-right-width](css/border-right-width.md)
* [border-style](css/border-style.md)
* [border-top-color](css/border-top-color.md)
* [border-top-left-radius](css/border-top-left-radius.md)
* [border-top-right-radius](css/border-top-right-radius.md)
* [border-top-style](css/border-top-style.md)
* [border-top-width](css/border-top-width.md)
* [border-width](css/border-width.md)
* [bottom](css/bottom.md)
* [box-shadow](css/box-shadow.md)
* [box-sizing](css/box-sizing.md)
* [color](css/color.md)
* [display](css/display.md)
* [flex](css/flex.md)
* [flex-basis](css/flex-basis.md)
* [flex-direction](css/flex-direction.md)
* [flex-flow](css/flex-flow.md)
* [flex-grow](css/flex-grow.md)
* [flex-shrink](css/flex-shrink.md)
* [flex-wrap](css/flex-wrap.md)
* [font-family](css/font-family.md)
* [font-size](css/font-size.md)
* [font-style](css/font-style.md)
* [font-weight](css/font-weight.md)
* [height](css/height.md)
* [justify-content](css/justify-content.md)
* [left](css/left.md)
* [line-height](css/line-height.md)
* [margin](css/margin.md)
* [margin-bottom](css/margin-bottom.md)
* [margin-left](css/margin-left.md)
* [margin-right](css/margin-right.md)
* [margin-top](css/margin-top.md)
* [max-height](css/max-height.md)
* [max-width](css/max-width.md)
* [min-height](css/min-height.md)
* [min-width](css/min-width.md)
* [opacity](css/opacity.md)
* [overflow](css/overflow.md)
* [padding](css/padding.md)
* [padding-bottom](css/padding-bottom.md)
* [padding-left](css/padding-left.md)
* [padding-right](css/padding-right.md)
* [padding-top](css/padding-top.md)
* [position](css/position.md)
* [right](css/right.md)
* [text-align](css/text-align.md)
* [text-decoration](css/text-decoration.md)
* [text-decoration-color](css/text-decoration-color.md)
* [text-decoration-line](css/text-decoration-line.md)
* [text-decoration-style](css/text-decoration-style.md)
* [text-overflow](css/text-overflow.md)
* [top](css/top.md)
* [transform](css/transform.md)
* [transition](css/transition.md)
* [transition-delay](css/transition-delay.md)
* [transition-duration](css/transition-duration.md)
* [transition-property](css/transition-property.md)
* [transition-timing-function](css/transition-timing-function.md)
* [width](css/width.md)
* [z-index](css/z-index.md)
* [text-decoration-thickness](css/text-decoration-thickness.md)
* [lines](css/lines.md)
<!-- * [新建项目]()
* [1. 通过 HBuilderX 可视化界面](quickstart-hx.md) * [1. 通过 HBuilderX 可视化界面](quickstart-hx.md)
* [运行和调试]() * [运行和调试]()
* [打包发行]() * [打包发行]()
...@@ -8,7 +91,6 @@ ...@@ -8,7 +91,6 @@
* [全局文件]() * [全局文件]()
* [组件]() * [组件]()
* [API]() * [API]()
* [CSS]()
* [编译器]() * [编译器]()
* [质量]() * [质量]()
* [性能]() * [性能]() -->
## align-content
<!-- CSSJSON.align-content.description -->
<!-- CSSJSON.align-content.syntax -->
<!-- CSSJSON.align-content.values -->
<!-- CSSJSON.align-content.compatibility -->
<!-- CSSJSON.align-content.reference -->
\ No newline at end of file
## align-items
<!-- CSSJSON.align-items.description -->
<!-- CSSJSON.align-items.syntax -->
<!-- CSSJSON.align-items.values -->
<!-- CSSJSON.align-items.compatibility -->
<!-- CSSJSON.align-items.reference -->
\ No newline at end of file
## background-clip
<!-- CSSJSON.background-clip.description -->
<!-- CSSJSON.background-clip.syntax -->
<!-- CSSJSON.background-clip.values -->
<!-- CSSJSON.background-clip.compatibility -->
<!-- CSSJSON.background-clip.reference -->
\ No newline at end of file
## background-color
<!-- CSSJSON.background-color.description -->
<!-- CSSJSON.background-color.syntax -->
<!-- CSSJSON.background-color.values -->
<!-- CSSJSON.background-color.compatibility -->
<!-- CSSJSON.background-color.reference -->
\ No newline at end of file
## background-image
<!-- CSSJSON.background-image.description -->
<!-- CSSJSON.background-image.syntax -->
<!-- CSSJSON.background-image.values -->
<!-- CSSJSON.background-image.compatibility -->
<!-- CSSJSON.background-image.reference -->
\ No newline at end of file
## background
<!-- CSSJSON.background.description -->
<!-- CSSJSON.background.syntax -->
<!-- CSSJSON.background.values -->
<!-- CSSJSON.background.compatibility -->
<!-- CSSJSON.background.reference -->
\ No newline at end of file
## border-bottom-color
<!-- CSSJSON.border-bottom-color.description -->
<!-- CSSJSON.border-bottom-color.syntax -->
<!-- CSSJSON.border-bottom-color.values -->
<!-- CSSJSON.border-bottom-color.compatibility -->
<!-- CSSJSON.border-bottom-color.reference -->
\ No newline at end of file
## border-bottom-left-radius
<!-- CSSJSON.border-bottom-left-radius.description -->
<!-- CSSJSON.border-bottom-left-radius.syntax -->
<!-- CSSJSON.border-bottom-left-radius.values -->
<!-- CSSJSON.border-bottom-left-radius.compatibility -->
<!-- CSSJSON.border-bottom-left-radius.reference -->
\ No newline at end of file
## border-bottom-right-radius
<!-- CSSJSON.border-bottom-right-radius.description -->
<!-- CSSJSON.border-bottom-right-radius.syntax -->
<!-- CSSJSON.border-bottom-right-radius.values -->
<!-- CSSJSON.border-bottom-right-radius.compatibility -->
<!-- CSSJSON.border-bottom-right-radius.reference -->
\ No newline at end of file
## border-bottom-style
<!-- CSSJSON.border-bottom-style.description -->
<!-- CSSJSON.border-bottom-style.syntax -->
<!-- CSSJSON.border-bottom-style.values -->
<!-- CSSJSON.border-bottom-style.compatibility -->
<!-- CSSJSON.border-bottom-style.reference -->
\ No newline at end of file
## border-bottom-width
<!-- CSSJSON.border-bottom-width.description -->
<!-- CSSJSON.border-bottom-width.syntax -->
<!-- CSSJSON.border-bottom-width.values -->
<!-- CSSJSON.border-bottom-width.compatibility -->
<!-- CSSJSON.border-bottom-width.reference -->
\ No newline at end of file
## border-color
<!-- CSSJSON.border-color.description -->
<!-- CSSJSON.border-color.syntax -->
<!-- CSSJSON.border-color.values -->
<!-- CSSJSON.border-color.compatibility -->
<!-- CSSJSON.border-color.reference -->
\ No newline at end of file
## border-left-color
<!-- CSSJSON.border-left-color.description -->
<!-- CSSJSON.border-left-color.syntax -->
<!-- CSSJSON.border-left-color.values -->
<!-- CSSJSON.border-left-color.compatibility -->
<!-- CSSJSON.border-left-color.reference -->
\ No newline at end of file
## border-left-style
<!-- CSSJSON.border-left-style.description -->
<!-- CSSJSON.border-left-style.syntax -->
<!-- CSSJSON.border-left-style.values -->
<!-- CSSJSON.border-left-style.compatibility -->
<!-- CSSJSON.border-left-style.reference -->
\ No newline at end of file
## border-left-width
<!-- CSSJSON.border-left-width.description -->
<!-- CSSJSON.border-left-width.syntax -->
<!-- CSSJSON.border-left-width.values -->
<!-- CSSJSON.border-left-width.compatibility -->
<!-- CSSJSON.border-left-width.reference -->
\ No newline at end of file
## border-radius
<!-- CSSJSON.border-radius.description -->
<!-- CSSJSON.border-radius.syntax -->
<!-- CSSJSON.border-radius.values -->
<!-- CSSJSON.border-radius.compatibility -->
<!-- CSSJSON.border-radius.reference -->
\ No newline at end of file
## border-right-color
<!-- CSSJSON.border-right-color.description -->
<!-- CSSJSON.border-right-color.syntax -->
<!-- CSSJSON.border-right-color.values -->
<!-- CSSJSON.border-right-color.compatibility -->
<!-- CSSJSON.border-right-color.reference -->
\ No newline at end of file
## border-right-style
<!-- CSSJSON.border-right-style.description -->
<!-- CSSJSON.border-right-style.syntax -->
<!-- CSSJSON.border-right-style.values -->
<!-- CSSJSON.border-right-style.compatibility -->
<!-- CSSJSON.border-right-style.reference -->
\ No newline at end of file
## border-right-width
<!-- CSSJSON.border-right-width.description -->
<!-- CSSJSON.border-right-width.syntax -->
<!-- CSSJSON.border-right-width.values -->
<!-- CSSJSON.border-right-width.compatibility -->
<!-- CSSJSON.border-right-width.reference -->
\ No newline at end of file
## border-style
<!-- CSSJSON.border-style.description -->
<!-- CSSJSON.border-style.syntax -->
<!-- CSSJSON.border-style.values -->
<!-- CSSJSON.border-style.compatibility -->
<!-- CSSJSON.border-style.reference -->
\ No newline at end of file
## border-top-color
<!-- CSSJSON.border-top-color.description -->
<!-- CSSJSON.border-top-color.syntax -->
<!-- CSSJSON.border-top-color.values -->
<!-- CSSJSON.border-top-color.compatibility -->
<!-- CSSJSON.border-top-color.reference -->
\ No newline at end of file
## border-top-left-radius
<!-- CSSJSON.border-top-left-radius.description -->
<!-- CSSJSON.border-top-left-radius.syntax -->
<!-- CSSJSON.border-top-left-radius.values -->
<!-- CSSJSON.border-top-left-radius.compatibility -->
<!-- CSSJSON.border-top-left-radius.reference -->
\ No newline at end of file
## border-top-right-radius
<!-- CSSJSON.border-top-right-radius.description -->
<!-- CSSJSON.border-top-right-radius.syntax -->
<!-- CSSJSON.border-top-right-radius.values -->
<!-- CSSJSON.border-top-right-radius.compatibility -->
<!-- CSSJSON.border-top-right-radius.reference -->
\ No newline at end of file
## border-top-style
<!-- CSSJSON.border-top-style.description -->
<!-- CSSJSON.border-top-style.syntax -->
<!-- CSSJSON.border-top-style.values -->
<!-- CSSJSON.border-top-style.compatibility -->
<!-- CSSJSON.border-top-style.reference -->
\ No newline at end of file
## border-top-width
<!-- CSSJSON.border-top-width.description -->
<!-- CSSJSON.border-top-width.syntax -->
<!-- CSSJSON.border-top-width.values -->
<!-- CSSJSON.border-top-width.compatibility -->
<!-- CSSJSON.border-top-width.reference -->
\ No newline at end of file
## border-width
<!-- CSSJSON.border-width.description -->
<!-- CSSJSON.border-width.syntax -->
<!-- CSSJSON.border-width.values -->
<!-- CSSJSON.border-width.compatibility -->
<!-- CSSJSON.border-width.reference -->
\ No newline at end of file
## border
<!-- CSSJSON.border.description -->
<!-- CSSJSON.border.syntax -->
<!-- CSSJSON.border.values -->
<!-- CSSJSON.border.compatibility -->
<!-- CSSJSON.border.reference -->
\ No newline at end of file
## bottom
<!-- CSSJSON.bottom.description -->
<!-- CSSJSON.bottom.syntax -->
<!-- CSSJSON.bottom.values -->
<!-- CSSJSON.bottom.compatibility -->
<!-- CSSJSON.bottom.reference -->
\ No newline at end of file
## box-shadow
<!-- CSSJSON.box-shadow.description -->
<!-- CSSJSON.box-shadow.syntax -->
<!-- CSSJSON.box-shadow.values -->
<!-- CSSJSON.box-shadow.compatibility -->
<!-- CSSJSON.box-shadow.reference -->
\ No newline at end of file
## box-sizing
<!-- CSSJSON.box-sizing.description -->
<!-- CSSJSON.box-sizing.syntax -->
<!-- CSSJSON.box-sizing.values -->
<!-- CSSJSON.box-sizing.compatibility -->
<!-- CSSJSON.box-sizing.reference -->
\ No newline at end of file
## color
<!-- CSSJSON.color.description -->
<!-- CSSJSON.color.syntax -->
<!-- CSSJSON.color.values -->
<!-- CSSJSON.color.compatibility -->
<!-- CSSJSON.color.reference -->
\ No newline at end of file
## display
<!-- CSSJSON.display.description -->
<!-- CSSJSON.display.syntax -->
<!-- CSSJSON.display.values -->
<!-- CSSJSON.display.compatibility -->
<!-- CSSJSON.display.reference -->
\ No newline at end of file
## flex-basis
<!-- CSSJSON.flex-basis.description -->
<!-- CSSJSON.flex-basis.syntax -->
<!-- CSSJSON.flex-basis.values -->
<!-- CSSJSON.flex-basis.compatibility -->
<!-- CSSJSON.flex-basis.reference -->
\ No newline at end of file
## flex-direction
<!-- CSSJSON.flex-direction.description -->
<!-- CSSJSON.flex-direction.syntax -->
<!-- CSSJSON.flex-direction.values -->
<!-- CSSJSON.flex-direction.compatibility -->
<!-- CSSJSON.flex-direction.reference -->
\ No newline at end of file
## flex-flow
<!-- CSSJSON.flex-flow.description -->
<!-- CSSJSON.flex-flow.syntax -->
<!-- CSSJSON.flex-flow.values -->
<!-- CSSJSON.flex-flow.compatibility -->
<!-- CSSJSON.flex-flow.reference -->
\ No newline at end of file
## flex-grow
<!-- CSSJSON.flex-grow.description -->
<!-- CSSJSON.flex-grow.syntax -->
<!-- CSSJSON.flex-grow.values -->
<!-- CSSJSON.flex-grow.compatibility -->
<!-- CSSJSON.flex-grow.reference -->
\ No newline at end of file
## flex-shrink
<!-- CSSJSON.flex-shrink.description -->
<!-- CSSJSON.flex-shrink.syntax -->
<!-- CSSJSON.flex-shrink.values -->
<!-- CSSJSON.flex-shrink.compatibility -->
<!-- CSSJSON.flex-shrink.reference -->
\ No newline at end of file
## flex-wrap
<!-- CSSJSON.flex-wrap.description -->
<!-- CSSJSON.flex-wrap.syntax -->
<!-- CSSJSON.flex-wrap.values -->
<!-- CSSJSON.flex-wrap.compatibility -->
<!-- CSSJSON.flex-wrap.reference -->
\ No newline at end of file
## flex
<!-- CSSJSON.flex.description -->
<!-- CSSJSON.flex.syntax -->
<!-- CSSJSON.flex.values -->
<!-- CSSJSON.flex.compatibility -->
<!-- CSSJSON.flex.reference -->
\ No newline at end of file
## font-family
<!-- CSSJSON.font-family.description -->
<!-- CSSJSON.font-family.syntax -->
<!-- CSSJSON.font-family.values -->
<!-- CSSJSON.font-family.compatibility -->
<!-- CSSJSON.font-family.reference -->
\ No newline at end of file
## font-size
<!-- CSSJSON.font-size.description -->
<!-- CSSJSON.font-size.syntax -->
<!-- CSSJSON.font-size.values -->
<!-- CSSJSON.font-size.compatibility -->
<!-- CSSJSON.font-size.reference -->
\ No newline at end of file
## font-style
<!-- CSSJSON.font-style.description -->
<!-- CSSJSON.font-style.syntax -->
<!-- CSSJSON.font-style.values -->
<!-- CSSJSON.font-style.compatibility -->
<!-- CSSJSON.font-style.reference -->
\ No newline at end of file
## font-weight
<!-- CSSJSON.font-weight.description -->
<!-- CSSJSON.font-weight.syntax -->
<!-- CSSJSON.font-weight.values -->
<!-- CSSJSON.font-weight.compatibility -->
<!-- CSSJSON.font-weight.reference -->
\ No newline at end of file
## height
<!-- CSSJSON.height.description -->
<!-- CSSJSON.height.syntax -->
<!-- CSSJSON.height.values -->
<!-- CSSJSON.height.compatibility -->
<!-- CSSJSON.height.reference -->
\ No newline at end of file
## justify-content
<!-- CSSJSON.justify-content.description -->
<!-- CSSJSON.justify-content.syntax -->
<!-- CSSJSON.justify-content.values -->
<!-- CSSJSON.justify-content.compatibility -->
<!-- CSSJSON.justify-content.reference -->
\ No newline at end of file
## left
<!-- CSSJSON.left.description -->
<!-- CSSJSON.left.syntax -->
<!-- CSSJSON.left.values -->
<!-- CSSJSON.left.compatibility -->
<!-- CSSJSON.left.reference -->
\ No newline at end of file
## line-height
<!-- CSSJSON.line-height.description -->
<!-- CSSJSON.line-height.syntax -->
<!-- CSSJSON.line-height.values -->
<!-- CSSJSON.line-height.compatibility -->
<!-- CSSJSON.line-height.reference -->
\ No newline at end of file
## lines
<!-- CSSJSON.lines.description -->
<!-- CSSJSON.lines.syntax -->
<!-- CSSJSON.lines.values -->
<!-- CSSJSON.lines.compatibility -->
<!-- CSSJSON.lines.reference -->
\ No newline at end of file
## margin-bottom
<!-- CSSJSON.margin-bottom.description -->
<!-- CSSJSON.margin-bottom.syntax -->
<!-- CSSJSON.margin-bottom.values -->
<!-- CSSJSON.margin-bottom.compatibility -->
<!-- CSSJSON.margin-bottom.reference -->
\ No newline at end of file
## margin-left
<!-- CSSJSON.margin-left.description -->
<!-- CSSJSON.margin-left.syntax -->
<!-- CSSJSON.margin-left.values -->
<!-- CSSJSON.margin-left.compatibility -->
<!-- CSSJSON.margin-left.reference -->
\ No newline at end of file
## margin-right
<!-- CSSJSON.margin-right.description -->
<!-- CSSJSON.margin-right.syntax -->
<!-- CSSJSON.margin-right.values -->
<!-- CSSJSON.margin-right.compatibility -->
<!-- CSSJSON.margin-right.reference -->
\ No newline at end of file
## margin-top
<!-- CSSJSON.margin-top.description -->
<!-- CSSJSON.margin-top.syntax -->
<!-- CSSJSON.margin-top.values -->
<!-- CSSJSON.margin-top.compatibility -->
<!-- CSSJSON.margin-top.reference -->
\ No newline at end of file
## margin
<!-- CSSJSON.margin.description -->
<!-- CSSJSON.margin.syntax -->
<!-- CSSJSON.margin.values -->
<!-- CSSJSON.margin.compatibility -->
<!-- CSSJSON.margin.reference -->
\ No newline at end of file
## max-height
<!-- CSSJSON.max-height.description -->
<!-- CSSJSON.max-height.syntax -->
<!-- CSSJSON.max-height.values -->
<!-- CSSJSON.max-height.compatibility -->
<!-- CSSJSON.max-height.reference -->
\ No newline at end of file
## max-width
<!-- CSSJSON.max-width.description -->
<!-- CSSJSON.max-width.syntax -->
<!-- CSSJSON.max-width.values -->
<!-- CSSJSON.max-width.compatibility -->
<!-- CSSJSON.max-width.reference -->
\ No newline at end of file
## min-height
<!-- CSSJSON.min-height.description -->
<!-- CSSJSON.min-height.syntax -->
<!-- CSSJSON.min-height.values -->
<!-- CSSJSON.min-height.compatibility -->
<!-- CSSJSON.min-height.reference -->
\ No newline at end of file
## min-width
<!-- CSSJSON.min-width.description -->
<!-- CSSJSON.min-width.syntax -->
<!-- CSSJSON.min-width.values -->
<!-- CSSJSON.min-width.compatibility -->
<!-- CSSJSON.min-width.reference -->
\ No newline at end of file
## opacity
<!-- CSSJSON.opacity.description -->
<!-- CSSJSON.opacity.syntax -->
<!-- CSSJSON.opacity.values -->
<!-- CSSJSON.opacity.compatibility -->
<!-- CSSJSON.opacity.reference -->
\ No newline at end of file
## overflow
<!-- CSSJSON.overflow.description -->
<!-- CSSJSON.overflow.syntax -->
<!-- CSSJSON.overflow.values -->
<!-- CSSJSON.overflow.compatibility -->
<!-- CSSJSON.overflow.reference -->
\ No newline at end of file
## padding-bottom
<!-- CSSJSON.padding-bottom.description -->
<!-- CSSJSON.padding-bottom.syntax -->
<!-- CSSJSON.padding-bottom.values -->
<!-- CSSJSON.padding-bottom.compatibility -->
<!-- CSSJSON.padding-bottom.reference -->
\ No newline at end of file
## padding-left
<!-- CSSJSON.padding-left.description -->
<!-- CSSJSON.padding-left.syntax -->
<!-- CSSJSON.padding-left.values -->
<!-- CSSJSON.padding-left.compatibility -->
<!-- CSSJSON.padding-left.reference -->
\ No newline at end of file
## padding-right
<!-- CSSJSON.padding-right.description -->
<!-- CSSJSON.padding-right.syntax -->
<!-- CSSJSON.padding-right.values -->
<!-- CSSJSON.padding-right.compatibility -->
<!-- CSSJSON.padding-right.reference -->
\ No newline at end of file
## padding-top
<!-- CSSJSON.padding-top.description -->
<!-- CSSJSON.padding-top.syntax -->
<!-- CSSJSON.padding-top.values -->
<!-- CSSJSON.padding-top.compatibility -->
<!-- CSSJSON.padding-top.reference -->
\ No newline at end of file
## padding
<!-- CSSJSON.padding.description -->
<!-- CSSJSON.padding.syntax -->
<!-- CSSJSON.padding.values -->
<!-- CSSJSON.padding.compatibility -->
<!-- CSSJSON.padding.reference -->
\ No newline at end of file
## position
<!-- CSSJSON.position.description -->
<!-- CSSJSON.position.syntax -->
<!-- CSSJSON.position.values -->
<!-- CSSJSON.position.compatibility -->
<!-- CSSJSON.position.reference -->
\ No newline at end of file
## right
<!-- CSSJSON.right.description -->
<!-- CSSJSON.right.syntax -->
<!-- CSSJSON.right.values -->
<!-- CSSJSON.right.compatibility -->
<!-- CSSJSON.right.reference -->
\ No newline at end of file
## text-align
<!-- CSSJSON.text-align.description -->
<!-- CSSJSON.text-align.syntax -->
<!-- CSSJSON.text-align.values -->
<!-- CSSJSON.text-align.compatibility -->
<!-- CSSJSON.text-align.reference -->
\ No newline at end of file
## text-decoration-color
<!-- CSSJSON.text-decoration-color.description -->
<!-- CSSJSON.text-decoration-color.syntax -->
<!-- CSSJSON.text-decoration-color.values -->
<!-- CSSJSON.text-decoration-color.compatibility -->
<!-- CSSJSON.text-decoration-color.reference -->
\ No newline at end of file
## text-decoration-line
<!-- CSSJSON.text-decoration-line.description -->
<!-- CSSJSON.text-decoration-line.syntax -->
<!-- CSSJSON.text-decoration-line.values -->
<!-- CSSJSON.text-decoration-line.compatibility -->
<!-- CSSJSON.text-decoration-line.reference -->
\ No newline at end of file
## text-decoration-style
<!-- CSSJSON.text-decoration-style.description -->
<!-- CSSJSON.text-decoration-style.syntax -->
<!-- CSSJSON.text-decoration-style.values -->
<!-- CSSJSON.text-decoration-style.compatibility -->
<!-- CSSJSON.text-decoration-style.reference -->
\ No newline at end of file
## text-decoration-thickness
<!-- CSSJSON.text-decoration-thickness.description -->
<!-- CSSJSON.text-decoration-thickness.syntax -->
<!-- CSSJSON.text-decoration-thickness.values -->
<!-- CSSJSON.text-decoration-thickness.compatibility -->
<!-- CSSJSON.text-decoration-thickness.reference -->
\ No newline at end of file
## text-decoration
<!-- CSSJSON.text-decoration.description -->
<!-- CSSJSON.text-decoration.syntax -->
<!-- CSSJSON.text-decoration.values -->
<!-- CSSJSON.text-decoration.compatibility -->
<!-- CSSJSON.text-decoration.reference -->
\ No newline at end of file
## text-overflow
<!-- CSSJSON.text-overflow.description -->
<!-- CSSJSON.text-overflow.syntax -->
<!-- CSSJSON.text-overflow.values -->
<!-- CSSJSON.text-overflow.compatibility -->
<!-- CSSJSON.text-overflow.reference -->
\ No newline at end of file
## top
<!-- CSSJSON.top.description -->
<!-- CSSJSON.top.syntax -->
<!-- CSSJSON.top.values -->
<!-- CSSJSON.top.compatibility -->
<!-- CSSJSON.top.reference -->
\ No newline at end of file
## transform
<!-- CSSJSON.transform.description -->
<!-- CSSJSON.transform.syntax -->
<!-- CSSJSON.transform.values -->
<!-- CSSJSON.transform.compatibility -->
<!-- CSSJSON.transform.reference -->
\ No newline at end of file
## transition-delay
<!-- CSSJSON.transition-delay.description -->
<!-- CSSJSON.transition-delay.syntax -->
<!-- CSSJSON.transition-delay.values -->
<!-- CSSJSON.transition-delay.compatibility -->
<!-- CSSJSON.transition-delay.reference -->
\ No newline at end of file
## transition-duration
<!-- CSSJSON.transition-duration.description -->
<!-- CSSJSON.transition-duration.syntax -->
<!-- CSSJSON.transition-duration.values -->
<!-- CSSJSON.transition-duration.compatibility -->
<!-- CSSJSON.transition-duration.reference -->
\ No newline at end of file
## transition-property
<!-- CSSJSON.transition-property.description -->
<!-- CSSJSON.transition-property.syntax -->
<!-- CSSJSON.transition-property.values -->
<!-- CSSJSON.transition-property.compatibility -->
<!-- CSSJSON.transition-property.reference -->
\ No newline at end of file
## transition-timing-function
<!-- CSSJSON.transition-timing-function.description -->
<!-- CSSJSON.transition-timing-function.syntax -->
<!-- CSSJSON.transition-timing-function.values -->
<!-- CSSJSON.transition-timing-function.compatibility -->
<!-- CSSJSON.transition-timing-function.reference -->
\ No newline at end of file
## transition
<!-- CSSJSON.transition.description -->
<!-- CSSJSON.transition.syntax -->
<!-- CSSJSON.transition.values -->
<!-- CSSJSON.transition.compatibility -->
<!-- CSSJSON.transition.reference -->
\ No newline at end of file
## width
<!-- CSSJSON.width.description -->
<!-- CSSJSON.width.syntax -->
<!-- CSSJSON.width.values -->
<!-- CSSJSON.width.compatibility -->
<!-- CSSJSON.width.reference -->
\ No newline at end of file
## z-index
<!-- CSSJSON.z-index.description -->
<!-- CSSJSON.z-index.syntax -->
<!-- CSSJSON.z-index.values -->
<!-- CSSJSON.z-index.compatibility -->
<!-- CSSJSON.z-index.reference -->
\ No newline at end of file
uni-app x介绍
# uni-app x 是什么? # uni-app x 是什么?
uni-app x,是下一代 uni-app,是一个跨平台应用开发引擎。 uni-app x,是下一代 uni-app,是一个跨平台应用开发引擎。
...@@ -12,9 +10,9 @@ uni-app x 是一个庞大的工程,它包括uts语言、uvue渲染引擎、uni ...@@ -12,9 +10,9 @@ uni-app x 是一个庞大的工程,它包括uts语言、uvue渲染引擎、uni
uts 全称 uni type script,是一门跨平台的、高性能的、强类型的现代编程语言。它在不同平台,会被编译为不同平台的native语言,如: uts 全称 uni type script,是一门跨平台的、高性能的、强类型的现代编程语言。它在不同平台,会被编译为不同平台的native语言,如:
* web/小程序平台,编译为JavaScript > * web/小程序平台,编译为JavaScript
* Android平台,编译为Kotlin > * Android平台,编译为Kotlin
* iOS平台,编译Swift > * iOS平台,编译Swift
uts和ts很相似,但为了跨端,uts进行了一些约束和特定平台的增补。详见 [uts语言介绍](https://uniapp.dcloud.net.cn/uts/) uts和ts很相似,但为了跨端,uts进行了一些约束和特定平台的增补。详见 [uts语言介绍](https://uniapp.dcloud.net.cn/uts/)
...@@ -26,15 +24,15 @@ uts替代的是js,而uvue替代的就是html和css。或者如果你了解flut ...@@ -26,15 +24,15 @@ uts替代的是js,而uvue替代的就是html和css。或者如果你了解flut
uvue是一套基于uts的、兼容vue语法的、跨iOS和Android的、原生渲染引擎。 uvue是一套基于uts的、兼容vue语法的、跨iOS和Android的、原生渲染引擎。
uvue渲染引擎包括原生版的vue框架(组件、数据绑定...)、跨平台基础ui、css引擎。 uvue渲染引擎包括原生版的vue框架(组件、数据绑定...、跨平台基础ui、css引擎。
有了uvue,开发者就可以使用vue语法写一套页面,编译为高性能的纯原生界面。 有了uvue,开发者就可以使用vue语法写一套页面,编译为高性能的纯原生界面。
在过去的跨平台方案中,逻辑层和ui层的通信始终是痛点。 在过去的跨平台方案中,逻辑层和ui层的通信始终是痛点。
* 所以在webview渲染时,增加了renderjs、wxs等技术 > * 所以在webview渲染时,增加了renderjs、wxs等技术
* 所以在nvue渲染时,增加了bindingX技术 > * 所以在nvue渲染时,增加了bindingX技术
* 所以在skyline渲染时,增加了worklet技术 > * 所以在skyline渲染时,增加了worklet技术
但这些补丁技术都不治根。过去只有flutter解决了dart和ui层的通信问题,但dart和原生层通信也还是有延时。 但这些补丁技术都不治根。过去只有flutter解决了dart和ui层的通信问题,但dart和原生层通信也还是有延时。
...@@ -246,7 +244,7 @@ uni-app 的自动化测试教程详见:[https://uniapp.dcloud.net.cn/worktile/ ...@@ -246,7 +244,7 @@ uni-app 的自动化测试教程详见:[https://uniapp.dcloud.net.cn/worktile/
- 一期不支持:云开发(已在开发中)、uni-ad。另外包括微信、支付宝、个推等三方sdk封装一期均未启动 - 一期不支持:云开发(已在开发中)、uni-ad。另外包括微信、支付宝、个推等三方sdk封装一期均未启动
- 一期不支持国际区账户创建和打包uni-app x,仅大陆区开发者账户可用。 - 一期不支持国际区账户创建和打包uni-app x,仅大陆区开发者账户可用。
欢迎去[需求墙]()投票,告诉我们你的需求优先级。 欢迎去[需求墙](https://vote.dcloud.net.cn/)投票,告诉我们你的需求优先级。
# 历史老项目兼容指南 # 历史老项目兼容指南
......
## Array # Array
Array 对象是用于构造数组的全局对象,数组是类似于列表的高阶对象。 Array 对象是用于构造数组的全局对象,数组是类似于列表的高阶对象。
### 实例属性 ## 实例属性
### length ### length
数组中的元素个数 <!-- UTSJSON.Array.length.description -->
<!-- UTSJSON.Array.length.param -->
<!-- UTSJSON.Array.length.returValue -->
```ts ```ts
const clothing = ['shoes', 'shirts', 'socks', 'sweaters']; const clothing = ['shoes', 'shirts', 'socks', 'sweaters'];
...@@ -14,6 +19,8 @@ console.log(clothing.length); ...@@ -14,6 +19,8 @@ console.log(clothing.length);
// expected output: 4 // expected output: 4
``` ```
<!-- UTSJSON.Array.length.compatibility -->
边界情况说明: 边界情况说明:
- 在不同平台上,数组的长度限制不同,超出限制会导致相应的错误或异常 - 在不同平台上,数组的长度限制不同,超出限制会导致相应的错误或异常
...@@ -21,48 +28,57 @@ console.log(clothing.length); ...@@ -21,48 +28,57 @@ console.log(clothing.length);
* 编译至 Kotlin 平台时,最大长度受系统内存的限制,超出限制报错:`java.lang.OutOfMemoryError: Failed to allocate a allocation until OOM` * 编译至 Kotlin 平台时,最大长度受系统内存的限制,超出限制报错:`java.lang.OutOfMemoryError: Failed to allocate a allocation until OOM`
* 编译至 Swift 平台时,最大长度也受系统内存的限制,目前超出限制没有返回信息。 * 编译至 Swift 平台时,最大长度也受系统内存的限制,目前超出限制没有返回信息。
### 实例方法
### concat ## 实例方法
concat() 方法用于合并两个或多个数组。此方法不会更改现有数组,而是返回一个新数组。
```ts ### find(predicate, thisArg?)
const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = array1.concat(array2);
console.log(array3);
// expected output: Array ["a", "b", "c", "d", "e", "f"]
```
### copyWithin <!-- UTSJSON.Array.find.description -->
copyWithin() 方法浅复制数组的一部分到同一数组中的另一个位置,并返回它,不会改变原数组的长度。 <!-- UTSJSON.Array.find.param -->
<!-- UTSJSON.Array.find.returValue -->
```ts ```ts
const array1 = ['a', 'b', 'c', 'd', 'e']; const array1 = [5, 12, 8, 130, 44];
// copy to index 0 the element at index 3
console.log(array1.copyWithin(0, 3, 4)); const found = array1.find((element:number):boolean => element > 10);
// expected output: Array ["d", "b", "c", "d", "e"]
// copy to index 1 all elements from index 3 to the end console.log(found);
console.log(array1.copyWithin(1, 3)); // expected output: 12
// expected output: Array ["d", "d", "e", "d", "e"]
``` ```
### every <!-- UTSJSON.Array.find.compatibility -->
every() 方法测试一个数组内的所有元素是否都能通过某个指定函数的测试。它返回一个布尔值。 ### findIndex(predicate, thisArg?)
<!-- UTSJSON.Array.findIndex.description -->
<!-- UTSJSON.Array.findIndex.param -->
<!-- UTSJSON.Array.findIndex.returValue -->
```ts ```ts
const isBelowThreshold = (currentValue:number):boolean => currentValue < 40; const array1 = [5, 12, 8, 130, 44];
const array1 = [1, 30, 39, 29, 10, 13];
console.log(array1.every(isBelowThreshold)); const isLargeNumber = (element:number):boolean => element > 13;
// expected output: true
console.log(array1.findIndex(isLargeNumber));
// expected output: 3
``` ```
### fill <!-- UTSJSON.Array.findIndex.compatibility -->
### fill(value, start?, end?)
fill() 方法用一个固定值填充一个数组中从起始索引到终止索引内的全部元素。不包括终止索引。 <!-- UTSJSON.Array.fill.description -->
<!-- UTSJSON.Array.fill.param -->
<!-- UTSJSON.Array.fill.returValue -->
```ts ```ts
const array1 = [1, 2, 3, 4]; const array1 = [1, 2, 3, 4];
...@@ -79,117 +95,115 @@ console.log(array1.fill(6)); ...@@ -79,117 +95,115 @@ console.log(array1.fill(6));
// expected output: [6, 6, 6, 6] // expected output: [6, 6, 6, 6]
``` ```
### filter
filter() 方法创建一个新数组,其包含通过所提供函数实现的测试的所有元素。 <!-- UTSJSON.Array.fill.compatibility -->
```ts ### copyWithin(target, start?, end?)
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter((word:string):boolean => word.length > 6); <!-- UTSJSON.Array.copyWithin.description -->
console.log(result); <!-- UTSJSON.Array.copyWithin.param -->
// expected output: Array ["exuberant", "destruction", "present"]
```
### find
find() 方法返回数组中满足提供的测试函数的第一个元素的值。 <!-- UTSJSON.Array.copyWithin.returValue -->
```ts ```ts
const array1 = [5, 12, 8, 130, 44]; const array1 = ['a', 'b', 'c', 'd', 'e'];
// copy to index 0 the element at index 3
console.log(array1.copyWithin(0, 3, 4));
// expected output: Array ["d", "b", "c", "d", "e"]
// copy to index 1 all elements from index 3 to the end
console.log(array1.copyWithin(1, 3));
// expected output: Array ["d", "d", "e", "d", "e"]
```
const found = array1.find((element:number):boolean => element > 10); <!-- UTSJSON.Array.copyWithin.compatibility -->
console.log(found); ### pop()
// expected output: 12
``` <!-- UTSJSON.Array.pop.description -->
### findIndex <!-- UTSJSON.Array.pop.param -->
findIndex()方法返回数组中满足提供的测试函数的第一个元素的索引。若没有找到对应元素则返回-1。 <!-- UTSJSON.Array.pop.returValue -->
```ts ```ts
const array1 = [5, 12, 8, 130, 44]; const plants = ['broccoli', 'cauliflower', 'cabbage', 'kale', 'tomato'];
const isLargeNumber = (element:number):boolean => element > 13;
console.log(array1.findIndex(isLargeNumber)); console.log(plants.pop());
// expected output: 3 // expected output: "tomato"
``` console.log(plants);
// expected output: Array ["broccoli", "cauliflower", "cabbage", "kale"]
### flat plants.pop();
flat() 方法会按照一个可指定的深度递归遍历数组,并将所有元素与遍历到的子数组中的元素合并为一个新数组返回。 console.log(plants);
// expected output: Array ["broccoli", "cauliflower", "cabbage"]
```ts ```
const arr1 = [0, 1, 2, [3, 4]];
console.log(arr1.flat()); <!-- UTSJSON.Array.pop.compatibility -->
// expected output: [0, 1, 2, 3, 4]
const arr2 = [0, 1, 2, [[[3, 4]]]]; ### push(items)
console.log(arr2.flat(2)); <!-- UTSJSON.Array.push.description -->
// expected output: [0, 1, 2, [3, 4]]
```
### forEach <!-- UTSJSON.Array.push.param -->
forEach() 方法对数组的每个元素执行一次给定的函数。 <!-- UTSJSON.Array.push.returValue -->
```ts ```ts
const array1 = ['a', 'b', 'c']; const animals = ['pigs', 'goats', 'sheep'];
array1.forEach(element => console.log(element));
// expected output: "a"
// expected output: "b"
// expected output: "c"
```
### includes const count = animals.push('cows');
console.log(count);
// expected output: 4
console.log(animals);
// expected output: Array ["pigs", "goats", "sheep", "cows"]
includes() 方法用来判断一个数组是否包含一个指定的值,根据情况,如果包含则返回 true,否则返回 false。 animals.push('chickens', 'cats', 'dogs');
console.log(animals);
// expected output: Array ["pigs", "goats", "sheep", "cows", "chickens", "cats", "dogs"]
```ts ```
const array1 = [1, 2, 3];
console.log(array1.includes(2)); <!-- UTSJSON.Array.push.compatibility -->
// expected output: true
const pets = ['cat', 'dog', 'bat']; ### concat(items)
console.log(pets.includes('cat')); <!-- UTSJSON.Array.concat.description -->
// expected output: true
<!-- UTSJSON.Array.concat.param -->
console.log(pets.includes('at')); <!-- UTSJSON.Array.concat.returValue -->
// expected output: false
```ts
const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = array1.concat(array2);
console.log(array3);
// expected output: Array ["a", "b", "c", "d", "e", "f"]
``` ```
### indexOf <!-- UTSJSON.Array.concat.compatibility -->
indexOf() 方法返回在数组中可以找到一个给定元素的第一个索引,如果不存在,则返回-1。 ### concat(items)
```ts <!-- UTSJSON.Array.concat_1.description -->
const beasts = ['ant', 'bison', 'camel', 'duck', 'bison'];
console.log(beasts.indexOf('bison')); <!-- UTSJSON.Array.concat_1.param -->
// expected output: 1
// start from index 2 <!-- UTSJSON.Array.concat_1.returValue -->
console.log(beasts.indexOf('bison', 2));
// expected output: 4
console.log(beasts.indexOf('giraffe')); <!-- UTSJSON.Array.concat_1.compatibility -->
// expected output: -1
``` ### join(separator?)
<!-- UTSJSON.Array.join.description -->
### join <!-- UTSJSON.Array.join.param -->
join() 方法将一个数组的所有元素连接成一个字符串并返回这个字符串。如果数组只有一个项目,那么将返回该项目而不使用分隔符。 <!-- UTSJSON.Array.join.returValue -->
```ts ```ts
const elements = ['Fire', 'Air', 'Water']; const elements = ['Fire', 'Air', 'Water'];
...@@ -205,141 +219,202 @@ console.log(elements.join('-')); ...@@ -205,141 +219,202 @@ console.log(elements.join('-'));
``` ```
### lastIndexOf <!-- UTSJSON.Array.join.compatibility -->
lastIndexOf() 方法返回指定元素在数组中的最后一个的索引,如果不存在则返回 -1。从数组的后面向前查找,从 fromIndex 处开始。 ### reverse()
```ts <!-- UTSJSON.Array.reverse.description -->
const animals = ['Dodo', 'Tiger', 'Penguin', 'Dodo'];
console.log(animals.lastIndexOf('Dodo')); <!-- UTSJSON.Array.reverse.param -->
// expected output: 3
console.log(animals.lastIndexOf('Tiger')); <!-- UTSJSON.Array.reverse.returValue -->
// expected output: 1
``` <!-- UTSJSON.Array.reverse.compatibility -->
### map
### shift()
<!-- UTSJSON.Array.shift.description -->
<!-- UTSJSON.Array.shift.param -->
map() 方法创建一个新数组,这个新数组由原数组中的每个元素都调用一次提供的函数后的返回值组成。 <!-- UTSJSON.Array.shift.returValue -->
```ts ```ts
const array1 = [1, 4, 9, 16]; const array1 = [1, 2, 3];
// pass a function to map const firstElement = array1.shift();
const map1 = array1.map((x:number):number => x * 2);
console.log(map1); console.log(array1);
// expected output: Array [2, 8, 18, 32] // expected output: Array [2, 3]
console.log(firstElement);
// expected output: 1
``` ```
### pop <!-- UTSJSON.Array.shift.compatibility -->
### slice(start?, end?)
<!-- UTSJSON.Array.slice.description -->
<!-- UTSJSON.Array.slice.param -->
pop() 方法从数组中删除最后一个元素,并返回该元素的值。此方法会更改数组的长度。 <!-- UTSJSON.Array.slice.returValue -->
```ts ```ts
const plants = ['broccoli', 'cauliflower', 'cabbage', 'kale', 'tomato']; const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];
console.log(plants.pop()); console.log(animals.slice(2));
// expected output: "tomato" // expected output: Array ["camel", "duck", "elephant"]
console.log(plants); console.log(animals.slice(2, 4));
// expected output: Array ["broccoli", "cauliflower", "cabbage", "kale"] // expected output: Array ["camel", "duck"]
plants.pop(); console.log(animals.slice(1, 5));
// expected output: Array ["bison", "camel", "duck", "elephant"]
console.log(plants); console.log(animals.slice(-2));
// expected output: Array ["broccoli", "cauliflower", "cabbage"] // expected output: Array ["duck", "elephant"]
console.log(animals.slice(2, -1));
// expected output: Array ["camel", "duck"]
console.log(animals.slice());
// expected output: Array ["ant", "bison", "camel", "duck", "elephant"]
``` ```
### push <!-- UTSJSON.Array.slice.compatibility -->
push() 方法将一个或多个元素添加到数组的末尾,并返回该数组的新长度。 ### sort(compareFn?)
```ts <!-- UTSJSON.Array.sort.description -->
const animals = ['pigs', 'goats', 'sheep'];
const count = animals.push('cows'); <!-- UTSJSON.Array.sort.param -->
console.log(count);
// expected output: 4
console.log(animals);
// expected output: Array ["pigs", "goats", "sheep", "cows"]
animals.push('chickens', 'cats', 'dogs'); <!-- UTSJSON.Array.sort.returValue -->
console.log(animals);
// expected output: Array ["pigs", "goats", "sheep", "cows", "chickens", "cats", "dogs"]
```ts
const array2 = [5, 1, 4, 2, 3];
array2.sort((a: number, b: number):number => a - b);
// expect(array2).toEqual([1, 2, 3, 4, 5]);
``` ```
### reduce <!-- UTSJSON.Array.sort.compatibility -->
reduce() 方法对数组中的每个元素按序执行一个由您提供的 reducer 函数,每一次运行 reducer 会将先前元素的计算结果作为参数传入,最后将其结果汇总为单个返回值。 ### splice(start, deleteCount, items)
第一次执行回调函数时,不存在“上一次的计算结果”。如果需要回调函数从数组索引为 0 的元素开始执行,则需要传递初始值。否则,数组索引为 0 的元素将被作为初始值 initialValue,迭代器将从第二个元素开始执行(索引为 1 而不是 0)。 <!-- UTSJSON.Array.splice.description -->
```ts <!-- UTSJSON.Array.splice.param -->
const array1 = [1, 2, 3, 4];
// 0 + 1 + 2 + 3 + 4 <!-- UTSJSON.Array.splice.returValue -->
const initialValue = 0;
const sumWithInitial = array1.reduce(
(previousValue:number, currentValue:number):number => previousValue + currentValue,
initialValue
);
console.log(sumWithInitial); ```ts
// expected output: 10 const months = ['Jan', 'March', 'April', 'June'];
months.splice(1, 0, 'Feb');
// inserts at index 1
console.log(months);
// expected output: Array ["Jan", "Feb", "March", "April", "June"]
months.splice(4, 1, 'May');
// replaces 1 element at index 4
console.log(months);
// expected output: Array ["Jan", "Feb", "March", "April", "May"]
``` ```
### shift <!-- UTSJSON.Array.splice.compatibility -->
shift() 方法从数组中删除第一个元素,并返回该元素的值。此方法更改数组的长度。 ### unshift(items)
<!-- UTSJSON.Array.unshift.description -->
<!-- UTSJSON.Array.unshift.param -->
<!-- UTSJSON.Array.unshift.returValue -->
```ts ```ts
const array1 = [1, 2, 3]; const array1 = [1, 2, 3];
const firstElement = array1.shift(); console.log(array1.unshift(4, 5));
// expected output: 5
console.log(array1); console.log(array1);
// expected output: Array [2, 3] // expected output: Array [4, 5, 1, 2, 3]
```
console.log(firstElement); <!-- UTSJSON.Array.unshift.compatibility -->
### indexOf(searchElement, fromIndex?)
<!-- UTSJSON.Array.indexOf.description -->
<!-- UTSJSON.Array.indexOf.param -->
<!-- UTSJSON.Array.indexOf.returValue -->
```ts
const beasts = ['ant', 'bison', 'camel', 'duck', 'bison'];
console.log(beasts.indexOf('bison'));
// expected output: 1 // expected output: 1
// start from index 2
console.log(beasts.indexOf('bison', 2));
// expected output: 4
console.log(beasts.indexOf('giraffe'));
// expected output: -1
``` ```
### slice <!-- UTSJSON.Array.indexOf.compatibility -->
slice() 方法返回一个新的数组对象,这一对象是一个由 begin 和 end 决定的原数组的浅拷贝(包括 begin,不包括end)。原始数组不会被改变。 ### lastIndexOf(searchElement, fromIndex?)
<!-- UTSJSON.Array.lastIndexOf.description -->
<!-- UTSJSON.Array.lastIndexOf.param -->
<!-- UTSJSON.Array.lastIndexOf.returValue -->
```ts ```ts
const animals = ['ant', 'bison', 'camel', 'duck', 'elephant']; const animals = ['Dodo', 'Tiger', 'Penguin', 'Dodo'];
console.log(animals.slice(2)); console.log(animals.lastIndexOf('Dodo'));
// expected output: Array ["camel", "duck", "elephant"] // expected output: 3
console.log(animals.slice(2, 4)); console.log(animals.lastIndexOf('Tiger'));
// expected output: Array ["camel", "duck"] // expected output: 1
```
console.log(animals.slice(1, 5)); <!-- UTSJSON.Array.lastIndexOf.compatibility -->
// expected output: Array ["bison", "camel", "duck", "elephant"]
console.log(animals.slice(-2)); ### every(predicate, thisArg?)
// expected output: Array ["duck", "elephant"]
console.log(animals.slice(2, -1)); <!-- UTSJSON.Array.every.description -->
// expected output: Array ["camel", "duck"]
console.log(animals.slice()); <!-- UTSJSON.Array.every.param -->
// expected output: Array ["ant", "bison", "camel", "duck", "elephant"]
<!-- UTSJSON.Array.every.returValue -->
```ts
const isBelowThreshold = (currentValue:number):boolean => currentValue < 40;
const array1 = [1, 30, 39, 29, 10, 13];
console.log(array1.every(isBelowThreshold));
// expected output: true
``` ```
### some <!-- UTSJSON.Array.every.compatibility -->
### some(predicate, thisArg?)
<!-- UTSJSON.Array.some.description -->
<!-- UTSJSON.Array.some.param -->
<!-- UTSJSON.Array.some.returValue -->
some() 方法测试数组中是不是至少有 1 个元素通过了被提供的函数测试。它返回的是一个 Boolean 类型的值。
```ts ```ts
const array = [1, 2, 3, 4, 5]; const array = [1, 2, 3, 4, 5];
...@@ -351,54 +426,103 @@ console.log(array.some(even)); ...@@ -351,54 +426,103 @@ console.log(array.some(even));
// expected output: true // expected output: true
``` ```
### sort <!-- UTSJSON.Array.some.compatibility -->
### forEach(callbackfn, thisArg?)
sort() 方法对数组的元素进行排序,并返回数组。 <!-- UTSJSON.Array.forEach.description -->
**平台差异说明** <!-- UTSJSON.Array.forEach.param -->
|JavaScript|Kotlin|Swift| <!-- UTSJSON.Array.forEach.returValue -->
|:-:|:-:|:-:|
|√|√|x|
```ts ```ts
const array2 = [5, 1, 4, 2, 3]; const array1 = ['a', 'b', 'c'];
array2.sort((a: number, b: number):number => a - b); array1.forEach(element => console.log(element));
// expect(array2).toEqual([1, 2, 3, 4, 5]); // expected output: "a"
// expected output: "b"
// expected output: "c"
``` ```
### splice <!-- UTSJSON.Array.forEach.compatibility -->
### map(callbackfn, thisArg?)
<!-- UTSJSON.Array.map.description -->
splice() 方法通过删除或替换现有元素或者原地添加新的元素来修改数组,并以数组形式返回被修改的内容。此方法会改变原数组。 <!-- UTSJSON.Array.map.param -->
<!-- UTSJSON.Array.map.returValue -->
```ts ```ts
const months = ['Jan', 'March', 'April', 'June']; const array1 = [1, 4, 9, 16];
months.splice(1, 0, 'Feb');
// inserts at index 1 // pass a function to map
console.log(months); const map1 = array1.map((x:number):number => x * 2);
// expected output: Array ["Jan", "Feb", "March", "April", "June"]
console.log(map1);
// expected output: Array [2, 8, 18, 32]
months.splice(4, 1, 'May');
// replaces 1 element at index 4
console.log(months);
// expected output: Array ["Jan", "Feb", "March", "April", "May"]
``` ```
### unshift <!-- UTSJSON.Array.map.compatibility -->
unshift() 方法将一个或多个元素添加到数组的开头,并返回该数组的新长度(该方法修改原有数组)。 ### filter(predicate, thisArg?)
<!-- UTSJSON.Array.filter.description -->
<!-- UTSJSON.Array.filter.param -->
<!-- UTSJSON.Array.filter.returValue -->
```ts ```ts
const array1 = [1, 2, 3]; const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
console.log(array1.unshift(4, 5)); const result = words.filter((word:string):boolean => word.length > 6);
// expected output: 5
console.log(result);
// expected output: Array ["exuberant", "destruction", "present"]
```
<!-- UTSJSON.Array.filter.compatibility -->
### reduce(callbackfn)
<!-- UTSJSON.Array.reduce.description -->
<!-- UTSJSON.Array.reduce.param -->
<!-- UTSJSON.Array.reduce.returValue -->
```ts
const array1 = [1, 2, 3, 4];
// 0 + 1 + 2 + 3 + 4
const initialValue = 0;
const sumWithInitial = array1.reduce(
(previousValue:number, currentValue:number):number => previousValue + currentValue,
initialValue
);
console.log(sumWithInitial);
// expected output: 10
console.log(array1);
// expected output: Array [4, 5, 1, 2, 3]
``` ```
### 常见操作 <!-- UTSJSON.Array.reduce.compatibility -->
### reduceRight(callbackfn)
<!-- UTSJSON.Array.reduceRight.description -->
<!-- UTSJSON.Array.reduceRight.param -->
<!-- UTSJSON.Array.reduceRight.returValue -->
<!-- UTSJSON.Array.reduceRight.compatibility -->
## 常见操作
- 创建数组 - 创建数组
```ts ```ts
...@@ -483,4 +607,3 @@ const shallowCopy = fruits.slice() // this is how to make a copy ...@@ -483,4 +607,3 @@ const shallowCopy = fruits.slice() // this is how to make a copy
```ts ```ts
console.log(arr.0) // a syntax error console.log(arr.0) // a syntax error
``` ```
## Date # Date
创建一个 Date 实例,该实例呈现时间中的某个时刻。Date 对象则基于 Unix Time Stamp,即自 1970 年 1 月 1 日(UTC)起经过的毫秒数。 创建一个 Date 实例,该实例呈现时间中的某个时刻。Date 对象则基于 Unix Time Stamp,即自 1970 年 1 月 1 日(UTC)起经过的毫秒数。
### 语法 ## 语法
```ts ```ts
new Date(); new Date();
...@@ -13,8 +13,8 @@ new Date(year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds] ...@@ -13,8 +13,8 @@ new Date(year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds]
- 如果没有输入任何参数,则 Date 的构造器会依据系统设置的当前时间来创建一个 Date 对象。 - 如果没有输入任何参数,则 Date 的构造器会依据系统设置的当前时间来创建一个 Date 对象。
- 如果提供了至少两个参数,其余的参数均会默认设置为 1(如果没有指定 day 参数)或者 0(如果没有指定 day 以外的参数)。 - 如果提供了至少两个参数,其余的参数均会默认设置为 1(如果没有指定 day 参数)或者 0(如果没有指定 day 以外的参数)。
- uts 的时间由世界标准时间(UTC)1970 年 1 月 1 日开始,用毫秒计时,一天由 86,400,000 毫秒组成。Date 对象的范围是 -100,000,000 天至 100,000,000 天(等效的毫秒值)。 - uts 的时间由世界标准时间(UTC)1970 年 1 月 1 日开始,用毫秒计时,一天由 86,400,000 毫秒组成。Date 对象的范围是 -100,000,000 天至 100,000,000 天(等效的毫秒值)。
-
### 静态方法 ## 静态方法
### now ### now
表示自 UNIX 纪元开始(1970 年 1 月 1 日 00:00:00 (UTC))到当前时间的毫秒数。 表示自 UNIX 纪元开始(1970 年 1 月 1 日 00:00:00 (UTC))到当前时间的毫秒数。
...@@ -37,138 +37,185 @@ setTimeout(() => { ...@@ -37,138 +37,185 @@ setTimeout(() => {
}, 2000) }, 2000)
``` ```
### 实例方法 ## 实例方法
### getDate
根据本地时间,返回一个指定的日期对象为一个月中的哪一日(从 1--31)。 ### toString()
**平台差异说明** <!-- UTSJSON.Date.toString.description -->
|JavaScript|Kotlin|Swift| <!-- UTSJSON.Date.toString.param -->
|:-:|:-:|:-:|
|√|√|√ `(3.6.11+)`|
### getDay <!-- UTSJSON.Date.toString.returValue -->
根据本地时间,返回一个具体日期中一周的第几天,0 表示星期天。对于某个月中的第几天 <!-- UTSJSON.Date.toString.compatibility -->
**平台差异说明** ### toDateString()
|JavaScript|Kotlin|Swift| <!-- UTSJSON.Date.toDateString.description -->
|:-:|:-:|:-:|
|√|√|√ `(3.6.11+)`|
### getFullYear <!-- UTSJSON.Date.toDateString.param -->
根据本地时间返回指定日期的年份。 <!-- UTSJSON.Date.toDateString.returValue -->
### getHours <!-- UTSJSON.Date.toDateString.compatibility -->
根据本地时间,返回一个指定的日期对象的小时。 ### getTime()
**平台差异说明** <!-- UTSJSON.Date.getTime.description -->
|JavaScript|Kotlin|Swift| <!-- UTSJSON.Date.getTime.param -->
|:-:|:-:|:-:|
|√|√|√ `(3.6.11+)`|
### getMilliseconds <!-- UTSJSON.Date.getTime.returValue -->
根据本地时间,返回一个指定的日期对象的毫秒数。 <!-- UTSJSON.Date.getTime.compatibility -->
**平台差异说明** ### getFullYear()
|JavaScript|Kotlin|Swift| <!-- UTSJSON.Date.getFullYear.description -->
|:-:|:-:|:-:|
|√|√|√ `(3.6.11+)`|
### getMinutes <!-- UTSJSON.Date.getFullYear.param -->
根据本地时间,返回一个指定的日期对象的分钟数。 <!-- UTSJSON.Date.getFullYear.returValue -->
**平台差异说明** <!-- UTSJSON.Date.getFullYear.compatibility -->
|JavaScript|Kotlin|Swift| ### getMonth()
|:-:|:-:|:-:|
|√|√|√ `(3.6.11+)`|
### getMonth <!-- UTSJSON.Date.getMonth.description -->
指定的日期对象的月份,为基于 0 的值(0 表示一年中的第一月)。 <!-- UTSJSON.Date.getMonth.param -->
**平台差异说明** <!-- UTSJSON.Date.getMonth.returValue -->
|JavaScript|Kotlin|Swift| <!-- UTSJSON.Date.getMonth.compatibility -->
|:-:|:-:|:-:|
|√|√|√ `(3.6.11+)`|
### getSeconds ### getDate()
根据本地时间,返回一个指定的日期对象的秒数。 <!-- UTSJSON.Date.getDate.description -->
**平台差异说明** <!-- UTSJSON.Date.getDate.param -->
|JavaScript|Kotlin|Swift| <!-- UTSJSON.Date.getDate.returValue -->
|:-:|:-:|:-:|
|√|√|√ `(3.6.11+)`|
### getTime <!-- UTSJSON.Date.getDate.compatibility -->
返回一个时间的格林威治时间数值。 ### getDay()
**平台差异说明** <!-- UTSJSON.Date.getDay.description -->
|JavaScript|Kotlin|Swift| <!-- UTSJSON.Date.getDay.param -->
|:-:|:-:|:-:|
|√|√|√ `(3.6.11+)`|
### setDate <!-- UTSJSON.Date.getDay.returValue -->
根据本地时间来指定一个日期对象的天数。 <!-- UTSJSON.Date.getDay.compatibility -->
**平台差异说明** ### getHours()
|JavaScript|Kotlin|Swift| <!-- UTSJSON.Date.getHours.description -->
|:-:|:-:|:-:|
|√|√|√ `(3.6.11+)`|
### setFullYear <!-- UTSJSON.Date.getHours.param -->
根据本地时间为一个日期对象设置年份。 <!-- UTSJSON.Date.getHours.returValue -->
**平台差异说明** <!-- UTSJSON.Date.getHours.compatibility -->
|JavaScript|Kotlin|Swift| ### getMinutes()
|:-:|:-:|:-:|
|√|√|√ `(3.6.11+)`|
### setHours <!-- UTSJSON.Date.getMinutes.description -->
根据本地时间为一个日期对象设置小时数,返回从 1970-01-01 00:00:00 UTC 到更新后的 日期 对象实例所表示时间的毫秒数。 <!-- UTSJSON.Date.getMinutes.param -->
### setMilliseconds <!-- UTSJSON.Date.getMinutes.returValue -->
根据本地时间设置一个日期对象的豪秒数。 <!-- UTSJSON.Date.getMinutes.compatibility -->
### setMinutes ### getSeconds()
根据本地时间为一个日期对象设置分钟数。 <!-- UTSJSON.Date.getSeconds.description -->
### setMonth <!-- UTSJSON.Date.getSeconds.param -->
根据本地时间为一个日期对象设置月份。 <!-- UTSJSON.Date.getSeconds.returValue -->
### setSeconds <!-- UTSJSON.Date.getSeconds.compatibility -->
根据本地时间设置一个日期对象的秒数。 ### setTime(time)
### setTime <!-- UTSJSON.Date.setTime.description -->
以一个表示从 1970-1-1 00:00:00 UTC 计时的毫秒数为来为 Date 对象设置时间。 <!-- UTSJSON.Date.setTime.param -->
**平台差异说明** <!-- UTSJSON.Date.setTime.returValue -->
|JavaScript|Kotlin|Swift| <!-- UTSJSON.Date.setTime.compatibility -->
|:-:|:-:|:-:|
|√|√|√ `(3.6.11+)`| ### setMilliseconds(ms)
<!-- UTSJSON.Date.setMilliseconds.description -->
<!-- UTSJSON.Date.setMilliseconds.param -->
<!-- UTSJSON.Date.setMilliseconds.returValue -->
<!-- UTSJSON.Date.setMilliseconds.compatibility -->
### setSeconds(sec, ms?)
<!-- UTSJSON.Date.setSeconds.description -->
<!-- UTSJSON.Date.setSeconds.param -->
<!-- UTSJSON.Date.setSeconds.returValue -->
<!-- UTSJSON.Date.setSeconds.compatibility -->
### setMinutes(min, sec?, ms?)
<!-- UTSJSON.Date.setMinutes.description -->
<!-- UTSJSON.Date.setMinutes.param -->
<!-- UTSJSON.Date.setMinutes.returValue -->
<!-- UTSJSON.Date.setMinutes.compatibility -->
### setHours(hours, min?, sec?, ms?)
<!-- UTSJSON.Date.setHours.description -->
<!-- UTSJSON.Date.setHours.param -->
<!-- UTSJSON.Date.setHours.returValue -->
<!-- UTSJSON.Date.setHours.compatibility -->
### setDate(date)
<!-- UTSJSON.Date.setDate.description -->
<!-- UTSJSON.Date.setDate.param -->
<!-- UTSJSON.Date.setDate.returValue -->
<!-- UTSJSON.Date.setDate.compatibility -->
### setMonth(month, date?)
<!-- UTSJSON.Date.setMonth.description -->
<!-- UTSJSON.Date.setMonth.param -->
<!-- UTSJSON.Date.setMonth.returValue -->
<!-- UTSJSON.Date.setMonth.compatibility -->
### setFullYear(year, month?, date?)
<!-- UTSJSON.Date.setFullYear.description -->
<!-- UTSJSON.Date.setFullYear.param -->
<!-- UTSJSON.Date.setFullYear.returValue -->
<!-- UTSJSON.Date.setFullYear.compatibility -->
\ No newline at end of file
## 全局函数 # Global
### setTimeout
设定一个定时器。在定时到期以后执行注册的回调函数 ## 实例方法
```ts
setTimeout(() => {
console.log("Delayed for 1 second.") ### parseInt(string, radix?)
}, 1000)
``` <!-- UTSJSON.Global.parseInt.description -->
### clearTimeout
取消由 setTimeout 设置的定时器。 <!-- UTSJSON.Global.parseInt.param -->
```ts
const timer = setTimeout(() => { <!-- UTSJSON.Global.parseInt.returValue -->
console.log("Delayed for 1 second.")
}, 1000) <!-- UTSJSON.Global.parseInt.compatibility -->
clearTimeout(timer)
``` ### parseFloat(string)
### setInterval
设定一个定时器。按照指定的周期(以毫秒计)来执行注册的回调函数 <!-- UTSJSON.Global.parseFloat.description -->
```ts
setInterval(() => { <!-- UTSJSON.Global.parseFloat.param -->
console.log(Date.now())
}, 1000) <!-- UTSJSON.Global.parseFloat.returValue -->
```
### clearInterval <!-- UTSJSON.Global.parseFloat.compatibility -->
取消由 setInterval 设置的定时器。 \ No newline at end of file
```ts
const timer = setInterval(() => {
console.log(Date.now())
}, 1000)
clearInterval(timer)
```
注意:暂不支持在变量没有定义完成(赋值的过程中)就访问。比如:需要在setInterval内执行clearInterval。
例如:
```ts
let index = 0;
let interval : number = setInterval(() => {
index ++
if (index > 3) {
clearInterval(interval)
}
}, 6)
```
暂时需要使用如下写法(后续会优化抹平):
```ts
let index = 0;
let interval : number = 0;
interval = setInterval(() => {
index ++
if (index > 3) {
clearInterval(interval)
}
}, 6)
```
## JSON # JSON
### 静态方法 ## 静态方法
### parse ### parse
...@@ -22,14 +22,18 @@ console.log(obj["result"]); ...@@ -22,14 +22,18 @@ console.log(obj["result"]);
- JSON.parse 解析出来的对象,目前仅支持使用方括号[]访问 - JSON.parse 解析出来的对象,目前仅支持使用方括号[]访问
- 如果输入的字符串不是合法的json格式,则会返回 null - 如果输入的字符串不是合法的json格式,则会返回 null
### 带泛型的 parse ## 实例方法
带泛型的 JSON.parse<T>() 是JSON.parse() 的加强版实现,它可以返回一个指定类型的结构化数据,在很多场景下它非常有用。
先看看他的用法 ### parse(text, reviver?)
```uts <!-- UTSJSON.JSON.parse.description -->
<!-- UTSJSON.JSON.parse.param -->
<!-- UTSJSON.JSON.parse.returValue -->
```ts
class Persion { class Persion {
var name ="" var name =""
var age = 0 var age = 0
...@@ -39,13 +43,13 @@ class Persion { ...@@ -39,13 +43,13 @@ class Persion {
let personObj = JSON.parse<Persion>('{"name":"zhangsan","age":12}') let personObj = JSON.parse<Persion>('{"name":"zhangsan","age":12}')
// 不带泛型的parse,这里的jsonObj类型是通用的`UTSJSONObject` // 不带泛型的parse,这里的jsonObj类型是通用的`UTSJSONObject`
let jsonObj = JSON.parse('{"name":"zhangsan","age":12}') let jsonObj = JSON.parse('{"name":"zhangsan","age":12}')
``` ```
与不带泛型的JSON.parse 相比,多了一个`<Persion>` 尖括号 用来指定返回类型。 与不带泛型的JSON.parse 相比,多了一个`<Persion>` 尖括号 用来指定返回类型。
在这个示例中,看上去好像也不是很有用。太简单了。我们可以扩展一下 在这个示例中,看上去好像也不是很有用。太简单了。我们可以扩展一下
``` ```ts
let userArrayArray = JSON.parse<Array<Persion>>('[{"name":"zhangsan","age":12},{"name":"lisi","age":13}]') let userArrayArray = JSON.parse<Array<Persion>>('[{"name":"zhangsan","age":12},{"name":"lisi","age":13}]')
``` ```
...@@ -54,10 +58,15 @@ let userArrayArray = JSON.parse<Array<Persion>>('[{"name":"zhangsan","age":12},{ ...@@ -54,10 +58,15 @@ let userArrayArray = JSON.parse<Array<Persion>>('[{"name":"zhangsan","age":12},{
总结:带泛型的 `parse`函数,会提高我们反序列数据的开发效率,明确的结构数据可以提升工程健壮度,推荐使用 总结:带泛型的 `parse`函数,会提高我们反序列数据的开发效率,明确的结构数据可以提升工程健壮度,推荐使用
<!-- UTSJSON.JSON.parse.compatibility -->
### stringify(value, replacer?, space?)
<!-- UTSJSON.JSON.stringify.description -->
### stringify <!-- UTSJSON.JSON.stringify.param -->
JSON.stringify() 方法将一个 uts 对象或值转换为 JSON 字符串 <!-- UTSJSON.JSON.stringify.returValue -->
```ts ```ts
console.log(JSON.stringify({ x: 5, y: 6 })); console.log(JSON.stringify({ x: 5, y: 6 }));
...@@ -70,3 +79,15 @@ console.log(JSON.stringify(new Date(2006, 0, 2, 15, 4, 5))); ...@@ -70,3 +79,15 @@ console.log(JSON.stringify(new Date(2006, 0, 2, 15, 4, 5)));
// expected output: ""2006-01-02T15:04:05.000Z"" // expected output: ""2006-01-02T15:04:05.000Z""
``` ```
<!-- UTSJSON.JSON.stringify.compatibility -->
### stringify(value, replacer?, space?)
<!-- UTSJSON.JSON.stringify_1.description -->
<!-- UTSJSON.JSON.stringify_1.param -->
<!-- UTSJSON.JSON.stringify_1.returValue -->
<!-- UTSJSON.JSON.stringify_1.compatibility -->
\ No newline at end of file
## Map # Map
Map 对象保存键值对。任何值(对象或者基本类型)都可以作为一个键或一个值。 Map 对象保存键值对。任何值(对象或者基本类型)都可以作为一个键或一个值。
### 实例属性 ## 实例属性
### size ### size
返回 Map 对象的成员数量。 <!-- UTSJSON.Map.size.description -->
<!-- UTSJSON.Map.size.param -->
<!-- UTSJSON.Map.size.returValue -->
```ts ```ts
const map1 = new Map<string,string>(); const map1 = new Map<string,string>();
...@@ -18,11 +23,19 @@ console.log(map1.size); ...@@ -18,11 +23,19 @@ console.log(map1.size);
``` ```
### 实例方法 <!-- UTSJSON.Map.size.compatibility -->
## 实例方法
### clear()
### clear <!-- UTSJSON.Map.clear.description -->
移除 Map 对象中的所有元素。 <!-- UTSJSON.Map.clear.param -->
<!-- UTSJSON.Map.clear.returValue -->
```ts ```ts
const map1 = new Map<string,string>(); const map1 = new Map<string,string>();
...@@ -35,9 +48,15 @@ console.log(map1.size); ...@@ -35,9 +48,15 @@ console.log(map1.size);
// expected output: 0 // expected output: 0
``` ```
#### delete <!-- UTSJSON.Map.clear.compatibility -->
### delete(key)
<!-- UTSJSON.Map.delete.description -->
用于移除 Map 对象中指定的元素。 <!-- UTSJSON.Map.delete.param -->
<!-- UTSJSON.Map.delete.returValue -->
```ts ```ts
const map1 = new Map<string,string>(); const map1 = new Map<string,string>();
...@@ -49,9 +68,25 @@ console.log(map1.has('bar')); ...@@ -49,9 +68,25 @@ console.log(map1.has('bar'));
// expected result: false // expected result: false
``` ```
### get <!-- UTSJSON.Map.delete.compatibility -->
### forEach(callbackfn, thisArg?)
<!-- UTSJSON.Map.forEach.description -->
返回某个 Map 对象中的一个指定元素。 <!-- UTSJSON.Map.forEach.param -->
<!-- UTSJSON.Map.forEach.returValue -->
<!-- UTSJSON.Map.forEach.compatibility -->
### get(key)
<!-- UTSJSON.Map.get.description -->
<!-- UTSJSON.Map.get.param -->
<!-- UTSJSON.Map.get.returValue -->
```ts ```ts
const map1 = new Map<string,string>(); const map1 = new Map<string,string>();
...@@ -61,9 +96,15 @@ console.log(map1.get('bar')); ...@@ -61,9 +96,15 @@ console.log(map1.get('bar'));
// expected output: "foo" // expected output: "foo"
``` ```
### has <!-- UTSJSON.Map.get.compatibility -->
### has(key)
返回一个布尔值,用来表明 Map 中是否存在指定元素。 <!-- UTSJSON.Map.has.description -->
<!-- UTSJSON.Map.has.param -->
<!-- UTSJSON.Map.has.returValue -->
```ts ```ts
const map1 = new Map<string,string>(); const map1 = new Map<string,string>();
...@@ -76,9 +117,15 @@ console.log(map1.has('baz')); ...@@ -76,9 +117,15 @@ console.log(map1.has('baz'));
// expected output: false // expected output: false
``` ```
### set <!-- UTSJSON.Map.has.compatibility -->
### set(key, value)
添加或更新一个指定了键(key)和值(value)的(新)键值对。 <!-- UTSJSON.Map.set.description -->
<!-- UTSJSON.Map.set.param -->
<!-- UTSJSON.Map.set.returValue -->
```ts ```ts
const map1 = new Map<string,string>(); const map1 = new Map<string,string>();
...@@ -91,7 +138,9 @@ console.log(map1.get('baz')); ...@@ -91,7 +138,9 @@ console.log(map1.get('baz'));
// expected output: null // expected output: null
``` ```
### 常见操作 <!-- UTSJSON.Map.set.compatibility -->
## 常见操作
- 创建map - 创建map
```ts ```ts
......
此差异已折叠。
## Number # Number
Number 对象是经过封装的能让你处理数字值的对象。 Number 对象是经过封装的能让你处理数字值的对象。
### 实例方法 ## 实例方法
### toFixed
toFixed() 方法使用定点表示法来格式化一个数值。 ### toFixed(fractionDigits?)
**平台差异说明** <!-- UTSJSON.Number.toFixed.description -->
|JavaScript|Kotlin|Swift| <!-- UTSJSON.Number.toFixed.param -->
|:-:|:-:|:-:|
|√|√|√ `(3.6.11+)`| <!-- UTSJSON.Number.toFixed.returValue -->
```ts ```ts
function financial(x: Number): String { function financial(x: Number): String {
...@@ -24,6 +24,8 @@ console.log(financial(0.004)); ...@@ -24,6 +24,8 @@ console.log(financial(0.004));
// expected output: "0.00" // expected output: "0.00"
``` ```
<!-- UTSJSON.Number.toFixed.compatibility -->
### toByte() ### toByte()
toByte() 方法将当前的Number数据转换为Byte表示,如果超出Byte最大值表示范围,会得到溢出后余数表示 toByte() 方法将当前的Number数据转换为Byte表示,如果超出Byte最大值表示范围,会得到溢出后余数表示
...@@ -76,6 +78,3 @@ let a = 12 ...@@ -76,6 +78,3 @@ let a = 12
console.log(a.toLong()); console.log(a.toLong());
// expected output: 12 // expected output: 12
``` ```
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册