npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@yolanda-qn/four-electrodes-report-lib

v1.4.3

Published

四电极报告

Downloads

5

Readme

四电极指标报告库

点击查看Demo

Usage

|名称|类型|必须|默认值|说明| |:--|:--|:--:|:--|:--| |measureData|measureData|Y||测量数据| |config|config|N|| |callback|(err: null Error, reportItems: ReportItem[]) => void|N||回调函数|

注意:在微信小程序中使用需要将 https://third-api.yolanda.hk 添加到地址白名单中,并且将runEnv指定为wx_miniprogram

示例:

在模块中

// 引入iconfont图标,如果需要展示图标。注意只能使用 svg 方式引入
import '@yolanda-qn/four-electrodes-report-lib/icons';
import getReports from '@yolanda-qn/four-electrodes-report-lib';
// 引入所有语言
import locales from '@yolanda-qn/four-electrodes-report-lib/dist/locales';

// 设置所有语言。默认只有简体中文和英语
getReports.i18n.setLangPack(locales);
// 设置回退语言
getReports.i18n.setFallbackLang('en');

 // 测量的数据
cosnt measureData = {"gender":1,"birthday":"1994-08-08","height":"168","weight":"65.6","bmi":"23.2","bodyfat":"16.8","subfat":"14.9","visfat":"6","water":"60.1","bmr":"1549","body_age":"27","muscle":"47.4","bone":"2.7","sinew":"51.9","protein":"19","lbm":"54.6","body_shape":"4","heart_index":"3","heart_rate":"83","score":"94.4"};
const config = {
	// sdk的appid
	appId: '',
	// 如果需要根据设备型号过滤指标
	modelId: '',
	weightUnit : 'kg', // 重量单位
	lang : 'zh_CN', // 当前系统语言
	// 在微信小程序中 请指定为 wx_miniprogram
	runEnv: 'browser',
};

// 这里拿到的是原始的报告项数据,尚未进行重量单位转换
getReports(
	measureData, 
	config,
	// 使用函数回调的形式。promise方式和函数回调使用其中一种就可以了
	(err, reportItems) => {
		if (err) {
			console.error(err);
			throw err;
		}
		console.log(reportItems);
	},
).then((reportItems) => {
	// 这里的数据进行了单位转换。不做额外处理的话直接展示数据即可
	const reportObjects = reportItems.map((r) => r.toObject());
});

在浏览器中

<!-- 引入iconfont图标,如果需要展示图标。注意只能使用 svg 方式引入 -->
<script src="./dist/icons.js"></script>
<script src="./dist/index.umd.js"></script>
<!-- 引入所有语言 -->
<script src="./dist/locales/index.umd.js"></script>
<script>
	// 设置完整的语言包,默认只包含简体中文和英语
  window.QN_globalGetFourElectrodesReports.default.i18n.setLangPack(window.QN_globalFourElectrodesLocales);
	
	// 获取报告数据
	window.QN_globalGetFourElectrodesReports.default(measureData, config)
	.then((reportItems) => {
		console.log(reportItems);
	});
</script>

预览测试

yarn preview

exports

// export { default as Big } from 'big.js';
export { default as ReportBuilder } from './ReportBuilder';
export { default as ReportItem } from './ReportItem';
export { default as builders } from './builders';
export { default as version } from './version';
export * as consts from './consts';
export * as util from './util';
export { default as createI18n } from './i18n/createI18n';

export { default } from './main';

measureData

|名称|类型|必须|说明|单位| |:--|:--|:--:|:--|:--| |gender |1和0 |Y|性别。1:男性,0:女性|| |birthday |string |Y|生日。例如:1994-06-17|| |local_updated_at|string|Y|测量时间|| |height |number |Y|身体高度|cm| |weight |number |Y|体重|kg| |bmi |number |N|BMI|kg/m²| |bodyfat |number |N|体脂率|%| |subfat |number |N|皮下脂肪率|%| |visfat |number |N|内脏脂肪等级|| |water |number |N|体水分|%| |bmr |number |N|基础代谢量|kcal| |body_age |number |N|体年龄。别名:bodyAge|岁| |muscle |number |N|骨骼肌率|%| |bone|number |N|骨量(又称无机盐)|kg| |sinew |number |N|肌肉量。别名:muscleMass|kg| |protein |number |N|蛋白质|%| |lbm|number|N|去脂体重|kg| |body_shape|number|N|体型。别名:bodyShape|| |heart_index|number|N|心脏等级。别名:heartIndex|| |heart_rate|number|N|心率。别名:heartRate|次/分钟| |score|number|N|健康评分||

