import { COMMON_SH , COMMON_SZ , COMMON_HK , COMMON_US } from "@stocks/base/utils/constant" ; import { ERROR_UNDEFINED_API_CODE , ERROR_UNDEFINED_SZ_API_CODE , ERROR_UNDEFINED_SH_API_CODE , ERROR_UNDEFINED_HK_API_CODE , ERROR_UNDEFINED_US_API_CODE , ERROR_API_CODE } from "@utils/constant" ; import ApiCodeTransform from "types/stocks/transforms/api-code" ; /**
 * 【基础】股票代码转换统一代码
 */ class BaseApiCodeTransform implements ApiCodeTransform { param code public transform ( code ) { if ( code . indexOf ( COMMON_SH ) === 0 ) { return this . SHTransform ( code ) ; } if ( code . indexOf ( COMMON_SZ ) === 0 ) { return this . SZTransform ( code ) ; } if ( code . indexOf ( COMMON_HK ) === 0 ) { return this . HKTransform ( code ) ; } if ( code . indexOf ( COMMON_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 ) { throw new Error ( ERROR_UNDEFINED_SZ_API_CODE ) ; } param code public SHTransform ( code ) { throw new Error ( ERROR_UNDEFINED_SH_API_CODE ) ; } param code public HKTransform ( code ) { throw new Error ( ERROR_UNDEFINED_HK_API_CODE ) ; } param code public USTransform ( code ) { throw new Error ( ERROR_UNDEFINED_US_API_CODE ) ; } } export default BaseApiCodeTransform ;