import BaseApiCodeTransform from "@stocks/base/transforms/api-code" ; import { ERROR_API_CODE } from "@utils/constant" ; import { COMMON_SH , COMMON_SZ , COMMON_HK , COMMON_US } from "@stocks/base/utils/constant" ; import { NETEASE_SZ , NETEASE_SH , NETEASE_HK , NETEASE_US } from "@stocks/netease/utils/constant" ; /**
 * 网易股票代码转统一代码
 */ class NeteaseApiCodeTransform extends BaseApiCodeTransform { param code public transform ( code ) { if ( code . indexOf ( NETEASE_SZ ) === 0 ) { return this . SZTransform ( code ) ; } if ( code . indexOf ( NETEASE_SH ) === 0 ) { return this . SHTransform ( code ) ; } if ( code . indexOf ( NETEASE_HK ) === 0 ) { return this . HKTransform ( code ) ; } if ( code . indexOf ( NETEASE_US ) === 0 ) { return this . USTransform ( code ) ; } throw new Error ( ERROR_API_CODE ) ; } param codes public transforms ( codes ) { return codes . map ( ( code ) => this . transform ( code ) ) ; } param code public SZTransform ( code ) { if ( code . indexOf ( NETEASE_SZ ) !== 0 ) { throw new Error ( ERROR_API_CODE ) ; } return COMMON_SZ + code . replace ( NETEASE_SZ , "" ) ; } param code public SHTransform ( code ) { if ( ! code . includes ( NETEASE_SH ) ) { throw new Error ( ERROR_API_CODE ) ; } return COMMON_SH + code . replace ( NETEASE_SH , "" ) ; } param code public HKTransform ( code ) { if ( ! code . includes ( NETEASE_HK ) ) { throw new Error ( ERROR_API_CODE ) ; } return COMMON_HK + code . replace ( NETEASE_HK , "" ) ; } param code public USTransform ( code ) { if ( ! code . includes ( NETEASE_US ) ) { throw new Error ( ERROR_API_CODE ) ; } return COMMON_US + code . replace ( NETEASE_US , "" ) ; } } export default NeteaseApiCodeTransform ;