注意:测量记录一定要保存用户当时测量的用户信息数据,历史数据的指标展示不能根据现在的用户信息去计算

config

|名称|类型|必须|默认值|说明| |:--|:--|:--:|:--|:--| |appId|string|Y||sdk配置所需的appid| |modelId|string|N||设备内部型号Id| |refreshSdkConfig|boolean|N|false|是否刷新sdk配置。默认缓存sdk配置| |builderIds|Array<ReportBuilderIdsEnum>|N|全部|指定报告项| |weightUnit|WeightUnitEnum|N|kg|重量单位| |levelColors|Record<LevelColors, string>|N||自定义标准颜色| |lang|LangsEnum|N|zh_CN|语言| |fallbackLang|LangsEnum|N|en|回退语言| |runEnv|browser:浏览器环境;wx_miniprogram: 微信小程序环境;|N|browser|运行环境,默认浏览器环境。涉及到获取sdk配置的请求方式|

ReportBuilderIdsEnum

|名称|值|单位|说明| |:--|:--|:--|:-| |Weight|Weight|WeightUnitTextEnum|体重| |WeightControl|WeightControl|WeightUnitTextEnum|体重控制| |BMR|BMR|kcal|基础代谢量| |BestVisualWeight|BestVisualWeight|WeightUnitTextEnum|理想视觉体重| |Bodyfat|Bodyfat|%|体脂率| |BodyfatMass|BodyfatMass|WeightUnitTextEnum|脂肪量| |BMI|BMI|kg/m²|| |BodyAge|BodyAge|岁|体年龄| |BodyShape|BodyShape||体型| |Bone|Bone|WeightUnitTextEnum|骨量/无机盐 |FatControl|FatControl|WeightUnitTextEnum|脂肪控制| |HeartIndex|HeartIndex|L/min/m^2|心脏指数| |HeartRate|HeartRate|bpm|心率| |LBM|LBM|WeightUnitTextEnum|去脂体重| |MineralSalt|MineralSalt||无机盐状况| |Muscle|Muscle|%|骨骼肌率| |SinewControl|SinewControl|WeightUnitTextEnum|肌肉控制| |Sinew|Sinew|WeightUnitTextEnum|肌肉量| |SinewRate|SinewRate|%|肌肉率| |Obesity|Obesity|%|肥胖度| |Protein|Protein|%|蛋白质| |ProteinMass|ProteinMass|WeightUnitTextEnum|蛋白质量 |Score|Score||健康评分| |StandardWeight|StandardWeight|WeightUnitTextEnum|标准体重| |Subfat|Subfat|%|皮下脂肪率| |Visfat|Visfat||内脏脂肪等级| |Water|Water|%|体水分| |WaterMass|WaterMass|WeightUnitTextEnum|体水量| |FattyLiver|FattyLiver||脂肪肝风险等级|

WeightUnitEnum

重量单位枚举

|名称|值|说明| |:--|:--|:--| |kg|kg|| |lb|lb|| |st|st|外版新增st_only标识| |st_lb|st_lb|对应 海外版st标识| |jin|jin|斤|

WeightUnitTextEnum

重量单位展示文字

|名称|值|说明| |:--|:--|:--| |kg|kg|| |lb|lb|| |st|st|外版新增st_only标识| |st_lb|st:lb|对应 海外版st标识。可能的展示方式为 10st:3lb| |jin|斤||

LevelColors

默认的等级颜色

|名称|值|说明| |:--|:--|:--| |ColorLowest|#AA8EE4|严重偏低| |ColorLower|#00C1E4|偏低| |ColorStandard|#A7CB40|标准| |ColorHigher|#FBC13D|偏高| |ColorHighest|#F74142|严重偏高| |ColorSufficient|#3EA42C|充足/优秀| |ColorHigh01|#FF8C00|轻度肥胖| |ColorHigh02|#F54531|严重肥胖|

LangsEnum

语种枚举。建议只使用英语中文

