{"version":3,"file":"ngx-shift-jis.mjs","sources":["../../../projects/ngx-shift-jis/src/lib/ngx-shift-jis.service.ts","../../../projects/ngx-shift-jis/src/lib/ngx-shift-jis.module.ts","../../../projects/ngx-shift-jis/src/public-api.ts","../../../projects/ngx-shift-jis/src/ngx-shift-jis.ts"],"sourcesContent":["/**\n * Author: DaiDH\n * Library based on encoding-japanese\n * https://www.npmjs.com/package/ngx-shift-jis\n * https://www.npmjs.com/package/encoding-japanese\n */\nimport { Injectable } from '@angular/core';\nimport * as encoding from 'encoding-japanese';\nimport { AsyncSubject } from 'rxjs';\n\nexport interface Type {\n  reg: string; // regex match file name\n  type: string;\n}\n\n@Injectable({\n  providedIn: 'root'\n})\nexport class NgxShiftJisService {\n\n  public types: Type[] = [\n    { reg: '\\.(txt)$', type: 'text/plain;charset=utf-8' },\n    { reg: '\\.(csv)$', type: 'text/csv;charset=utf-8' },\n\n    { reg: '\\.(doc|dot)$', type: 'application/msword' },\n    { reg: '\\.(docx)$', type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' },\n    { reg: '\\.(xls|xlt|xla)$', type: 'application/vnd.ms-excel' },\n\n    { reg: '\\.(xlsx)$', type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' },\n    { reg: '\\.(xltx)$', type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.template' },\n    { reg: '\\.(xlsm)$', type: 'application/vnd.ms-excel.sheet.macroEnabled.12' },\n    { reg: '\\.(xltm)$', type: 'application/vnd.ms-excel.template.macroEnabled.12' },\n    { reg: '\\.(xlam)$', type: 'application/vnd.ms-excel.addin.macroEnabled.12' },\n    { reg: '\\.(xlsb)$', type: 'application/vnd.ms-excel.sheet.binary.macroEnabled.12' },\n\n    { reg: '\\.(ppt|pot|pps|ppa)$', type: 'application/vnd.ms-powerpoint' },\n\n    { reg: '\\.(pptx)$', type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation' },\n    { reg: '\\.(potx)$', type: 'application/vnd.openxmlformats-officedocument.presentationml.template' },\n    { reg: '\\.(ppsx)$', type: 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' },\n    { reg: '\\.(ppam)$', type: 'application/vnd.ms-powerpoint.addin.macroEnabled.12' },\n    { reg: '\\.(pptm)$', type: 'application/vnd.ms-powerpoint.presentation.macroEnabled.12' },\n    { reg: '\\.(potm)$', type: 'application/vnd.ms-powerpoint.template.macroEnabled.12' },\n    { reg: '\\.(ppsm)$', type: 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12' },\n\n    { reg: '\\.(mdb)$', type: 'application/vnd.ms-access' },\n  ];\n\n  /**\n   * encoding-japanese\n   * @param content \n   * @param fileName \n   * @param convert \n   */\n  public downloadShiftJIS(content: string = '', fileName: string = '', convert?: Function): AsyncSubject<any> {\n    const as = new AsyncSubject();\n    try {\n      // encoding-japanese\n      let num_array;\n      let sjis_array;\n      if (convert) {\n        // custom\n        sjis_array = convert(encoding);\n      } else {\n        // default SJIS UNICODE\n        num_array = encoding.stringToCode(content);\n        sjis_array = encoding.convert(num_array, \"SJIS\", \"UNICODE\");\n      }\n      const uint8_array = new Uint8Array(sjis_array);\n      // Type\n      const type = this.type(fileName);\n      // Blob\n      const blob = new Blob([uint8_array], { type: type && type.type });\n      // Download\n      this.downloadUri(blob, fileName, type, as);\n      // AsyncSubject\n    } catch (error) {\n      as.error(error as any);\n      as.complete();\n    }\n    return as;\n  }\n\n  /**\n   * Type\n   * @param fileName \n   * @returns \n   */\n  private type(fileName: string): Type {\n    const type = this.types.find((f: Type) => new RegExp(f.reg, 'i').test(fileName));\n    return type || this.types[0];\n  }\n\n  /**\n   * Download\n   * @param blob \n   * @param fileName \n   * @param type \n   * @param as \n   */\n  private downloadUri(blob: Blob, fileName: string, type: Type, as: AsyncSubject<any>): void {\n    const url = window.URL.createObjectURL(blob);\n    const a = document.createElement('a');\n    a.href = url;\n    a.download = fileName;\n    a.click();\n    a.remove();\n    as.next({ url: url, blob: blob, fileName: fileName, fileType: type });\n    as.complete();\n  }\n}","import { NgModule } from '@angular/core';\nimport { NgxShiftJisService } from './ngx-shift-jis.service';\n\n@NgModule({\n  providers: [NgxShiftJisService]\n})\nexport class NgxShiftJisModule { }\n","/*\n * Public API Surface of ngx-shift-jis\n */\n\nexport * from './lib/ngx-shift-jis.service';\nexport * from './lib/ngx-shift-jis.module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAAA;;;;;AAKG;MAaU,kBAAkB,CAAA;AAH/B,IAAA,WAAA,GAAA;AAKS,QAAA,IAAA,CAAA,KAAK,GAAW;AACrB,YAAA,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,0BAA0B,EAAE;AACrD,YAAA,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,wBAAwB,EAAE;AAEnD,YAAA,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,oBAAoB,EAAE;AACnD,YAAA,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,yEAAyE,EAAE;AACrG,YAAA,EAAE,GAAG,EAAE,kBAAkB,EAAE,IAAI,EAAE,0BAA0B,EAAE;AAE7D,YAAA,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,mEAAmE,EAAE;AAC/F,YAAA,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,sEAAsE,EAAE;AAClG,YAAA,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,gDAAgD,EAAE;AAC5E,YAAA,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,mDAAmD,EAAE;AAC/E,YAAA,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,gDAAgD,EAAE;AAC5E,YAAA,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,uDAAuD,EAAE;AAEnF,YAAA,EAAE,GAAG,EAAE,sBAAsB,EAAE,IAAI,EAAE,+BAA+B,EAAE;AAEtE,YAAA,EAAE,GAAG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