|名称|值|说明| |:--|:--|:--| |zh_CN|zh_CN|简体中文| |en|en|英语| |zh_TW|zh_TW|繁体中文| |ko|ko|韩语| |jp|jp|日语| |de|de|德语| |fa|fa|法语| |rus|rus|俄语| |es|es|西班牙语| |pt|pt|葡萄牙语| |ar|ar|阿拉伯语| |csy|csy|捷克语| |it|it|意大利语| |tr|tr|土耳其语| |ro|ro|罗马尼亚语| |hu|hu|匈牙利语| |pl|pl|波兰语| |sk|sk|斯洛伐克语| |th|th|泰语| |nl|nl|荷兰语|

ReportItem

id

  • type: string
  • desc: 指标id。

nameI18nKey

  • type: string
  • default: ''
  • desc: 当前名称对应语言的key

name

  • type: string
  • default: ''
  • desc: 指标名

value

  • type: string | number
  • desc: 指标数值

stdValue

  • since: v1.3.1
  • type: number
  • default: 0
  • desc: 标准值。有些指标会输出标准值。如果为0则表示未输出标准值

fixed

  • type: number
  • default: 2
  • desc: 设定value,boundaries,min,max等保留的小数位

unit

  • type: string
  • default: '',
  • desc: 单位。展示用。当使用toObject方法导出数据,默认unit的值为unitValue

unitValue

  • type: string
  • default: ''
  • desc: 单位的值。例如 unitValue: jin。unit则为 斤。如果不是重量单位,unitValue一般为unit值的 i18nKey名

order

  • type: number
  • default: 0
  • desc: 排序。10作为梯度

icon

  • type: string
  • default: ''
  • desc: 图标名或地址

descI18nKey

  • type: string
  • default: ‘’
  • desc: 来自levels中对应等级的descI18nKey

desc

  • type: string
  • default: ''
  • desc: 来自levels中对应等级的desc

introI18nKey

  • type: string
  • default: ‘’
  • desc: 指标介绍的i18nKey

intro

  • type: string
  • default: ''
  • desc: 指标介绍

boundaries

  • type: Array<string | number>
  • default: []
  • desc: 边界值数组

subBoundaries

  • type: Array<string | number>
  • default: []
  • desc: 细分边界值数组

min

  • type: string | number
  • default: 0
  • desc: 最小值

max

  • type: string | number
  • default: 9999
  • desc: 最大值

levels

  • type: Array<{ color: string; nameI18nKey: string; name: string; desc: string; descI18nKey: string; }>
  • default: []
  • desc: 等级描述

levelIndex

  • type: number
  • default: 0
  • desc: 当前等级索引

progress

  • type: number
  • default: 0
  • desc: 总进度。例如 50。 如果小于最小值则会为负数。 大于最大值则会超过100。 计算公式:(value - min) / (max - min)。 注意此字段不应该作为进度条展示依据。单条进度条百分比展示请使用 displayProgress 字段。

displayProgress

readonly

  • since: v1.3.1
  • type: number
  • desc: 可用于单条进度条百分比展示

levelProgress

  • type: number
  • default: 0
  • desc: 在当前区间的进度。例如 30。 如果小于最小值则为 -100。 大于最大值为 100。 计算公式:(value - levelStart) / (levelEnd - levelStart)。 区间进度条分段展示可用此字段。

processBarVisible

  • type: boolean
  • default: false
  • desc: 是否显示进度条

valueFormatter

  • type: (ctx: ReportItem) => string
  • desc: 对value值格式化展示。会根据重量单位进行数值转换以及toFixed

stdValueFormatter

  • type: (ctx: ReportItem) => string
  • desc: 对stdValue值格式化展示。会根据重量单位进行数值转换以及toFixed

minFormatter

  • type: (ctx: ReportItem) => string
  • desc: 对min值格式化展示。会根据重量单位进行数值转换以及toFixed

maxFormatter

  • type: (ctx: ReportItem) => string
  • desc: 对max值格式化展示。会根据重量单位进行数值转换以及toFixed

unitFormatter

  • type: (ctx: ReportItem) => string
  • desc: 对unit值格式化展示。会根据重量单位以及unitValue决定返回的文字

boundariesFormatter

  • type: (ctx: ReportItem) => string
  • desc: 对boundaries值格式化展示。会根据重量单位进行数值转换以及toFixed

subBoundariesFormatter

  • type: (ctx: ReportItem) => string
  • desc: 对subBoundaries值格式化展示。会根据重量单位进行数值转换以及toFixed

isNeedTransformWeightValueByUnit

  • type: boolean
  • default: false
  • desc: 展示结果是否需要单位换算

isAdditional

  • type: boolean
  • default: false
  • desc: 是否是额外指标

constructor

  • args
  • params
    • type: Partial<Pick<ReportItem, TypeAllowedProp>> | ReportItem
    • default: {}

call

  • args
    • fn
      • type: string
      • desc: 方法名
    • args
      • type: any[]
      • desc: 要传递的参数

toFixed

  • args
    • value
      • type: string | number
      • default: tihs.value
    • fixed
      • type: number
      • default: this.fixed
    • tz
      • type: boolean
      • default: true
      • desc: 是否去掉小数位末尾的0
    • rm
      • type: number
      • desc: round取值方式
  • example
value = 255.5;
toFixed(value, 5); // "255.5"
toFixed(value, 5, false); // "255.50000"

toPrecision

固定位数

  • args
    • value
      • type: string | number
      • default: tihs.value
    • precision
      • type: number
    • rm
      • type: number
      • desc: round取值方式
  • example
value = 255.5;
toPrecision(value, 5); // "255.50"

toExponential

科学计数法结果

  • args
    • value
      • type: string | number
      • default: tihs.value
    • dp
      • type: number
    • rm
      • type: number
      • desc: round取值方式
  • example
value = 255.5;
toExponential(value, 5); // "2.55500e+2"

toObject

输出为普通对象

export type TypeReportItemObject = {
  id: string;
  nameI18nKey: string;
  name: string;
  value: string;
  stdValue: string; // since v1.3.1
  fixed: number;
  unit: string;
  unitValue: string;
  order: number;
  icon: string;
  descI18nKey: string;
  desc: string;
  introI18nKey: string;
  intro: string;
  boundaries: string[];
  subBoundaries: string[];
  min: string;
  max: string;
  levels: TypedLevels[];
  levelIndex: number;
  progress: number;
  levelProgress: number;
  displayProgress: number; // since v1.3.1
  processBarVisible: boolean;
};

setter, getter

id,nameI18nKey,name,value,stdValue,fixed,unit,unitValue,order,icon,descI18nKey,desc,introI18nKey,intro,boundaries,subBoundaries,min,max,levelIndex,levels,progress,levelProgress,processBarVisible,valueFormatter,stdValueFormatter,minFormatter,maxFormatter,unitFormatter,boundariesFormatter,subBoundariesFormatter,isNeedTransformWeightValueByUnit, isAdditional

有对应的get和set方法。 例如: getId() setId('Weight')

无机盐输出的值的定义

对应字段mineral_salt

BREAKING CHANGE

// Before v1.4.0
export enum MineralSaltReportValueEnum {
  // 充足
  adequate = 0,
  // 正常
  normal = 1,
  // 缺乏
  lack = 2,
}

// Since v1.4.0
export enum MineralSaltReportValueEnum {
  // 充足
  adequate = 3,
  // 正常
  normal = 2,
  // 缺乏
  lack = 1,
}

体型输出值的定义

对应返回的字段body_shape

export enum BodyShapeReportValueEnum {
  // 隐形肥胖型
  shape1 = 1,
  // 运动不足型
  shape2 = 2,
  // 偏瘦型
  shape3 = 3,
  // 标准型
  shape4 = 4,
  // 偏瘦肌肉型
  shape5 = 5,
  // 肥胖型
  shape6 = 6,
  // 偏胖型
  shape7 = 7,
  // 标准肌肉型
  shape8 = 8,
  // 非常肌肉型
  shape9 = 9,
}

脂肪肝风险等级输出值定义

export enum FattyLiverReportValueEnum {
  // 0级
  level0 = 0,
  // I级
  level1 = 1,
  // II级
  level2 = 2,
  // III级
  level3 = 3,
  // IV级
  level4 = 4,
}

CHANGELOG

点击查看

(npm上无法查看当前目录下的其他md文件,可安装库后在对应模块目录里找到CHANGELOG.md文件)