administrate-field-simple_mde_markdown 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.circleci/config.yml +72 -0
- data/.circleci/setup-rubygems.sh +3 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +196 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +8 -0
- data/administrate-field-simple_mde_markdown.gemspec +31 -0
- data/app/assets/javascripts/administrate-field-simple_mde_markdown/application.js +6 -0
- data/app/assets/stylesheets/administrate-field-simple_mde_markdown/application.css +3 -0
- data/app/views/fields/simple_mde_markdown/_form.html.erb +6 -0
- data/app/views/fields/simple_mde_markdown/_index.html.erb +1 -0
- data/app/views/fields/simple_mde_markdown/_show.html.erb +1 -0
- data/lib/administrate/field/simple_mde_markdown.rb +31 -0
- data/node_modules/.bin/marked +1 -0
- data/node_modules/codemirror-spell-checker/.eslintrc +23 -0
- data/node_modules/codemirror-spell-checker/.npmignore +2 -0
- data/node_modules/codemirror-spell-checker/.travis.yml +18 -0
- data/node_modules/codemirror-spell-checker/CONTRIBUTING 2.md +10 -0
- data/node_modules/codemirror-spell-checker/CONTRIBUTING.md +10 -0
- data/node_modules/codemirror-spell-checker/LICENSE +22 -0
- data/node_modules/codemirror-spell-checker/README.md +50 -0
- data/node_modules/codemirror-spell-checker/bower.json +27 -0
- data/node_modules/codemirror-spell-checker/debug/.spell-checker 2.css.icloud +0 -0
- data/node_modules/codemirror-spell-checker/debug/spell-checker.css +9 -0
- data/node_modules/codemirror-spell-checker/debug/spell-checker.debug.js +2844 -0
- data/node_modules/codemirror-spell-checker/debug/spell-checker.js +2841 -0
- data/node_modules/codemirror-spell-checker/dist/.spell-checker.min 2.css.icloud +0 -0
- data/node_modules/codemirror-spell-checker/dist/en_US.aff +201 -0
- data/node_modules/codemirror-spell-checker/dist/en_US.dic +62120 -0
- data/node_modules/codemirror-spell-checker/dist/spell-checker.min 2.js +7 -0
- data/node_modules/codemirror-spell-checker/dist/spell-checker.min.css +7 -0
- data/node_modules/codemirror-spell-checker/dist/spell-checker.min.js +7 -0
- data/node_modules/codemirror-spell-checker/gulpfile.js +94 -0
- data/node_modules/codemirror-spell-checker/package.json +75 -0
- data/node_modules/codemirror-spell-checker/src/css/spell-checker.css +3 -0
- data/node_modules/codemirror-spell-checker/src/data/en_US.aff +201 -0
- data/node_modules/codemirror-spell-checker/src/data/en_US.dic +62120 -0
- data/node_modules/codemirror-spell-checker/src/js/spell-checker.js +119 -0
- data/node_modules/codemirror/.package 2.json.icloud +0 -0
- data/node_modules/codemirror/AUTHORS +773 -0
- data/node_modules/codemirror/CHANGELOG.md +1486 -0
- data/node_modules/codemirror/CONTRIBUTING.md +92 -0
- data/node_modules/codemirror/LICENSE +21 -0
- data/node_modules/codemirror/README.md +49 -0
- data/node_modules/codemirror/addon/comment/comment.js +209 -0
- data/node_modules/codemirror/addon/comment/continuecomment.js +78 -0
- data/node_modules/codemirror/addon/dialog/dialog.css +32 -0
- data/node_modules/codemirror/addon/dialog/dialog.js +161 -0
- data/node_modules/codemirror/addon/display/autorefresh.js +47 -0
- data/node_modules/codemirror/addon/display/fullscreen.css +6 -0
- data/node_modules/codemirror/addon/display/fullscreen.js +41 -0
- data/node_modules/codemirror/addon/display/panel.js +127 -0
- data/node_modules/codemirror/addon/display/placeholder.js +63 -0
- data/node_modules/codemirror/addon/display/rulers.js +51 -0
- data/node_modules/codemirror/addon/edit/closebrackets.js +187 -0
- data/node_modules/codemirror/addon/edit/closetag.js +175 -0
- data/node_modules/codemirror/addon/edit/continuelist.js +89 -0
- data/node_modules/codemirror/addon/edit/matchbrackets.js +145 -0
- data/node_modules/codemirror/addon/edit/matchtags.js +66 -0
- data/node_modules/codemirror/addon/edit/trailingspace.js +27 -0
- data/node_modules/codemirror/addon/fold/brace-fold.js +105 -0
- data/node_modules/codemirror/addon/fold/comment-fold.js +59 -0
- data/node_modules/codemirror/addon/fold/foldcode.js +152 -0
- data/node_modules/codemirror/addon/fold/foldgutter.css +20 -0
- data/node_modules/codemirror/addon/fold/foldgutter.js +146 -0
- data/node_modules/codemirror/addon/fold/indent-fold.js +48 -0
- data/node_modules/codemirror/addon/fold/markdown-fold.js +49 -0
- data/node_modules/codemirror/addon/fold/xml-fold.js +184 -0
- data/node_modules/codemirror/addon/hint/anyword-hint.js +41 -0
- data/node_modules/codemirror/addon/hint/css-hint.js +60 -0
- data/node_modules/codemirror/addon/hint/html-hint.js +348 -0
- data/node_modules/codemirror/addon/hint/javascript-hint.js +157 -0
- data/node_modules/codemirror/addon/hint/show-hint.css +36 -0
- data/node_modules/codemirror/addon/hint/show-hint.js +434 -0
- data/node_modules/codemirror/addon/hint/sql-hint.js +299 -0
- data/node_modules/codemirror/addon/hint/xml-hint.js +110 -0
- data/node_modules/codemirror/addon/lint/coffeescript-lint.js +47 -0
- data/node_modules/codemirror/addon/lint/css-lint.js +40 -0
- data/node_modules/codemirror/addon/lint/html-lint.js +53 -0
- data/node_modules/codemirror/addon/lint/javascript-lint.js +63 -0
- data/node_modules/codemirror/addon/lint/json-lint.js +40 -0
- data/node_modules/codemirror/addon/lint/lint.css +73 -0
- data/node_modules/codemirror/addon/lint/lint.js +252 -0
- data/node_modules/codemirror/addon/lint/yaml-lint.js +41 -0
- data/node_modules/codemirror/addon/merge/merge.css +119 -0
- data/node_modules/codemirror/addon/merge/merge.js +1002 -0
- data/node_modules/codemirror/addon/mode/loadmode.js +64 -0
- data/node_modules/codemirror/addon/mode/multiplex.js +131 -0
- data/node_modules/codemirror/addon/mode/multiplex_test.js +33 -0
- data/node_modules/codemirror/addon/mode/overlay.js +90 -0
- data/node_modules/codemirror/addon/mode/simple.js +216 -0
- data/node_modules/codemirror/addon/runmode/colorize.js +40 -0
- data/node_modules/codemirror/addon/runmode/runmode-standalone.js +158 -0
- data/node_modules/codemirror/addon/runmode/runmode.js +72 -0
- data/node_modules/codemirror/addon/runmode/runmode.node.js +197 -0
- data/node_modules/codemirror/addon/scroll/annotatescrollbar.js +122 -0
- data/node_modules/codemirror/addon/scroll/scrollpastend.js +48 -0
- data/node_modules/codemirror/addon/scroll/simplescrollbars.css +66 -0
- data/node_modules/codemirror/addon/scroll/simplescrollbars.js +152 -0
- data/node_modules/codemirror/addon/search/jump-to-line.js +50 -0
- data/node_modules/codemirror/addon/search/match-highlighter.js +165 -0
- data/node_modules/codemirror/addon/search/matchesonscrollbar.css +8 -0
- data/node_modules/codemirror/addon/search/matchesonscrollbar.js +97 -0
- data/node_modules/codemirror/addon/search/search.js +258 -0
- data/node_modules/codemirror/addon/search/searchcursor.js +293 -0
- data/node_modules/codemirror/addon/selection/active-line.js +72 -0
- data/node_modules/codemirror/addon/selection/mark-selection.js +119 -0
- data/node_modules/codemirror/addon/selection/selection-pointer.js +98 -0
- data/node_modules/codemirror/addon/tern/tern.css +87 -0
- data/node_modules/codemirror/addon/tern/tern.js +718 -0
- data/node_modules/codemirror/addon/tern/worker.js +44 -0
- data/node_modules/codemirror/addon/wrap/hardwrap.js +145 -0
- data/node_modules/codemirror/bin/source-highlight +48 -0
- data/node_modules/codemirror/keymap/emacs.js +417 -0
- data/node_modules/codemirror/keymap/sublime.js +691 -0
- data/node_modules/codemirror/keymap/vim.js +5467 -0
- data/node_modules/codemirror/lib/codemirror.css +346 -0
- data/node_modules/codemirror/lib/codemirror.js +9698 -0
- data/node_modules/codemirror/mode/apl/apl.js +174 -0
- data/node_modules/codemirror/mode/asciiarmor/asciiarmor.js +74 -0
- data/node_modules/codemirror/mode/asn.1/asn.1.js +204 -0
- data/node_modules/codemirror/mode/asterisk/asterisk.js +196 -0
- data/node_modules/codemirror/mode/brainfuck/brainfuck.js +85 -0
- data/node_modules/codemirror/mode/clike/clike.js +879 -0
- data/node_modules/codemirror/mode/clojure/clojure.js +292 -0
- data/node_modules/codemirror/mode/cmake/cmake.js +97 -0
- data/node_modules/codemirror/mode/cobol/cobol.js +255 -0
- data/node_modules/codemirror/mode/coffeescript/coffeescript.js +359 -0
- data/node_modules/codemirror/mode/commonlisp/commonlisp.js +124 -0
- data/node_modules/codemirror/mode/crystal/crystal.js +433 -0
- data/node_modules/codemirror/mode/css/css.js +832 -0
- data/node_modules/codemirror/mode/cypher/cypher.js +150 -0
- data/node_modules/codemirror/mode/d/d.js +223 -0
- data/node_modules/codemirror/mode/dart/dart.js +157 -0
- data/node_modules/codemirror/mode/diff/diff.js +47 -0
- data/node_modules/codemirror/mode/django/django.js +356 -0
- data/node_modules/codemirror/mode/dockerfile/dockerfile.js +211 -0
- data/node_modules/codemirror/mode/dtd/dtd.js +142 -0
- data/node_modules/codemirror/mode/dylan/dylan.js +352 -0
- data/node_modules/codemirror/mode/ebnf/ebnf.js +195 -0
- data/node_modules/codemirror/mode/ecl/ecl.js +206 -0
- data/node_modules/codemirror/mode/eiffel/eiffel.js +160 -0
- data/node_modules/codemirror/mode/elm/elm.js +205 -0
- data/node_modules/codemirror/mode/erlang/erlang.js +619 -0
- data/node_modules/codemirror/mode/factor/factor.js +85 -0
- data/node_modules/codemirror/mode/fcl/fcl.js +173 -0
- data/node_modules/codemirror/mode/forth/forth.js +180 -0
- data/node_modules/codemirror/mode/fortran/fortran.js +188 -0
- data/node_modules/codemirror/mode/gas/gas.js +345 -0
- data/node_modules/codemirror/mode/gfm/gfm.js +129 -0
- data/node_modules/codemirror/mode/gherkin/gherkin.js +178 -0
- data/node_modules/codemirror/mode/go/go.js +187 -0
- data/node_modules/codemirror/mode/groovy/groovy.js +230 -0
- data/node_modules/codemirror/mode/haml/haml.js +161 -0
- data/node_modules/codemirror/mode/handlebars/handlebars.js +66 -0
- data/node_modules/codemirror/mode/haskell-literate/haskell-literate.js +43 -0
- data/node_modules/codemirror/mode/haskell/haskell.js +268 -0
- data/node_modules/codemirror/mode/haxe/haxe.js +515 -0
- data/node_modules/codemirror/mode/htmlembedded/htmlembedded.js +37 -0
- data/node_modules/codemirror/mode/htmlmixed/htmlmixed.js +152 -0
- data/node_modules/codemirror/mode/http/http.js +113 -0
- data/node_modules/codemirror/mode/idl/idl.js +290 -0
- data/node_modules/codemirror/mode/javascript/javascript.js +899 -0
- data/node_modules/codemirror/mode/jinja2/jinja2.js +144 -0
- data/node_modules/codemirror/mode/jsx/jsx.js +148 -0
- data/node_modules/codemirror/mode/julia/julia.js +433 -0
- data/node_modules/codemirror/mode/livescript/livescript.js +280 -0
- data/node_modules/codemirror/mode/lua/lua.js +159 -0
- data/node_modules/codemirror/mode/markdown/markdown.js +884 -0
- data/node_modules/codemirror/mode/mathematica/mathematica.js +176 -0
- data/node_modules/codemirror/mode/mbox/mbox.js +129 -0
- data/node_modules/codemirror/mode/meta.js +217 -0
- data/node_modules/codemirror/mode/mirc/mirc.js +193 -0
- data/node_modules/codemirror/mode/mllike/mllike.js +359 -0
- data/node_modules/codemirror/mode/modelica/modelica.js +245 -0
- data/node_modules/codemirror/mode/mscgen/mscgen.js +175 -0
- data/node_modules/codemirror/mode/mumps/mumps.js +148 -0
- data/node_modules/codemirror/mode/nginx/nginx.js +178 -0
- data/node_modules/codemirror/mode/nsis/nsis.js +95 -0
- data/node_modules/codemirror/mode/ntriples/ntriples.js +195 -0
- data/node_modules/codemirror/mode/octave/octave.js +139 -0
- data/node_modules/codemirror/mode/oz/oz.js +252 -0
- data/node_modules/codemirror/mode/pascal/pascal.js +121 -0
- data/node_modules/codemirror/mode/pegjs/pegjs.js +114 -0
- data/node_modules/codemirror/mode/perl/perl.js +837 -0
- data/node_modules/codemirror/mode/php/php.js +234 -0
- data/node_modules/codemirror/mode/pig/pig.js +178 -0
- data/node_modules/codemirror/mode/powershell/powershell.js +398 -0
- data/node_modules/codemirror/mode/properties/properties 2.js +78 -0
- data/node_modules/codemirror/mode/properties/properties.js +78 -0
- data/node_modules/codemirror/mode/protobuf/protobuf.js +69 -0
- data/node_modules/codemirror/mode/pug/pug.js +591 -0
- data/node_modules/codemirror/mode/puppet/puppet.js +220 -0
- data/node_modules/codemirror/mode/python/python.js +409 -0
- data/node_modules/codemirror/mode/q/q.js +139 -0
- data/node_modules/codemirror/mode/r/r.js +190 -0
- data/node_modules/codemirror/mode/rpm/changes/index.html +66 -0
- data/node_modules/codemirror/mode/rpm/rpm.js +109 -0
- data/node_modules/codemirror/mode/rst/rst.js +557 -0
- data/node_modules/codemirror/mode/ruby/ruby.js +296 -0
- data/node_modules/codemirror/mode/rust/rust.js +72 -0
- data/node_modules/codemirror/mode/sas/sas.js +303 -0
- data/node_modules/codemirror/mode/sass/sass.js +454 -0
- data/node_modules/codemirror/mode/scheme/scheme.js +265 -0
- data/node_modules/codemirror/mode/shell/shell.js +152 -0
- data/node_modules/codemirror/mode/sieve/sieve.js +193 -0
- data/node_modules/codemirror/mode/slim/slim.js +575 -0
- data/node_modules/codemirror/mode/smalltalk/smalltalk.js +168 -0
- data/node_modules/codemirror/mode/smarty/smarty.js +225 -0
- data/node_modules/codemirror/mode/solr/solr.js +104 -0
- data/node_modules/codemirror/mode/soy/soy 2.js +359 -0
- data/node_modules/codemirror/mode/soy/soy.js +235 -0
- data/node_modules/codemirror/mode/sparql/sparql.js +180 -0
- data/node_modules/codemirror/mode/spreadsheet/spreadsheet.js +112 -0
- data/node_modules/codemirror/mode/sql/sql.js +499 -0
- data/node_modules/codemirror/mode/stex/stex.js +264 -0
- data/node_modules/codemirror/mode/stylus/stylus.js +771 -0
- data/node_modules/codemirror/mode/swift/swift.js +219 -0
- data/node_modules/codemirror/mode/tcl/tcl.js +139 -0
- data/node_modules/codemirror/mode/textile/textile.js +469 -0
- data/node_modules/codemirror/mode/tiddlywiki/tiddlywiki.css +14 -0
- data/node_modules/codemirror/mode/tiddlywiki/tiddlywiki.js +308 -0
- data/node_modules/codemirror/mode/tiki/tiki.css +26 -0
- data/node_modules/codemirror/mode/tiki/tiki.js +312 -0
- data/node_modules/codemirror/mode/toml/toml.js +88 -0
- data/node_modules/codemirror/mode/tornado/tornado.js +68 -0
- data/node_modules/codemirror/mode/troff/troff.js +84 -0
- data/node_modules/codemirror/mode/ttcn-cfg/ttcn-cfg.js +214 -0
- data/node_modules/codemirror/mode/ttcn/ttcn.js +283 -0
- data/node_modules/codemirror/mode/turtle/turtle.js +162 -0
- data/node_modules/codemirror/mode/twig/twig.js +141 -0
- data/node_modules/codemirror/mode/vb/vb.js +275 -0
- data/node_modules/codemirror/mode/vbscript/vbscript.js +350 -0
- data/node_modules/codemirror/mode/velocity/velocity.js +201 -0
- data/node_modules/codemirror/mode/verilog/verilog.js +675 -0
- data/node_modules/codemirror/mode/vhdl/vhdl.js +189 -0
- data/node_modules/codemirror/mode/vue/vue.js +77 -0
- data/node_modules/codemirror/mode/webidl/webidl.js +195 -0
- data/node_modules/codemirror/mode/xml/xml.js +402 -0
- data/node_modules/codemirror/mode/xquery/xquery.js +448 -0
- data/node_modules/codemirror/mode/yacas/yacas.js +204 -0
- data/node_modules/codemirror/mode/yaml-frontmatter/yaml-frontmatter.js +68 -0
- data/node_modules/codemirror/mode/yaml/yaml.js +120 -0
- data/node_modules/codemirror/mode/z80/z80.js +116 -0
- data/node_modules/codemirror/package.json +2395 -0
- data/node_modules/codemirror/rollup.config.js +20 -0
- data/node_modules/codemirror/src/codemirror.js +3 -0
- data/node_modules/codemirror/src/display/Display.js +106 -0
- data/node_modules/codemirror/src/display/focus.js +47 -0
- data/node_modules/codemirror/src/display/gutters.js +34 -0
- data/node_modules/codemirror/src/display/highlight_worker.js +55 -0
- data/node_modules/codemirror/src/display/line_numbers.js +48 -0
- data/node_modules/codemirror/src/display/mode_state.js +22 -0
- data/node_modules/codemirror/src/display/operations.js +205 -0
- data/node_modules/codemirror/src/display/scroll_events.js +115 -0
- data/node_modules/codemirror/src/display/scrollbars.js +193 -0
- data/node_modules/codemirror/src/display/scrolling.js +184 -0
- data/node_modules/codemirror/src/display/selection.js +158 -0
- data/node_modules/codemirror/src/display/update_display.js +260 -0
- data/node_modules/codemirror/src/display/update_line.js +188 -0
- data/node_modules/codemirror/src/display/update_lines.js +64 -0
- data/node_modules/codemirror/src/display/view_tracking.js +153 -0
- data/node_modules/codemirror/src/edit/CodeMirror.js +215 -0
- data/node_modules/codemirror/src/edit/commands.js +178 -0
- data/node_modules/codemirror/src/edit/deleteNearSelection.js +30 -0
- data/node_modules/codemirror/src/edit/drop_events.js +119 -0
- data/node_modules/codemirror/src/edit/fromTextArea.js +61 -0
- data/node_modules/codemirror/src/edit/global_events.js +42 -0
- data/node_modules/codemirror/src/edit/key_events.js +159 -0
- data/node_modules/codemirror/src/edit/legacy.js +62 -0
- data/node_modules/codemirror/src/edit/main.js +69 -0
- data/node_modules/codemirror/src/edit/methods.js +544 -0
- data/node_modules/codemirror/src/edit/mouse_events.js +407 -0
- data/node_modules/codemirror/src/edit/options.js +193 -0
- data/node_modules/codemirror/src/edit/utils.js +7 -0
- data/node_modules/codemirror/src/input/ContentEditableInput.js +527 -0
- data/node_modules/codemirror/src/input/TextareaInput.js +355 -0
- data/node_modules/codemirror/src/input/indent.js +71 -0
- data/node_modules/codemirror/src/input/input.js +135 -0
- data/node_modules/codemirror/src/input/keymap.js +148 -0
- data/node_modules/codemirror/src/input/keynames.js +17 -0
- data/node_modules/codemirror/src/input/movement.js +110 -0
- data/node_modules/codemirror/src/line/highlight.js +284 -0
- data/node_modules/codemirror/src/line/line_data.js +339 -0
- data/node_modules/codemirror/src/line/pos.js +40 -0
- data/node_modules/codemirror/src/line/saw_special_spans.js +10 -0
- data/node_modules/codemirror/src/line/spans.js +382 -0
- data/node_modules/codemirror/src/line/utils_line.js +85 -0
- data/node_modules/codemirror/src/measurement/position_measurement.js +699 -0
- data/node_modules/codemirror/src/measurement/widgets.js +26 -0
- data/node_modules/codemirror/src/model/Doc.js +432 -0
- data/node_modules/codemirror/src/model/change_measurement.js +61 -0
- data/node_modules/codemirror/src/model/changes.js +333 -0
- data/node_modules/codemirror/src/model/chunk.js +167 -0
- data/node_modules/codemirror/src/model/document_data.js +111 -0
- data/node_modules/codemirror/src/model/history.js +228 -0
- data/node_modules/codemirror/src/model/line_widget.js +78 -0
- data/node_modules/codemirror/src/model/mark_text.js +292 -0
- data/node_modules/codemirror/src/model/selection.js +84 -0
- data/node_modules/codemirror/src/model/selection_updates.js +208 -0
- data/node_modules/codemirror/src/modes.js +96 -0
- data/node_modules/codemirror/src/util/StringStream.js +90 -0
- data/node_modules/codemirror/src/util/bidi.js +214 -0
- data/node_modules/codemirror/src/util/browser.js +33 -0
- data/node_modules/codemirror/src/util/dom.js +97 -0
- data/node_modules/codemirror/src/util/event.js +103 -0
- data/node_modules/codemirror/src/util/feature_detection.js +84 -0
- data/node_modules/codemirror/src/util/misc.js +150 -0
- data/node_modules/codemirror/src/util/operation_group.js +72 -0
- data/node_modules/codemirror/theme/3024-day.css +41 -0
- data/node_modules/codemirror/theme/3024-night.css +39 -0
- data/node_modules/codemirror/theme/abcdef.css +32 -0
- data/node_modules/codemirror/theme/ambiance-mobile.css +5 -0
- data/node_modules/codemirror/theme/ambiance.css +74 -0
- data/node_modules/codemirror/theme/base16-dark.css +38 -0
- data/node_modules/codemirror/theme/base16-light.css +38 -0
- data/node_modules/codemirror/theme/bespin.css +34 -0
- data/node_modules/codemirror/theme/blackboard.css +32 -0
- data/node_modules/codemirror/theme/cobalt.css +25 -0
- data/node_modules/codemirror/theme/colorforth.css +33 -0
- data/node_modules/codemirror/theme/darcula.css +46 -0
- data/node_modules/codemirror/theme/dracula.css +40 -0
- data/node_modules/codemirror/theme/duotone-dark.css +35 -0
- data/node_modules/codemirror/theme/duotone-light.css +36 -0
- data/node_modules/codemirror/theme/eclipse.css +23 -0
- data/node_modules/codemirror/theme/elegant.css +13 -0
- data/node_modules/codemirror/theme/erlang-dark.css +34 -0
- data/node_modules/codemirror/theme/gruvbox-dark.css +37 -0
- data/node_modules/codemirror/theme/hopscotch.css +34 -0
- data/node_modules/codemirror/theme/icecoder.css +43 -0
- data/node_modules/codemirror/theme/idea.css +42 -0
- data/node_modules/codemirror/theme/isotope.css +34 -0
- data/node_modules/codemirror/theme/lesser-dark.css +47 -0
- data/node_modules/codemirror/theme/liquibyte.css +95 -0
- data/node_modules/codemirror/theme/lucario.css +37 -0
- data/node_modules/codemirror/theme/material.css +53 -0
- data/node_modules/codemirror/theme/mbo.css +37 -0
- data/node_modules/codemirror/theme/mdn-like.css +46 -0
- data/node_modules/codemirror/theme/midnight.css +43 -0
- data/node_modules/codemirror/theme/monokai.css +41 -0
- data/node_modules/codemirror/theme/neat.css +12 -0
- data/node_modules/codemirror/theme/neo.css +43 -0
- data/node_modules/codemirror/theme/night.css +27 -0
- data/node_modules/codemirror/theme/oceanic-next.css +44 -0
- data/node_modules/codemirror/theme/panda-syntax.css +85 -0
- data/node_modules/codemirror/theme/paraiso-dark.css +38 -0
- data/node_modules/codemirror/theme/paraiso-light.css +38 -0
- data/node_modules/codemirror/theme/pastel-on-dark.css +52 -0
- data/node_modules/codemirror/theme/railscasts.css +34 -0
- data/node_modules/codemirror/theme/rubyblue.css +25 -0
- data/node_modules/codemirror/theme/seti.css +44 -0
- data/node_modules/codemirror/theme/shadowfox.css +52 -0
- data/node_modules/codemirror/theme/solarized.css +168 -0
- data/node_modules/codemirror/theme/ssms.css +16 -0
- data/node_modules/codemirror/theme/the-matrix.css +30 -0
- data/node_modules/codemirror/theme/tomorrow-night-bright.css +35 -0
- data/node_modules/codemirror/theme/tomorrow-night-eighties.css +38 -0
- data/node_modules/codemirror/theme/ttcn.css +64 -0
- data/node_modules/codemirror/theme/twilight.css +32 -0
- data/node_modules/codemirror/theme/vibrant-ink.css +34 -0
- data/node_modules/codemirror/theme/xq-dark.css +53 -0
- data/node_modules/codemirror/theme/xq-light.css +43 -0
- data/node_modules/codemirror/theme/yeti.css +44 -0
- data/node_modules/codemirror/theme/zenburn.css +37 -0
- data/node_modules/marked/.editorconfig +16 -0
- data/node_modules/marked/.eslintignore +1 -0
- data/node_modules/marked/.eslintrc.json +28 -0
- data/node_modules/marked/.package 2.json.icloud +0 -0
- data/node_modules/marked/.travis.yml +47 -0
- data/node_modules/marked/Makefile +15 -0
- data/node_modules/marked/Makefile 2 +15 -0
- data/node_modules/marked/README 2.md +75 -0
- data/node_modules/marked/README.md +75 -0
- data/node_modules/marked/bin/marked +199 -0
- data/node_modules/marked/bower.json +23 -0
- data/node_modules/marked/component.json +10 -0
- data/node_modules/marked/index.js +1 -0
- data/node_modules/marked/jasmine.json +11 -0
- data/node_modules/marked/lib/marked 2.js +1604 -0
- data/node_modules/marked/lib/marked.js +1604 -0
- data/node_modules/marked/man/marked.1 +91 -0
- data/node_modules/marked/man/marked.1.txt +96 -0
- data/node_modules/marked/marked.min.js +6 -0
- data/node_modules/marked/package.json +95 -0
- data/node_modules/simplemde/.eslintrc +23 -0
- data/node_modules/simplemde/.npmignore +9 -0
- data/node_modules/simplemde/.travis.yml +18 -0
- data/node_modules/simplemde/CONTRIBUTING 2.md +10 -0
- data/node_modules/simplemde/CONTRIBUTING.md +10 -0
- data/node_modules/simplemde/LICENSE +22 -0
- data/node_modules/simplemde/README.md +331 -0
- data/node_modules/simplemde/bower.json +23 -0
- data/node_modules/simplemde/debug/.simplemde 2.css.icloud +0 -0
- data/node_modules/simplemde/debug/simplemde.css +676 -0
- data/node_modules/simplemde/debug/simplemde.debug.js +17023 -0
- data/node_modules/simplemde/debug/simplemde.js +17019 -0
- data/node_modules/simplemde/dist/simplemde.min.css +7 -0
- data/node_modules/simplemde/dist/simplemde.min.js +15 -0
- data/node_modules/simplemde/gulpfile.js +96 -0
- data/node_modules/simplemde/package.json +73 -0
- data/node_modules/simplemde/src/css/simplemde.css +328 -0
- data/node_modules/simplemde/src/js/codemirror/tablist 2.js +44 -0
- data/node_modules/simplemde/src/js/codemirror/tablist.js +44 -0
- data/node_modules/simplemde/src/js/simplemde.js +2028 -0
- data/node_modules/typo-js/README.md +45 -0
- data/node_modules/typo-js/dictionaries/en_US/.en_US 2.dic.icloud +0 -0
- data/node_modules/typo-js/dictionaries/en_US/README.md +7 -0
- data/node_modules/typo-js/dictionaries/en_US/en_US.aff +201 -0
- data/node_modules/typo-js/dictionaries/en_US/en_US.dic +62120 -0
- data/node_modules/typo-js/package.json +56 -0
- data/node_modules/typo-js/typo.js +931 -0
- data/package-lock.json +40 -0
- data/package.json +7 -0
- metadata +557 -0
@@ -0,0 +1,2841 @@
|
|
1
|
+
/**
|
2
|
+
* codemirror-spell-checker v1.1.2
|
3
|
+
* Copyright Next Step Webs, Inc.
|
4
|
+
* @link https://github.com/NextStepWebs/codemirror-spell-checker
|
5
|
+
* @license MIT
|
6
|
+
*/
|
7
|
+
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.CodeMirrorSpellChecker = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
8
|
+
'use strict'
|
9
|
+
|
10
|
+
exports.toByteArray = toByteArray
|
11
|
+
exports.fromByteArray = fromByteArray
|
12
|
+
|
13
|
+
var lookup = []
|
14
|
+
var revLookup = []
|
15
|
+
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
|
16
|
+
|
17
|
+
function init () {
|
18
|
+
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
19
|
+
for (var i = 0, len = code.length; i < len; ++i) {
|
20
|
+
lookup[i] = code[i]
|
21
|
+
revLookup[code.charCodeAt(i)] = i
|
22
|
+
}
|
23
|
+
|
24
|
+
revLookup['-'.charCodeAt(0)] = 62
|
25
|
+
revLookup['_'.charCodeAt(0)] = 63
|
26
|
+
}
|
27
|
+
|
28
|
+
init()
|
29
|
+
|
30
|
+
function toByteArray (b64) {
|
31
|
+
var i, j, l, tmp, placeHolders, arr
|
32
|
+
var len = b64.length
|
33
|
+
|
34
|
+
if (len % 4 > 0) {
|
35
|
+
throw new Error('Invalid string. Length must be a multiple of 4')
|
36
|
+
}
|
37
|
+
|
38
|
+
// the number of equal signs (place holders)
|
39
|
+
// if there are two placeholders, than the two characters before it
|
40
|
+
// represent one byte
|
41
|
+
// if there is only one, then the three characters before it represent 2 bytes
|
42
|
+
// this is just a cheap hack to not do indexOf twice
|
43
|
+
placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
|
44
|
+
|
45
|
+
// base64 is 4/3 + up to two characters of the original data
|
46
|
+
arr = new Arr(len * 3 / 4 - placeHolders)
|
47
|
+
|
48
|
+
// if there are placeholders, only get up to the last complete 4 chars
|
49
|
+
l = placeHolders > 0 ? len - 4 : len
|
50
|
+
|
51
|
+
var L = 0
|
52
|
+
|
53
|
+
for (i = 0, j = 0; i < l; i += 4, j += 3) {
|
54
|
+
tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
|
55
|
+
arr[L++] = (tmp >> 16) & 0xFF
|
56
|
+
arr[L++] = (tmp >> 8) & 0xFF
|
57
|
+
arr[L++] = tmp & 0xFF
|
58
|
+
}
|
59
|
+
|
60
|
+
if (placeHolders === 2) {
|
61
|
+
tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
|
62
|
+
arr[L++] = tmp & 0xFF
|
63
|
+
} else if (placeHolders === 1) {
|
64
|
+
tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
|
65
|
+
arr[L++] = (tmp >> 8) & 0xFF
|
66
|
+
arr[L++] = tmp & 0xFF
|
67
|
+
}
|
68
|
+
|
69
|
+
return arr
|
70
|
+
}
|
71
|
+
|
72
|
+
function tripletToBase64 (num) {
|
73
|
+
return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
|
74
|
+
}
|
75
|
+
|
76
|
+
function encodeChunk (uint8, start, end) {
|
77
|
+
var tmp
|
78
|
+
var output = []
|
79
|
+
for (var i = start; i < end; i += 3) {
|
80
|
+
tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
|
81
|
+
output.push(tripletToBase64(tmp))
|
82
|
+
}
|
83
|
+
return output.join('')
|
84
|
+
}
|
85
|
+
|
86
|
+
function fromByteArray (uint8) {
|
87
|
+
var tmp
|
88
|
+
var len = uint8.length
|
89
|
+
var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
|
90
|
+
var output = ''
|
91
|
+
var parts = []
|
92
|
+
var maxChunkLength = 16383 // must be multiple of 3
|
93
|
+
|
94
|
+
// go through the array every three bytes, we'll deal with trailing stuff later
|
95
|
+
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
|
96
|
+
parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
|
97
|
+
}
|
98
|
+
|
99
|
+
// pad the end with zeros, but make sure to not forget the extra bytes
|
100
|
+
if (extraBytes === 1) {
|
101
|
+
tmp = uint8[len - 1]
|
102
|
+
output += lookup[tmp >> 2]
|
103
|
+
output += lookup[(tmp << 4) & 0x3F]
|
104
|
+
output += '=='
|
105
|
+
} else if (extraBytes === 2) {
|
106
|
+
tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
|
107
|
+
output += lookup[tmp >> 10]
|
108
|
+
output += lookup[(tmp >> 4) & 0x3F]
|
109
|
+
output += lookup[(tmp << 2) & 0x3F]
|
110
|
+
output += '='
|
111
|
+
}
|
112
|
+
|
113
|
+
parts.push(output)
|
114
|
+
|
115
|
+
return parts.join('')
|
116
|
+
}
|
117
|
+
|
118
|
+
},{}],2:[function(require,module,exports){
|
119
|
+
|
120
|
+
},{}],3:[function(require,module,exports){
|
121
|
+
(function (global){
|
122
|
+
/*!
|
123
|
+
* The buffer module from node.js, for the browser.
|
124
|
+
*
|
125
|
+
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
|
126
|
+
* @license MIT
|
127
|
+
*/
|
128
|
+
/* eslint-disable no-proto */
|
129
|
+
|
130
|
+
'use strict'
|
131
|
+
|
132
|
+
var base64 = require('base64-js')
|
133
|
+
var ieee754 = require('ieee754')
|
134
|
+
var isArray = require('isarray')
|
135
|
+
|
136
|
+
exports.Buffer = Buffer
|
137
|
+
exports.SlowBuffer = SlowBuffer
|
138
|
+
exports.INSPECT_MAX_BYTES = 50
|
139
|
+
|
140
|
+
/**
|
141
|
+
* If `Buffer.TYPED_ARRAY_SUPPORT`:
|
142
|
+
* === true Use Uint8Array implementation (fastest)
|
143
|
+
* === false Use Object implementation (most compatible, even IE6)
|
144
|
+
*
|
145
|
+
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
|
146
|
+
* Opera 11.6+, iOS 4.2+.
|
147
|
+
*
|
148
|
+
* Due to various browser bugs, sometimes the Object implementation will be used even
|
149
|
+
* when the browser supports typed arrays.
|
150
|
+
*
|
151
|
+
* Note:
|
152
|
+
*
|
153
|
+
* - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
|
154
|
+
* See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
|
155
|
+
*
|
156
|
+
* - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
|
157
|
+
*
|
158
|
+
* - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
|
159
|
+
* incorrect length in some situations.
|
160
|
+
|
161
|
+
* We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
|
162
|
+
* get the Object implementation, which is slower but behaves correctly.
|
163
|
+
*/
|
164
|
+
Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
|
165
|
+
? global.TYPED_ARRAY_SUPPORT
|
166
|
+
: typedArraySupport()
|
167
|
+
|
168
|
+
/*
|
169
|
+
* Export kMaxLength after typed array support is determined.
|
170
|
+
*/
|
171
|
+
exports.kMaxLength = kMaxLength()
|
172
|
+
|
173
|
+
function typedArraySupport () {
|
174
|
+
try {
|
175
|
+
var arr = new Uint8Array(1)
|
176
|
+
arr.foo = function () { return 42 }
|
177
|
+
return arr.foo() === 42 && // typed array instances can be augmented
|
178
|
+
typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
|
179
|
+
arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
|
180
|
+
} catch (e) {
|
181
|
+
return false
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
function kMaxLength () {
|
186
|
+
return Buffer.TYPED_ARRAY_SUPPORT
|
187
|
+
? 0x7fffffff
|
188
|
+
: 0x3fffffff
|
189
|
+
}
|
190
|
+
|
191
|
+
function createBuffer (that, length) {
|
192
|
+
if (kMaxLength() < length) {
|
193
|
+
throw new RangeError('Invalid typed array length')
|
194
|
+
}
|
195
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
196
|
+
// Return an augmented `Uint8Array` instance, for best performance
|
197
|
+
that = new Uint8Array(length)
|
198
|
+
that.__proto__ = Buffer.prototype
|
199
|
+
} else {
|
200
|
+
// Fallback: Return an object instance of the Buffer class
|
201
|
+
if (that === null) {
|
202
|
+
that = new Buffer(length)
|
203
|
+
}
|
204
|
+
that.length = length
|
205
|
+
}
|
206
|
+
|
207
|
+
return that
|
208
|
+
}
|
209
|
+
|
210
|
+
/**
|
211
|
+
* The Buffer constructor returns instances of `Uint8Array` that have their
|
212
|
+
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
|
213
|
+
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
|
214
|
+
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
|
215
|
+
* returns a single octet.
|
216
|
+
*
|
217
|
+
* The `Uint8Array` prototype remains unmodified.
|
218
|
+
*/
|
219
|
+
|
220
|
+
function Buffer (arg, encodingOrOffset, length) {
|
221
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
|
222
|
+
return new Buffer(arg, encodingOrOffset, length)
|
223
|
+
}
|
224
|
+
|
225
|
+
// Common case.
|
226
|
+
if (typeof arg === 'number') {
|
227
|
+
if (typeof encodingOrOffset === 'string') {
|
228
|
+
throw new Error(
|
229
|
+
'If encoding is specified then the first argument must be a string'
|
230
|
+
)
|
231
|
+
}
|
232
|
+
return allocUnsafe(this, arg)
|
233
|
+
}
|
234
|
+
return from(this, arg, encodingOrOffset, length)
|
235
|
+
}
|
236
|
+
|
237
|
+
Buffer.poolSize = 8192 // not used by this implementation
|
238
|
+
|
239
|
+
// TODO: Legacy, not needed anymore. Remove in next major version.
|
240
|
+
Buffer._augment = function (arr) {
|
241
|
+
arr.__proto__ = Buffer.prototype
|
242
|
+
return arr
|
243
|
+
}
|
244
|
+
|
245
|
+
function from (that, value, encodingOrOffset, length) {
|
246
|
+
if (typeof value === 'number') {
|
247
|
+
throw new TypeError('"value" argument must not be a number')
|
248
|
+
}
|
249
|
+
|
250
|
+
if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
|
251
|
+
return fromArrayBuffer(that, value, encodingOrOffset, length)
|
252
|
+
}
|
253
|
+
|
254
|
+
if (typeof value === 'string') {
|
255
|
+
return fromString(that, value, encodingOrOffset)
|
256
|
+
}
|
257
|
+
|
258
|
+
return fromObject(that, value)
|
259
|
+
}
|
260
|
+
|
261
|
+
/**
|
262
|
+
* Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
|
263
|
+
* if value is a number.
|
264
|
+
* Buffer.from(str[, encoding])
|
265
|
+
* Buffer.from(array)
|
266
|
+
* Buffer.from(buffer)
|
267
|
+
* Buffer.from(arrayBuffer[, byteOffset[, length]])
|
268
|
+
**/
|
269
|
+
Buffer.from = function (value, encodingOrOffset, length) {
|
270
|
+
return from(null, value, encodingOrOffset, length)
|
271
|
+
}
|
272
|
+
|
273
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
274
|
+
Buffer.prototype.__proto__ = Uint8Array.prototype
|
275
|
+
Buffer.__proto__ = Uint8Array
|
276
|
+
if (typeof Symbol !== 'undefined' && Symbol.species &&
|
277
|
+
Buffer[Symbol.species] === Buffer) {
|
278
|
+
// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
|
279
|
+
Object.defineProperty(Buffer, Symbol.species, {
|
280
|
+
value: null,
|
281
|
+
configurable: true
|
282
|
+
})
|
283
|
+
}
|
284
|
+
}
|
285
|
+
|
286
|
+
function assertSize (size) {
|
287
|
+
if (typeof size !== 'number') {
|
288
|
+
throw new TypeError('"size" argument must be a number')
|
289
|
+
}
|
290
|
+
}
|
291
|
+
|
292
|
+
function alloc (that, size, fill, encoding) {
|
293
|
+
assertSize(size)
|
294
|
+
if (size <= 0) {
|
295
|
+
return createBuffer(that, size)
|
296
|
+
}
|
297
|
+
if (fill !== undefined) {
|
298
|
+
// Only pay attention to encoding if it's a string. This
|
299
|
+
// prevents accidentally sending in a number that would
|
300
|
+
// be interpretted as a start offset.
|
301
|
+
return typeof encoding === 'string'
|
302
|
+
? createBuffer(that, size).fill(fill, encoding)
|
303
|
+
: createBuffer(that, size).fill(fill)
|
304
|
+
}
|
305
|
+
return createBuffer(that, size)
|
306
|
+
}
|
307
|
+
|
308
|
+
/**
|
309
|
+
* Creates a new filled Buffer instance.
|
310
|
+
* alloc(size[, fill[, encoding]])
|
311
|
+
**/
|
312
|
+
Buffer.alloc = function (size, fill, encoding) {
|
313
|
+
return alloc(null, size, fill, encoding)
|
314
|
+
}
|
315
|
+
|
316
|
+
function allocUnsafe (that, size) {
|
317
|
+
assertSize(size)
|
318
|
+
that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
|
319
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT) {
|
320
|
+
for (var i = 0; i < size; i++) {
|
321
|
+
that[i] = 0
|
322
|
+
}
|
323
|
+
}
|
324
|
+
return that
|
325
|
+
}
|
326
|
+
|
327
|
+
/**
|
328
|
+
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
|
329
|
+
* */
|
330
|
+
Buffer.allocUnsafe = function (size) {
|
331
|
+
return allocUnsafe(null, size)
|
332
|
+
}
|
333
|
+
/**
|
334
|
+
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
335
|
+
*/
|
336
|
+
Buffer.allocUnsafeSlow = function (size) {
|
337
|
+
return allocUnsafe(null, size)
|
338
|
+
}
|
339
|
+
|
340
|
+
function fromString (that, string, encoding) {
|
341
|
+
if (typeof encoding !== 'string' || encoding === '') {
|
342
|
+
encoding = 'utf8'
|
343
|
+
}
|
344
|
+
|
345
|
+
if (!Buffer.isEncoding(encoding)) {
|
346
|
+
throw new TypeError('"encoding" must be a valid string encoding')
|
347
|
+
}
|
348
|
+
|
349
|
+
var length = byteLength(string, encoding) | 0
|
350
|
+
that = createBuffer(that, length)
|
351
|
+
|
352
|
+
that.write(string, encoding)
|
353
|
+
return that
|
354
|
+
}
|
355
|
+
|
356
|
+
function fromArrayLike (that, array) {
|
357
|
+
var length = checked(array.length) | 0
|
358
|
+
that = createBuffer(that, length)
|
359
|
+
for (var i = 0; i < length; i += 1) {
|
360
|
+
that[i] = array[i] & 255
|
361
|
+
}
|
362
|
+
return that
|
363
|
+
}
|
364
|
+
|
365
|
+
function fromArrayBuffer (that, array, byteOffset, length) {
|
366
|
+
array.byteLength // this throws if `array` is not a valid ArrayBuffer
|
367
|
+
|
368
|
+
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
369
|
+
throw new RangeError('\'offset\' is out of bounds')
|
370
|
+
}
|
371
|
+
|
372
|
+
if (array.byteLength < byteOffset + (length || 0)) {
|
373
|
+
throw new RangeError('\'length\' is out of bounds')
|
374
|
+
}
|
375
|
+
|
376
|
+
if (length === undefined) {
|
377
|
+
array = new Uint8Array(array, byteOffset)
|
378
|
+
} else {
|
379
|
+
array = new Uint8Array(array, byteOffset, length)
|
380
|
+
}
|
381
|
+
|
382
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
383
|
+
// Return an augmented `Uint8Array` instance, for best performance
|
384
|
+
that = array
|
385
|
+
that.__proto__ = Buffer.prototype
|
386
|
+
} else {
|
387
|
+
// Fallback: Return an object instance of the Buffer class
|
388
|
+
that = fromArrayLike(that, array)
|
389
|
+
}
|
390
|
+
return that
|
391
|
+
}
|
392
|
+
|
393
|
+
function fromObject (that, obj) {
|
394
|
+
if (Buffer.isBuffer(obj)) {
|
395
|
+
var len = checked(obj.length) | 0
|
396
|
+
that = createBuffer(that, len)
|
397
|
+
|
398
|
+
if (that.length === 0) {
|
399
|
+
return that
|
400
|
+
}
|
401
|
+
|
402
|
+
obj.copy(that, 0, 0, len)
|
403
|
+
return that
|
404
|
+
}
|
405
|
+
|
406
|
+
if (obj) {
|
407
|
+
if ((typeof ArrayBuffer !== 'undefined' &&
|
408
|
+
obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
|
409
|
+
if (typeof obj.length !== 'number' || isnan(obj.length)) {
|
410
|
+
return createBuffer(that, 0)
|
411
|
+
}
|
412
|
+
return fromArrayLike(that, obj)
|
413
|
+
}
|
414
|
+
|
415
|
+
if (obj.type === 'Buffer' && isArray(obj.data)) {
|
416
|
+
return fromArrayLike(that, obj.data)
|
417
|
+
}
|
418
|
+
}
|
419
|
+
|
420
|
+
throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
|
421
|
+
}
|
422
|
+
|
423
|
+
function checked (length) {
|
424
|
+
// Note: cannot use `length < kMaxLength` here because that fails when
|
425
|
+
// length is NaN (which is otherwise coerced to zero.)
|
426
|
+
if (length >= kMaxLength()) {
|
427
|
+
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
|
428
|
+
'size: 0x' + kMaxLength().toString(16) + ' bytes')
|
429
|
+
}
|
430
|
+
return length | 0
|
431
|
+
}
|
432
|
+
|
433
|
+
function SlowBuffer (length) {
|
434
|
+
if (+length != length) { // eslint-disable-line eqeqeq
|
435
|
+
length = 0
|
436
|
+
}
|
437
|
+
return Buffer.alloc(+length)
|
438
|
+
}
|
439
|
+
|
440
|
+
Buffer.isBuffer = function isBuffer (b) {
|
441
|
+
return !!(b != null && b._isBuffer)
|
442
|
+
}
|
443
|
+
|
444
|
+
Buffer.compare = function compare (a, b) {
|
445
|
+
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
|
446
|
+
throw new TypeError('Arguments must be Buffers')
|
447
|
+
}
|
448
|
+
|
449
|
+
if (a === b) return 0
|
450
|
+
|
451
|
+
var x = a.length
|
452
|
+
var y = b.length
|
453
|
+
|
454
|
+
for (var i = 0, len = Math.min(x, y); i < len; ++i) {
|
455
|
+
if (a[i] !== b[i]) {
|
456
|
+
x = a[i]
|
457
|
+
y = b[i]
|
458
|
+
break
|
459
|
+
}
|
460
|
+
}
|
461
|
+
|
462
|
+
if (x < y) return -1
|
463
|
+
if (y < x) return 1
|
464
|
+
return 0
|
465
|
+
}
|
466
|
+
|
467
|
+
Buffer.isEncoding = function isEncoding (encoding) {
|
468
|
+
switch (String(encoding).toLowerCase()) {
|
469
|
+
case 'hex':
|
470
|
+
case 'utf8':
|
471
|
+
case 'utf-8':
|
472
|
+
case 'ascii':
|
473
|
+
case 'binary':
|
474
|
+
case 'base64':
|
475
|
+
case 'raw':
|
476
|
+
case 'ucs2':
|
477
|
+
case 'ucs-2':
|
478
|
+
case 'utf16le':
|
479
|
+
case 'utf-16le':
|
480
|
+
return true
|
481
|
+
default:
|
482
|
+
return false
|
483
|
+
}
|
484
|
+
}
|
485
|
+
|
486
|
+
Buffer.concat = function concat (list, length) {
|
487
|
+
if (!isArray(list)) {
|
488
|
+
throw new TypeError('"list" argument must be an Array of Buffers')
|
489
|
+
}
|
490
|
+
|
491
|
+
if (list.length === 0) {
|
492
|
+
return Buffer.alloc(0)
|
493
|
+
}
|
494
|
+
|
495
|
+
var i
|
496
|
+
if (length === undefined) {
|
497
|
+
length = 0
|
498
|
+
for (i = 0; i < list.length; i++) {
|
499
|
+
length += list[i].length
|
500
|
+
}
|
501
|
+
}
|
502
|
+
|
503
|
+
var buffer = Buffer.allocUnsafe(length)
|
504
|
+
var pos = 0
|
505
|
+
for (i = 0; i < list.length; i++) {
|
506
|
+
var buf = list[i]
|
507
|
+
if (!Buffer.isBuffer(buf)) {
|
508
|
+
throw new TypeError('"list" argument must be an Array of Buffers')
|
509
|
+
}
|
510
|
+
buf.copy(buffer, pos)
|
511
|
+
pos += buf.length
|
512
|
+
}
|
513
|
+
return buffer
|
514
|
+
}
|
515
|
+
|
516
|
+
function byteLength (string, encoding) {
|
517
|
+
if (Buffer.isBuffer(string)) {
|
518
|
+
return string.length
|
519
|
+
}
|
520
|
+
if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
|
521
|
+
(ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
|
522
|
+
return string.byteLength
|
523
|
+
}
|
524
|
+
if (typeof string !== 'string') {
|
525
|
+
string = '' + string
|
526
|
+
}
|
527
|
+
|
528
|
+
var len = string.length
|
529
|
+
if (len === 0) return 0
|
530
|
+
|
531
|
+
// Use a for loop to avoid recursion
|
532
|
+
var loweredCase = false
|
533
|
+
for (;;) {
|
534
|
+
switch (encoding) {
|
535
|
+
case 'ascii':
|
536
|
+
case 'binary':
|
537
|
+
// Deprecated
|
538
|
+
case 'raw':
|
539
|
+
case 'raws':
|
540
|
+
return len
|
541
|
+
case 'utf8':
|
542
|
+
case 'utf-8':
|
543
|
+
case undefined:
|
544
|
+
return utf8ToBytes(string).length
|
545
|
+
case 'ucs2':
|
546
|
+
case 'ucs-2':
|
547
|
+
case 'utf16le':
|
548
|
+
case 'utf-16le':
|
549
|
+
return len * 2
|
550
|
+
case 'hex':
|
551
|
+
return len >>> 1
|
552
|
+
case 'base64':
|
553
|
+
return base64ToBytes(string).length
|
554
|
+
default:
|
555
|
+
if (loweredCase) return utf8ToBytes(string).length // assume utf8
|
556
|
+
encoding = ('' + encoding).toLowerCase()
|
557
|
+
loweredCase = true
|
558
|
+
}
|
559
|
+
}
|
560
|
+
}
|
561
|
+
Buffer.byteLength = byteLength
|
562
|
+
|
563
|
+
function slowToString (encoding, start, end) {
|
564
|
+
var loweredCase = false
|
565
|
+
|
566
|
+
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
|
567
|
+
// property of a typed array.
|
568
|
+
|
569
|
+
// This behaves neither like String nor Uint8Array in that we set start/end
|
570
|
+
// to their upper/lower bounds if the value passed is out of range.
|
571
|
+
// undefined is handled specially as per ECMA-262 6th Edition,
|
572
|
+
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
|
573
|
+
if (start === undefined || start < 0) {
|
574
|
+
start = 0
|
575
|
+
}
|
576
|
+
// Return early if start > this.length. Done here to prevent potential uint32
|
577
|
+
// coercion fail below.
|
578
|
+
if (start > this.length) {
|
579
|
+
return ''
|
580
|
+
}
|
581
|
+
|
582
|
+
if (end === undefined || end > this.length) {
|
583
|
+
end = this.length
|
584
|
+
}
|
585
|
+
|
586
|
+
if (end <= 0) {
|
587
|
+
return ''
|
588
|
+
}
|
589
|
+
|
590
|
+
// Force coersion to uint32. This will also coerce falsey/NaN values to 0.
|
591
|
+
end >>>= 0
|
592
|
+
start >>>= 0
|
593
|
+
|
594
|
+
if (end <= start) {
|
595
|
+
return ''
|
596
|
+
}
|
597
|
+
|
598
|
+
if (!encoding) encoding = 'utf8'
|
599
|
+
|
600
|
+
while (true) {
|
601
|
+
switch (encoding) {
|
602
|
+
case 'hex':
|
603
|
+
return hexSlice(this, start, end)
|
604
|
+
|
605
|
+
case 'utf8':
|
606
|
+
case 'utf-8':
|
607
|
+
return utf8Slice(this, start, end)
|
608
|
+
|
609
|
+
case 'ascii':
|
610
|
+
return asciiSlice(this, start, end)
|
611
|
+
|
612
|
+
case 'binary':
|
613
|
+
return binarySlice(this, start, end)
|
614
|
+
|
615
|
+
case 'base64':
|
616
|
+
return base64Slice(this, start, end)
|
617
|
+
|
618
|
+
case 'ucs2':
|
619
|
+
case 'ucs-2':
|
620
|
+
case 'utf16le':
|
621
|
+
case 'utf-16le':
|
622
|
+
return utf16leSlice(this, start, end)
|
623
|
+
|
624
|
+
default:
|
625
|
+
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
626
|
+
encoding = (encoding + '').toLowerCase()
|
627
|
+
loweredCase = true
|
628
|
+
}
|
629
|
+
}
|
630
|
+
}
|
631
|
+
|
632
|
+
// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
|
633
|
+
// Buffer instances.
|
634
|
+
Buffer.prototype._isBuffer = true
|
635
|
+
|
636
|
+
function swap (b, n, m) {
|
637
|
+
var i = b[n]
|
638
|
+
b[n] = b[m]
|
639
|
+
b[m] = i
|
640
|
+
}
|
641
|
+
|
642
|
+
Buffer.prototype.swap16 = function swap16 () {
|
643
|
+
var len = this.length
|
644
|
+
if (len % 2 !== 0) {
|
645
|
+
throw new RangeError('Buffer size must be a multiple of 16-bits')
|
646
|
+
}
|
647
|
+
for (var i = 0; i < len; i += 2) {
|
648
|
+
swap(this, i, i + 1)
|
649
|
+
}
|
650
|
+
return this
|
651
|
+
}
|
652
|
+
|
653
|
+
Buffer.prototype.swap32 = function swap32 () {
|
654
|
+
var len = this.length
|
655
|
+
if (len % 4 !== 0) {
|
656
|
+
throw new RangeError('Buffer size must be a multiple of 32-bits')
|
657
|
+
}
|
658
|
+
for (var i = 0; i < len; i += 4) {
|
659
|
+
swap(this, i, i + 3)
|
660
|
+
swap(this, i + 1, i + 2)
|
661
|
+
}
|
662
|
+
return this
|
663
|
+
}
|
664
|
+
|
665
|
+
Buffer.prototype.toString = function toString () {
|
666
|
+
var length = this.length | 0
|
667
|
+
if (length === 0) return ''
|
668
|
+
if (arguments.length === 0) return utf8Slice(this, 0, length)
|
669
|
+
return slowToString.apply(this, arguments)
|
670
|
+
}
|
671
|
+
|
672
|
+
Buffer.prototype.equals = function equals (b) {
|
673
|
+
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
|
674
|
+
if (this === b) return true
|
675
|
+
return Buffer.compare(this, b) === 0
|
676
|
+
}
|
677
|
+
|
678
|
+
Buffer.prototype.inspect = function inspect () {
|
679
|
+
var str = ''
|
680
|
+
var max = exports.INSPECT_MAX_BYTES
|
681
|
+
if (this.length > 0) {
|
682
|
+
str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
|
683
|
+
if (this.length > max) str += ' ... '
|
684
|
+
}
|
685
|
+
return '<Buffer ' + str + '>'
|
686
|
+
}
|
687
|
+
|
688
|
+
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
|
689
|
+
if (!Buffer.isBuffer(target)) {
|
690
|
+
throw new TypeError('Argument must be a Buffer')
|
691
|
+
}
|
692
|
+
|
693
|
+
if (start === undefined) {
|
694
|
+
start = 0
|
695
|
+
}
|
696
|
+
if (end === undefined) {
|
697
|
+
end = target ? target.length : 0
|
698
|
+
}
|
699
|
+
if (thisStart === undefined) {
|
700
|
+
thisStart = 0
|
701
|
+
}
|
702
|
+
if (thisEnd === undefined) {
|
703
|
+
thisEnd = this.length
|
704
|
+
}
|
705
|
+
|
706
|
+
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
707
|
+
throw new RangeError('out of range index')
|
708
|
+
}
|
709
|
+
|
710
|
+
if (thisStart >= thisEnd && start >= end) {
|
711
|
+
return 0
|
712
|
+
}
|
713
|
+
if (thisStart >= thisEnd) {
|
714
|
+
return -1
|
715
|
+
}
|
716
|
+
if (start >= end) {
|
717
|
+
return 1
|
718
|
+
}
|
719
|
+
|
720
|
+
start >>>= 0
|
721
|
+
end >>>= 0
|
722
|
+
thisStart >>>= 0
|
723
|
+
thisEnd >>>= 0
|
724
|
+
|
725
|
+
if (this === target) return 0
|
726
|
+
|
727
|
+
var x = thisEnd - thisStart
|
728
|
+
var y = end - start
|
729
|
+
var len = Math.min(x, y)
|
730
|
+
|
731
|
+
var thisCopy = this.slice(thisStart, thisEnd)
|
732
|
+
var targetCopy = target.slice(start, end)
|
733
|
+
|
734
|
+
for (var i = 0; i < len; ++i) {
|
735
|
+
if (thisCopy[i] !== targetCopy[i]) {
|
736
|
+
x = thisCopy[i]
|
737
|
+
y = targetCopy[i]
|
738
|
+
break
|
739
|
+
}
|
740
|
+
}
|
741
|
+
|
742
|
+
if (x < y) return -1
|
743
|
+
if (y < x) return 1
|
744
|
+
return 0
|
745
|
+
}
|
746
|
+
|
747
|
+
function arrayIndexOf (arr, val, byteOffset, encoding) {
|
748
|
+
var indexSize = 1
|
749
|
+
var arrLength = arr.length
|
750
|
+
var valLength = val.length
|
751
|
+
|
752
|
+
if (encoding !== undefined) {
|
753
|
+
encoding = String(encoding).toLowerCase()
|
754
|
+
if (encoding === 'ucs2' || encoding === 'ucs-2' ||
|
755
|
+
encoding === 'utf16le' || encoding === 'utf-16le') {
|
756
|
+
if (arr.length < 2 || val.length < 2) {
|
757
|
+
return -1
|
758
|
+
}
|
759
|
+
indexSize = 2
|
760
|
+
arrLength /= 2
|
761
|
+
valLength /= 2
|
762
|
+
byteOffset /= 2
|
763
|
+
}
|
764
|
+
}
|
765
|
+
|
766
|
+
function read (buf, i) {
|
767
|
+
if (indexSize === 1) {
|
768
|
+
return buf[i]
|
769
|
+
} else {
|
770
|
+
return buf.readUInt16BE(i * indexSize)
|
771
|
+
}
|
772
|
+
}
|
773
|
+
|
774
|
+
var foundIndex = -1
|
775
|
+
for (var i = 0; byteOffset + i < arrLength; i++) {
|
776
|
+
if (read(arr, byteOffset + i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
777
|
+
if (foundIndex === -1) foundIndex = i
|
778
|
+
if (i - foundIndex + 1 === valLength) return (byteOffset + foundIndex) * indexSize
|
779
|
+
} else {
|
780
|
+
if (foundIndex !== -1) i -= i - foundIndex
|
781
|
+
foundIndex = -1
|
782
|
+
}
|
783
|
+
}
|
784
|
+
return -1
|
785
|
+
}
|
786
|
+
|
787
|
+
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
|
788
|
+
if (typeof byteOffset === 'string') {
|
789
|
+
encoding = byteOffset
|
790
|
+
byteOffset = 0
|
791
|
+
} else if (byteOffset > 0x7fffffff) {
|
792
|
+
byteOffset = 0x7fffffff
|
793
|
+
} else if (byteOffset < -0x80000000) {
|
794
|
+
byteOffset = -0x80000000
|
795
|
+
}
|
796
|
+
byteOffset >>= 0
|
797
|
+
|
798
|
+
if (this.length === 0) return -1
|
799
|
+
if (byteOffset >= this.length) return -1
|
800
|
+
|
801
|
+
// Negative offsets start from the end of the buffer
|
802
|
+
if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0)
|
803
|
+
|
804
|
+
if (typeof val === 'string') {
|
805
|
+
val = Buffer.from(val, encoding)
|
806
|
+
}
|
807
|
+
|
808
|
+
if (Buffer.isBuffer(val)) {
|
809
|
+
// special case: looking for empty string/buffer always fails
|
810
|
+
if (val.length === 0) {
|
811
|
+
return -1
|
812
|
+
}
|
813
|
+
return arrayIndexOf(this, val, byteOffset, encoding)
|
814
|
+
}
|
815
|
+
if (typeof val === 'number') {
|
816
|
+
if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') {
|
817
|
+
return Uint8Array.prototype.indexOf.call(this, val, byteOffset)
|
818
|
+
}
|
819
|
+
return arrayIndexOf(this, [ val ], byteOffset, encoding)
|
820
|
+
}
|
821
|
+
|
822
|
+
throw new TypeError('val must be string, number or Buffer')
|
823
|
+
}
|
824
|
+
|
825
|
+
Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
|
826
|
+
return this.indexOf(val, byteOffset, encoding) !== -1
|
827
|
+
}
|
828
|
+
|
829
|
+
function hexWrite (buf, string, offset, length) {
|
830
|
+
offset = Number(offset) || 0
|
831
|
+
var remaining = buf.length - offset
|
832
|
+
if (!length) {
|
833
|
+
length = remaining
|
834
|
+
} else {
|
835
|
+
length = Number(length)
|
836
|
+
if (length > remaining) {
|
837
|
+
length = remaining
|
838
|
+
}
|
839
|
+
}
|
840
|
+
|
841
|
+
// must be an even number of digits
|
842
|
+
var strLen = string.length
|
843
|
+
if (strLen % 2 !== 0) throw new Error('Invalid hex string')
|
844
|
+
|
845
|
+
if (length > strLen / 2) {
|
846
|
+
length = strLen / 2
|
847
|
+
}
|
848
|
+
for (var i = 0; i < length; i++) {
|
849
|
+
var parsed = parseInt(string.substr(i * 2, 2), 16)
|
850
|
+
if (isNaN(parsed)) return i
|
851
|
+
buf[offset + i] = parsed
|
852
|
+
}
|
853
|
+
return i
|
854
|
+
}
|
855
|
+
|
856
|
+
function utf8Write (buf, string, offset, length) {
|
857
|
+
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
|
858
|
+
}
|
859
|
+
|
860
|
+
function asciiWrite (buf, string, offset, length) {
|
861
|
+
return blitBuffer(asciiToBytes(string), buf, offset, length)
|
862
|
+
}
|
863
|
+
|
864
|
+
function binaryWrite (buf, string, offset, length) {
|
865
|
+
return asciiWrite(buf, string, offset, length)
|
866
|
+
}
|
867
|
+
|
868
|
+
function base64Write (buf, string, offset, length) {
|
869
|
+
return blitBuffer(base64ToBytes(string), buf, offset, length)
|
870
|
+
}
|
871
|
+
|
872
|
+
function ucs2Write (buf, string, offset, length) {
|
873
|
+
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
|
874
|
+
}
|
875
|
+
|
876
|
+
Buffer.prototype.write = function write (string, offset, length, encoding) {
|
877
|
+
// Buffer#write(string)
|
878
|
+
if (offset === undefined) {
|
879
|
+
encoding = 'utf8'
|
880
|
+
length = this.length
|
881
|
+
offset = 0
|
882
|
+
// Buffer#write(string, encoding)
|
883
|
+
} else if (length === undefined && typeof offset === 'string') {
|
884
|
+
encoding = offset
|
885
|
+
length = this.length
|
886
|
+
offset = 0
|
887
|
+
// Buffer#write(string, offset[, length][, encoding])
|
888
|
+
} else if (isFinite(offset)) {
|
889
|
+
offset = offset | 0
|
890
|
+
if (isFinite(length)) {
|
891
|
+
length = length | 0
|
892
|
+
if (encoding === undefined) encoding = 'utf8'
|
893
|
+
} else {
|
894
|
+
encoding = length
|
895
|
+
length = undefined
|
896
|
+
}
|
897
|
+
// legacy write(string, encoding, offset, length) - remove in v0.13
|
898
|
+
} else {
|
899
|
+
throw new Error(
|
900
|
+
'Buffer.write(string, encoding, offset[, length]) is no longer supported'
|
901
|
+
)
|
902
|
+
}
|
903
|
+
|
904
|
+
var remaining = this.length - offset
|
905
|
+
if (length === undefined || length > remaining) length = remaining
|
906
|
+
|
907
|
+
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
|
908
|
+
throw new RangeError('Attempt to write outside buffer bounds')
|
909
|
+
}
|
910
|
+
|
911
|
+
if (!encoding) encoding = 'utf8'
|
912
|
+
|
913
|
+
var loweredCase = false
|
914
|
+
for (;;) {
|
915
|
+
switch (encoding) {
|
916
|
+
case 'hex':
|
917
|
+
return hexWrite(this, string, offset, length)
|
918
|
+
|
919
|
+
case 'utf8':
|
920
|
+
case 'utf-8':
|
921
|
+
return utf8Write(this, string, offset, length)
|
922
|
+
|
923
|
+
case 'ascii':
|
924
|
+
return asciiWrite(this, string, offset, length)
|
925
|
+
|
926
|
+
case 'binary':
|
927
|
+
return binaryWrite(this, string, offset, length)
|
928
|
+
|
929
|
+
case 'base64':
|
930
|
+
// Warning: maxLength not taken into account in base64Write
|
931
|
+
return base64Write(this, string, offset, length)
|
932
|
+
|
933
|
+
case 'ucs2':
|
934
|
+
case 'ucs-2':
|
935
|
+
case 'utf16le':
|
936
|
+
case 'utf-16le':
|
937
|
+
return ucs2Write(this, string, offset, length)
|
938
|
+
|
939
|
+
default:
|
940
|
+
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
941
|
+
encoding = ('' + encoding).toLowerCase()
|
942
|
+
loweredCase = true
|
943
|
+
}
|
944
|
+
}
|
945
|
+
}
|
946
|
+
|
947
|
+
Buffer.prototype.toJSON = function toJSON () {
|
948
|
+
return {
|
949
|
+
type: 'Buffer',
|
950
|
+
data: Array.prototype.slice.call(this._arr || this, 0)
|
951
|
+
}
|
952
|
+
}
|
953
|
+
|
954
|
+
function base64Slice (buf, start, end) {
|
955
|
+
if (start === 0 && end === buf.length) {
|
956
|
+
return base64.fromByteArray(buf)
|
957
|
+
} else {
|
958
|
+
return base64.fromByteArray(buf.slice(start, end))
|
959
|
+
}
|
960
|
+
}
|
961
|
+
|
962
|
+
function utf8Slice (buf, start, end) {
|
963
|
+
end = Math.min(buf.length, end)
|
964
|
+
var res = []
|
965
|
+
|
966
|
+
var i = start
|
967
|
+
while (i < end) {
|
968
|
+
var firstByte = buf[i]
|
969
|
+
var codePoint = null
|
970
|
+
var bytesPerSequence = (firstByte > 0xEF) ? 4
|
971
|
+
: (firstByte > 0xDF) ? 3
|
972
|
+
: (firstByte > 0xBF) ? 2
|
973
|
+
: 1
|
974
|
+
|
975
|
+
if (i + bytesPerSequence <= end) {
|
976
|
+
var secondByte, thirdByte, fourthByte, tempCodePoint
|
977
|
+
|
978
|
+
switch (bytesPerSequence) {
|
979
|
+
case 1:
|
980
|
+
if (firstByte < 0x80) {
|
981
|
+
codePoint = firstByte
|
982
|
+
}
|
983
|
+
break
|
984
|
+
case 2:
|
985
|
+
secondByte = buf[i + 1]
|
986
|
+
if ((secondByte & 0xC0) === 0x80) {
|
987
|
+
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
|
988
|
+
if (tempCodePoint > 0x7F) {
|
989
|
+
codePoint = tempCodePoint
|
990
|
+
}
|
991
|
+
}
|
992
|
+
break
|
993
|
+
case 3:
|
994
|
+
secondByte = buf[i + 1]
|
995
|
+
thirdByte = buf[i + 2]
|
996
|
+
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
|
997
|
+
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
|
998
|
+
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
|
999
|
+
codePoint = tempCodePoint
|
1000
|
+
}
|
1001
|
+
}
|
1002
|
+
break
|
1003
|
+
case 4:
|
1004
|
+
secondByte = buf[i + 1]
|
1005
|
+
thirdByte = buf[i + 2]
|
1006
|
+
fourthByte = buf[i + 3]
|
1007
|
+
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
|
1008
|
+
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
|
1009
|
+
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
|
1010
|
+
codePoint = tempCodePoint
|
1011
|
+
}
|
1012
|
+
}
|
1013
|
+
}
|
1014
|
+
}
|
1015
|
+
|
1016
|
+
if (codePoint === null) {
|
1017
|
+
// we did not generate a valid codePoint so insert a
|
1018
|
+
// replacement char (U+FFFD) and advance only 1 byte
|
1019
|
+
codePoint = 0xFFFD
|
1020
|
+
bytesPerSequence = 1
|
1021
|
+
} else if (codePoint > 0xFFFF) {
|
1022
|
+
// encode to utf16 (surrogate pair dance)
|
1023
|
+
codePoint -= 0x10000
|
1024
|
+
res.push(codePoint >>> 10 & 0x3FF | 0xD800)
|
1025
|
+
codePoint = 0xDC00 | codePoint & 0x3FF
|
1026
|
+
}
|
1027
|
+
|
1028
|
+
res.push(codePoint)
|
1029
|
+
i += bytesPerSequence
|
1030
|
+
}
|
1031
|
+
|
1032
|
+
return decodeCodePointsArray(res)
|
1033
|
+
}
|
1034
|
+
|
1035
|
+
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
|
1036
|
+
// the lowest limit is Chrome, with 0x10000 args.
|
1037
|
+
// We go 1 magnitude less, for safety
|
1038
|
+
var MAX_ARGUMENTS_LENGTH = 0x1000
|
1039
|
+
|
1040
|
+
function decodeCodePointsArray (codePoints) {
|
1041
|
+
var len = codePoints.length
|
1042
|
+
if (len <= MAX_ARGUMENTS_LENGTH) {
|
1043
|
+
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
|
1044
|
+
}
|
1045
|
+
|
1046
|
+
// Decode in chunks to avoid "call stack size exceeded".
|
1047
|
+
var res = ''
|
1048
|
+
var i = 0
|
1049
|
+
while (i < len) {
|
1050
|
+
res += String.fromCharCode.apply(
|
1051
|
+
String,
|
1052
|
+
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
1053
|
+
)
|
1054
|
+
}
|
1055
|
+
return res
|
1056
|
+
}
|
1057
|
+
|
1058
|
+
function asciiSlice (buf, start, end) {
|
1059
|
+
var ret = ''
|
1060
|
+
end = Math.min(buf.length, end)
|
1061
|
+
|
1062
|
+
for (var i = start; i < end; i++) {
|
1063
|
+
ret += String.fromCharCode(buf[i] & 0x7F)
|
1064
|
+
}
|
1065
|
+
return ret
|
1066
|
+
}
|
1067
|
+
|
1068
|
+
function binarySlice (buf, start, end) {
|
1069
|
+
var ret = ''
|
1070
|
+
end = Math.min(buf.length, end)
|
1071
|
+
|
1072
|
+
for (var i = start; i < end; i++) {
|
1073
|
+
ret += String.fromCharCode(buf[i])
|
1074
|
+
}
|
1075
|
+
return ret
|
1076
|
+
}
|
1077
|
+
|
1078
|
+
function hexSlice (buf, start, end) {
|
1079
|
+
var len = buf.length
|
1080
|
+
|
1081
|
+
if (!start || start < 0) start = 0
|
1082
|
+
if (!end || end < 0 || end > len) end = len
|
1083
|
+
|
1084
|
+
var out = ''
|
1085
|
+
for (var i = start; i < end; i++) {
|
1086
|
+
out += toHex(buf[i])
|
1087
|
+
}
|
1088
|
+
return out
|
1089
|
+
}
|
1090
|
+
|
1091
|
+
function utf16leSlice (buf, start, end) {
|
1092
|
+
var bytes = buf.slice(start, end)
|
1093
|
+
var res = ''
|
1094
|
+
for (var i = 0; i < bytes.length; i += 2) {
|
1095
|
+
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
|
1096
|
+
}
|
1097
|
+
return res
|
1098
|
+
}
|
1099
|
+
|
1100
|
+
Buffer.prototype.slice = function slice (start, end) {
|
1101
|
+
var len = this.length
|
1102
|
+
start = ~~start
|
1103
|
+
end = end === undefined ? len : ~~end
|
1104
|
+
|
1105
|
+
if (start < 0) {
|
1106
|
+
start += len
|
1107
|
+
if (start < 0) start = 0
|
1108
|
+
} else if (start > len) {
|
1109
|
+
start = len
|
1110
|
+
}
|
1111
|
+
|
1112
|
+
if (end < 0) {
|
1113
|
+
end += len
|
1114
|
+
if (end < 0) end = 0
|
1115
|
+
} else if (end > len) {
|
1116
|
+
end = len
|
1117
|
+
}
|
1118
|
+
|
1119
|
+
if (end < start) end = start
|
1120
|
+
|
1121
|
+
var newBuf
|
1122
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
1123
|
+
newBuf = this.subarray(start, end)
|
1124
|
+
newBuf.__proto__ = Buffer.prototype
|
1125
|
+
} else {
|
1126
|
+
var sliceLen = end - start
|
1127
|
+
newBuf = new Buffer(sliceLen, undefined)
|
1128
|
+
for (var i = 0; i < sliceLen; i++) {
|
1129
|
+
newBuf[i] = this[i + start]
|
1130
|
+
}
|
1131
|
+
}
|
1132
|
+
|
1133
|
+
return newBuf
|
1134
|
+
}
|
1135
|
+
|
1136
|
+
/*
|
1137
|
+
* Need to make sure that buffer isn't trying to write out of bounds.
|
1138
|
+
*/
|
1139
|
+
function checkOffset (offset, ext, length) {
|
1140
|
+
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
|
1141
|
+
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
|
1142
|
+
}
|
1143
|
+
|
1144
|
+
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
|
1145
|
+
offset = offset | 0
|
1146
|
+
byteLength = byteLength | 0
|
1147
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length)
|
1148
|
+
|
1149
|
+
var val = this[offset]
|
1150
|
+
var mul = 1
|
1151
|
+
var i = 0
|
1152
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
1153
|
+
val += this[offset + i] * mul
|
1154
|
+
}
|
1155
|
+
|
1156
|
+
return val
|
1157
|
+
}
|
1158
|
+
|
1159
|
+
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
|
1160
|
+
offset = offset | 0
|
1161
|
+
byteLength = byteLength | 0
|
1162
|
+
if (!noAssert) {
|
1163
|
+
checkOffset(offset, byteLength, this.length)
|
1164
|
+
}
|
1165
|
+
|
1166
|
+
var val = this[offset + --byteLength]
|
1167
|
+
var mul = 1
|
1168
|
+
while (byteLength > 0 && (mul *= 0x100)) {
|
1169
|
+
val += this[offset + --byteLength] * mul
|
1170
|
+
}
|
1171
|
+
|
1172
|
+
return val
|
1173
|
+
}
|
1174
|
+
|
1175
|
+
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
|
1176
|
+
if (!noAssert) checkOffset(offset, 1, this.length)
|
1177
|
+
return this[offset]
|
1178
|
+
}
|
1179
|
+
|
1180
|
+
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
|
1181
|
+
if (!noAssert) checkOffset(offset, 2, this.length)
|
1182
|
+
return this[offset] | (this[offset + 1] << 8)
|
1183
|
+
}
|
1184
|
+
|
1185
|
+
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
|
1186
|
+
if (!noAssert) checkOffset(offset, 2, this.length)
|
1187
|
+
return (this[offset] << 8) | this[offset + 1]
|
1188
|
+
}
|
1189
|
+
|
1190
|
+
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
|
1191
|
+
if (!noAssert) checkOffset(offset, 4, this.length)
|
1192
|
+
|
1193
|
+
return ((this[offset]) |
|
1194
|
+
(this[offset + 1] << 8) |
|
1195
|
+
(this[offset + 2] << 16)) +
|
1196
|
+
(this[offset + 3] * 0x1000000)
|
1197
|
+
}
|
1198
|
+
|
1199
|
+
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
|
1200
|
+
if (!noAssert) checkOffset(offset, 4, this.length)
|
1201
|
+
|
1202
|
+
return (this[offset] * 0x1000000) +
|
1203
|
+
((this[offset + 1] << 16) |
|
1204
|
+
(this[offset + 2] << 8) |
|
1205
|
+
this[offset + 3])
|
1206
|
+
}
|
1207
|
+
|
1208
|
+
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
|
1209
|
+
offset = offset | 0
|
1210
|
+
byteLength = byteLength | 0
|
1211
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length)
|
1212
|
+
|
1213
|
+
var val = this[offset]
|
1214
|
+
var mul = 1
|
1215
|
+
var i = 0
|
1216
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
1217
|
+
val += this[offset + i] * mul
|
1218
|
+
}
|
1219
|
+
mul *= 0x80
|
1220
|
+
|
1221
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength)
|
1222
|
+
|
1223
|
+
return val
|
1224
|
+
}
|
1225
|
+
|
1226
|
+
Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
|
1227
|
+
offset = offset | 0
|
1228
|
+
byteLength = byteLength | 0
|
1229
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length)
|
1230
|
+
|
1231
|
+
var i = byteLength
|
1232
|
+
var mul = 1
|
1233
|
+
var val = this[offset + --i]
|
1234
|
+
while (i > 0 && (mul *= 0x100)) {
|
1235
|
+
val += this[offset + --i] * mul
|
1236
|
+
}
|
1237
|
+
mul *= 0x80
|
1238
|
+
|
1239
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength)
|
1240
|
+
|
1241
|
+
return val
|
1242
|
+
}
|
1243
|
+
|
1244
|
+
Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
|
1245
|
+
if (!noAssert) checkOffset(offset, 1, this.length)
|
1246
|
+
if (!(this[offset] & 0x80)) return (this[offset])
|
1247
|
+
return ((0xff - this[offset] + 1) * -1)
|
1248
|
+
}
|
1249
|
+
|
1250
|
+
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
|
1251
|
+
if (!noAssert) checkOffset(offset, 2, this.length)
|
1252
|
+
var val = this[offset] | (this[offset + 1] << 8)
|
1253
|
+
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
1254
|
+
}
|
1255
|
+
|
1256
|
+
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
|
1257
|
+
if (!noAssert) checkOffset(offset, 2, this.length)
|
1258
|
+
var val = this[offset + 1] | (this[offset] << 8)
|
1259
|
+
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
1260
|
+
}
|
1261
|
+
|
1262
|
+
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
|
1263
|
+
if (!noAssert) checkOffset(offset, 4, this.length)
|
1264
|
+
|
1265
|
+
return (this[offset]) |
|
1266
|
+
(this[offset + 1] << 8) |
|
1267
|
+
(this[offset + 2] << 16) |
|
1268
|
+
(this[offset + 3] << 24)
|
1269
|
+
}
|
1270
|
+
|
1271
|
+
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
|
1272
|
+
if (!noAssert) checkOffset(offset, 4, this.length)
|
1273
|
+
|
1274
|
+
return (this[offset] << 24) |
|
1275
|
+
(this[offset + 1] << 16) |
|
1276
|
+
(this[offset + 2] << 8) |
|
1277
|
+
(this[offset + 3])
|
1278
|
+
}
|
1279
|
+
|
1280
|
+
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
|
1281
|
+
if (!noAssert) checkOffset(offset, 4, this.length)
|
1282
|
+
return ieee754.read(this, offset, true, 23, 4)
|
1283
|
+
}
|
1284
|
+
|
1285
|
+
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
|
1286
|
+
if (!noAssert) checkOffset(offset, 4, this.length)
|
1287
|
+
return ieee754.read(this, offset, false, 23, 4)
|
1288
|
+
}
|
1289
|
+
|
1290
|
+
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
|
1291
|
+
if (!noAssert) checkOffset(offset, 8, this.length)
|
1292
|
+
return ieee754.read(this, offset, true, 52, 8)
|
1293
|
+
}
|
1294
|
+
|
1295
|
+
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
|
1296
|
+
if (!noAssert) checkOffset(offset, 8, this.length)
|
1297
|
+
return ieee754.read(this, offset, false, 52, 8)
|
1298
|
+
}
|
1299
|
+
|
1300
|
+
function checkInt (buf, value, offset, ext, max, min) {
|
1301
|
+
if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
|
1302
|
+
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
|
1303
|
+
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
1304
|
+
}
|
1305
|
+
|
1306
|
+
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
|
1307
|
+
value = +value
|
1308
|
+
offset = offset | 0
|
1309
|
+
byteLength = byteLength | 0
|
1310
|
+
if (!noAssert) {
|
1311
|
+
var maxBytes = Math.pow(2, 8 * byteLength) - 1
|
1312
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0)
|
1313
|
+
}
|
1314
|
+
|
1315
|
+
var mul = 1
|
1316
|
+
var i = 0
|
1317
|
+
this[offset] = value & 0xFF
|
1318
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
1319
|
+
this[offset + i] = (value / mul) & 0xFF
|
1320
|
+
}
|
1321
|
+
|
1322
|
+
return offset + byteLength
|
1323
|
+
}
|
1324
|
+
|
1325
|
+
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
|
1326
|
+
value = +value
|
1327
|
+
offset = offset | 0
|
1328
|
+
byteLength = byteLength | 0
|
1329
|
+
if (!noAssert) {
|
1330
|
+
var maxBytes = Math.pow(2, 8 * byteLength) - 1
|
1331
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0)
|
1332
|
+
}
|
1333
|
+
|
1334
|
+
var i = byteLength - 1
|
1335
|
+
var mul = 1
|
1336
|
+
this[offset + i] = value & 0xFF
|
1337
|
+
while (--i >= 0 && (mul *= 0x100)) {
|
1338
|
+
this[offset + i] = (value / mul) & 0xFF
|
1339
|
+
}
|
1340
|
+
|
1341
|
+
return offset + byteLength
|
1342
|
+
}
|
1343
|
+
|
1344
|
+
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
|
1345
|
+
value = +value
|
1346
|
+
offset = offset | 0
|
1347
|
+
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
|
1348
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
|
1349
|
+
this[offset] = (value & 0xff)
|
1350
|
+
return offset + 1
|
1351
|
+
}
|
1352
|
+
|
1353
|
+
function objectWriteUInt16 (buf, value, offset, littleEndian) {
|
1354
|
+
if (value < 0) value = 0xffff + value + 1
|
1355
|
+
for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) {
|
1356
|
+
buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
|
1357
|
+
(littleEndian ? i : 1 - i) * 8
|
1358
|
+
}
|
1359
|
+
}
|
1360
|
+
|
1361
|
+
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
|
1362
|
+
value = +value
|
1363
|
+
offset = offset | 0
|
1364
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
|
1365
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
1366
|
+
this[offset] = (value & 0xff)
|
1367
|
+
this[offset + 1] = (value >>> 8)
|
1368
|
+
} else {
|
1369
|
+
objectWriteUInt16(this, value, offset, true)
|
1370
|
+
}
|
1371
|
+
return offset + 2
|
1372
|
+
}
|
1373
|
+
|
1374
|
+
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
|
1375
|
+
value = +value
|
1376
|
+
offset = offset | 0
|
1377
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
|
1378
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
1379
|
+
this[offset] = (value >>> 8)
|
1380
|
+
this[offset + 1] = (value & 0xff)
|
1381
|
+
} else {
|
1382
|
+
objectWriteUInt16(this, value, offset, false)
|
1383
|
+
}
|
1384
|
+
return offset + 2
|
1385
|
+
}
|
1386
|
+
|
1387
|
+
function objectWriteUInt32 (buf, value, offset, littleEndian) {
|
1388
|
+
if (value < 0) value = 0xffffffff + value + 1
|
1389
|
+
for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) {
|
1390
|
+
buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
|
1391
|
+
}
|
1392
|
+
}
|
1393
|
+
|
1394
|
+
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
|
1395
|
+
value = +value
|
1396
|
+
offset = offset | 0
|
1397
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
|
1398
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
1399
|
+
this[offset + 3] = (value >>> 24)
|
1400
|
+
this[offset + 2] = (value >>> 16)
|
1401
|
+
this[offset + 1] = (value >>> 8)
|
1402
|
+
this[offset] = (value & 0xff)
|
1403
|
+
} else {
|
1404
|
+
objectWriteUInt32(this, value, offset, true)
|
1405
|
+
}
|
1406
|
+
return offset + 4
|
1407
|
+
}
|
1408
|
+
|
1409
|
+
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
|
1410
|
+
value = +value
|
1411
|
+
offset = offset | 0
|
1412
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
|
1413
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
1414
|
+
this[offset] = (value >>> 24)
|
1415
|
+
this[offset + 1] = (value >>> 16)
|
1416
|
+
this[offset + 2] = (value >>> 8)
|
1417
|
+
this[offset + 3] = (value & 0xff)
|
1418
|
+
} else {
|
1419
|
+
objectWriteUInt32(this, value, offset, false)
|
1420
|
+
}
|
1421
|
+
return offset + 4
|
1422
|
+
}
|
1423
|
+
|
1424
|
+
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
|
1425
|
+
value = +value
|
1426
|
+
offset = offset | 0
|
1427
|
+
if (!noAssert) {
|
1428
|
+
var limit = Math.pow(2, 8 * byteLength - 1)
|
1429
|
+
|
1430
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit)
|
1431
|
+
}
|
1432
|
+
|
1433
|
+
var i = 0
|
1434
|
+
var mul = 1
|
1435
|
+
var sub = 0
|
1436
|
+
this[offset] = value & 0xFF
|
1437
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
1438
|
+
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
1439
|
+
sub = 1
|
1440
|
+
}
|
1441
|
+
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
|
1442
|
+
}
|
1443
|
+
|
1444
|
+
return offset + byteLength
|
1445
|
+
}
|
1446
|
+
|
1447
|
+
Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
|
1448
|
+
value = +value
|
1449
|
+
offset = offset | 0
|
1450
|
+
if (!noAssert) {
|
1451
|
+
var limit = Math.pow(2, 8 * byteLength - 1)
|
1452
|
+
|
1453
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit)
|
1454
|
+
}
|
1455
|
+
|
1456
|
+
var i = byteLength - 1
|
1457
|
+
var mul = 1
|
1458
|
+
var sub = 0
|
1459
|
+
this[offset + i] = value & 0xFF
|
1460
|
+
while (--i >= 0 && (mul *= 0x100)) {
|
1461
|
+
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
1462
|
+
sub = 1
|
1463
|
+
}
|
1464
|
+
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
|
1465
|
+
}
|
1466
|
+
|
1467
|
+
return offset + byteLength
|
1468
|
+
}
|
1469
|
+
|
1470
|
+
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
|
1471
|
+
value = +value
|
1472
|
+
offset = offset | 0
|
1473
|
+
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
|
1474
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
|
1475
|
+
if (value < 0) value = 0xff + value + 1
|
1476
|
+
this[offset] = (value & 0xff)
|
1477
|
+
return offset + 1
|
1478
|
+
}
|
1479
|
+
|
1480
|
+
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
|
1481
|
+
value = +value
|
1482
|
+
offset = offset | 0
|
1483
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
|
1484
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
1485
|
+
this[offset] = (value & 0xff)
|
1486
|
+
this[offset + 1] = (value >>> 8)
|
1487
|
+
} else {
|
1488
|
+
objectWriteUInt16(this, value, offset, true)
|
1489
|
+
}
|
1490
|
+
return offset + 2
|
1491
|
+
}
|
1492
|
+
|
1493
|
+
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
|
1494
|
+
value = +value
|
1495
|
+
offset = offset | 0
|
1496
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
|
1497
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
1498
|
+
this[offset] = (value >>> 8)
|
1499
|
+
this[offset + 1] = (value & 0xff)
|
1500
|
+
} else {
|
1501
|
+
objectWriteUInt16(this, value, offset, false)
|
1502
|
+
}
|
1503
|
+
return offset + 2
|
1504
|
+
}
|
1505
|
+
|
1506
|
+
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
|
1507
|
+
value = +value
|
1508
|
+
offset = offset | 0
|
1509
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
|
1510
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
1511
|
+
this[offset] = (value & 0xff)
|
1512
|
+
this[offset + 1] = (value >>> 8)
|
1513
|
+
this[offset + 2] = (value >>> 16)
|
1514
|
+
this[offset + 3] = (value >>> 24)
|
1515
|
+
} else {
|
1516
|
+
objectWriteUInt32(this, value, offset, true)
|
1517
|
+
}
|
1518
|
+
return offset + 4
|
1519
|
+
}
|
1520
|
+
|
1521
|
+
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
|
1522
|
+
value = +value
|
1523
|
+
offset = offset | 0
|
1524
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
|
1525
|
+
if (value < 0) value = 0xffffffff + value + 1
|
1526
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
1527
|
+
this[offset] = (value >>> 24)
|
1528
|
+
this[offset + 1] = (value >>> 16)
|
1529
|
+
this[offset + 2] = (value >>> 8)
|
1530
|
+
this[offset + 3] = (value & 0xff)
|
1531
|
+
} else {
|
1532
|
+
objectWriteUInt32(this, value, offset, false)
|
1533
|
+
}
|
1534
|
+
return offset + 4
|
1535
|
+
}
|
1536
|
+
|
1537
|
+
function checkIEEE754 (buf, value, offset, ext, max, min) {
|
1538
|
+
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
1539
|
+
if (offset < 0) throw new RangeError('Index out of range')
|
1540
|
+
}
|
1541
|
+
|
1542
|
+
function writeFloat (buf, value, offset, littleEndian, noAssert) {
|
1543
|
+
if (!noAssert) {
|
1544
|
+
checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
|
1545
|
+
}
|
1546
|
+
ieee754.write(buf, value, offset, littleEndian, 23, 4)
|
1547
|
+
return offset + 4
|
1548
|
+
}
|
1549
|
+
|
1550
|
+
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
|
1551
|
+
return writeFloat(this, value, offset, true, noAssert)
|
1552
|
+
}
|
1553
|
+
|
1554
|
+
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
|
1555
|
+
return writeFloat(this, value, offset, false, noAssert)
|
1556
|
+
}
|
1557
|
+
|
1558
|
+
function writeDouble (buf, value, offset, littleEndian, noAssert) {
|
1559
|
+
if (!noAssert) {
|
1560
|
+
checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
|
1561
|
+
}
|
1562
|
+
ieee754.write(buf, value, offset, littleEndian, 52, 8)
|
1563
|
+
return offset + 8
|
1564
|
+
}
|
1565
|
+
|
1566
|
+
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
|
1567
|
+
return writeDouble(this, value, offset, true, noAssert)
|
1568
|
+
}
|
1569
|
+
|
1570
|
+
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
|
1571
|
+
return writeDouble(this, value, offset, false, noAssert)
|
1572
|
+
}
|
1573
|
+
|
1574
|
+
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
|
1575
|
+
Buffer.prototype.copy = function copy (target, targetStart, start, end) {
|
1576
|
+
if (!start) start = 0
|
1577
|
+
if (!end && end !== 0) end = this.length
|
1578
|
+
if (targetStart >= target.length) targetStart = target.length
|
1579
|
+
if (!targetStart) targetStart = 0
|
1580
|
+
if (end > 0 && end < start) end = start
|
1581
|
+
|
1582
|
+
// Copy 0 bytes; we're done
|
1583
|
+
if (end === start) return 0
|
1584
|
+
if (target.length === 0 || this.length === 0) return 0
|
1585
|
+
|
1586
|
+
// Fatal error conditions
|
1587
|
+
if (targetStart < 0) {
|
1588
|
+
throw new RangeError('targetStart out of bounds')
|
1589
|
+
}
|
1590
|
+
if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
|
1591
|
+
if (end < 0) throw new RangeError('sourceEnd out of bounds')
|
1592
|
+
|
1593
|
+
// Are we oob?
|
1594
|
+
if (end > this.length) end = this.length
|
1595
|
+
if (target.length - targetStart < end - start) {
|
1596
|
+
end = target.length - targetStart + start
|
1597
|
+
}
|
1598
|
+
|
1599
|
+
var len = end - start
|
1600
|
+
var i
|
1601
|
+
|
1602
|
+
if (this === target && start < targetStart && targetStart < end) {
|
1603
|
+
// descending copy from end
|
1604
|
+
for (i = len - 1; i >= 0; i--) {
|
1605
|
+
target[i + targetStart] = this[i + start]
|
1606
|
+
}
|
1607
|
+
} else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
|
1608
|
+
// ascending copy from start
|
1609
|
+
for (i = 0; i < len; i++) {
|
1610
|
+
target[i + targetStart] = this[i + start]
|
1611
|
+
}
|
1612
|
+
} else {
|
1613
|
+
Uint8Array.prototype.set.call(
|
1614
|
+
target,
|
1615
|
+
this.subarray(start, start + len),
|
1616
|
+
targetStart
|
1617
|
+
)
|
1618
|
+
}
|
1619
|
+
|
1620
|
+
return len
|
1621
|
+
}
|
1622
|
+
|
1623
|
+
// Usage:
|
1624
|
+
// buffer.fill(number[, offset[, end]])
|
1625
|
+
// buffer.fill(buffer[, offset[, end]])
|
1626
|
+
// buffer.fill(string[, offset[, end]][, encoding])
|
1627
|
+
Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
1628
|
+
// Handle string cases:
|
1629
|
+
if (typeof val === 'string') {
|
1630
|
+
if (typeof start === 'string') {
|
1631
|
+
encoding = start
|
1632
|
+
start = 0
|
1633
|
+
end = this.length
|
1634
|
+
} else if (typeof end === 'string') {
|
1635
|
+
encoding = end
|
1636
|
+
end = this.length
|
1637
|
+
}
|
1638
|
+
if (val.length === 1) {
|
1639
|
+
var code = val.charCodeAt(0)
|
1640
|
+
if (code < 256) {
|
1641
|
+
val = code
|
1642
|
+
}
|
1643
|
+
}
|
1644
|
+
if (encoding !== undefined && typeof encoding !== 'string') {
|
1645
|
+
throw new TypeError('encoding must be a string')
|
1646
|
+
}
|
1647
|
+
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
1648
|
+
throw new TypeError('Unknown encoding: ' + encoding)
|
1649
|
+
}
|
1650
|
+
} else if (typeof val === 'number') {
|
1651
|
+
val = val & 255
|
1652
|
+
}
|
1653
|
+
|
1654
|
+
// Invalid ranges are not set to a default, so can range check early.
|
1655
|
+
if (start < 0 || this.length < start || this.length < end) {
|
1656
|
+
throw new RangeError('Out of range index')
|
1657
|
+
}
|
1658
|
+
|
1659
|
+
if (end <= start) {
|
1660
|
+
return this
|
1661
|
+
}
|
1662
|
+
|
1663
|
+
start = start >>> 0
|
1664
|
+
end = end === undefined ? this.length : end >>> 0
|
1665
|
+
|
1666
|
+
if (!val) val = 0
|
1667
|
+
|
1668
|
+
var i
|
1669
|
+
if (typeof val === 'number') {
|
1670
|
+
for (i = start; i < end; i++) {
|
1671
|
+
this[i] = val
|
1672
|
+
}
|
1673
|
+
} else {
|
1674
|
+
var bytes = Buffer.isBuffer(val)
|
1675
|
+
? val
|
1676
|
+
: utf8ToBytes(new Buffer(val, encoding).toString())
|
1677
|
+
var len = bytes.length
|
1678
|
+
for (i = 0; i < end - start; i++) {
|
1679
|
+
this[i + start] = bytes[i % len]
|
1680
|
+
}
|
1681
|
+
}
|
1682
|
+
|
1683
|
+
return this
|
1684
|
+
}
|
1685
|
+
|
1686
|
+
// HELPER FUNCTIONS
|
1687
|
+
// ================
|
1688
|
+
|
1689
|
+
var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
|
1690
|
+
|
1691
|
+
function base64clean (str) {
|
1692
|
+
// Node strips out invalid characters like \n and \t from the string, base64-js does not
|
1693
|
+
str = stringtrim(str).replace(INVALID_BASE64_RE, '')
|
1694
|
+
// Node converts strings with length < 2 to ''
|
1695
|
+
if (str.length < 2) return ''
|
1696
|
+
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
|
1697
|
+
while (str.length % 4 !== 0) {
|
1698
|
+
str = str + '='
|
1699
|
+
}
|
1700
|
+
return str
|
1701
|
+
}
|
1702
|
+
|
1703
|
+
function stringtrim (str) {
|
1704
|
+
if (str.trim) return str.trim()
|
1705
|
+
return str.replace(/^\s+|\s+$/g, '')
|
1706
|
+
}
|
1707
|
+
|
1708
|
+
function toHex (n) {
|
1709
|
+
if (n < 16) return '0' + n.toString(16)
|
1710
|
+
return n.toString(16)
|
1711
|
+
}
|
1712
|
+
|
1713
|
+
function utf8ToBytes (string, units) {
|
1714
|
+
units = units || Infinity
|
1715
|
+
var codePoint
|
1716
|
+
var length = string.length
|
1717
|
+
var leadSurrogate = null
|
1718
|
+
var bytes = []
|
1719
|
+
|
1720
|
+
for (var i = 0; i < length; i++) {
|
1721
|
+
codePoint = string.charCodeAt(i)
|
1722
|
+
|
1723
|
+
// is surrogate component
|
1724
|
+
if (codePoint > 0xD7FF && codePoint < 0xE000) {
|
1725
|
+
// last char was a lead
|
1726
|
+
if (!leadSurrogate) {
|
1727
|
+
// no lead yet
|
1728
|
+
if (codePoint > 0xDBFF) {
|
1729
|
+
// unexpected trail
|
1730
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
1731
|
+
continue
|
1732
|
+
} else if (i + 1 === length) {
|
1733
|
+
// unpaired lead
|
1734
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
1735
|
+
continue
|
1736
|
+
}
|
1737
|
+
|
1738
|
+
// valid lead
|
1739
|
+
leadSurrogate = codePoint
|
1740
|
+
|
1741
|
+
continue
|
1742
|
+
}
|
1743
|
+
|
1744
|
+
// 2 leads in a row
|
1745
|
+
if (codePoint < 0xDC00) {
|
1746
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
1747
|
+
leadSurrogate = codePoint
|
1748
|
+
continue
|
1749
|
+
}
|
1750
|
+
|
1751
|
+
// valid surrogate pair
|
1752
|
+
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
|
1753
|
+
} else if (leadSurrogate) {
|
1754
|
+
// valid bmp char, but last char was a lead
|
1755
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
1756
|
+
}
|
1757
|
+
|
1758
|
+
leadSurrogate = null
|
1759
|
+
|
1760
|
+
// encode utf8
|
1761
|
+
if (codePoint < 0x80) {
|
1762
|
+
if ((units -= 1) < 0) break
|
1763
|
+
bytes.push(codePoint)
|
1764
|
+
} else if (codePoint < 0x800) {
|
1765
|
+
if ((units -= 2) < 0) break
|
1766
|
+
bytes.push(
|
1767
|
+
codePoint >> 0x6 | 0xC0,
|
1768
|
+
codePoint & 0x3F | 0x80
|
1769
|
+
)
|
1770
|
+
} else if (codePoint < 0x10000) {
|
1771
|
+
if ((units -= 3) < 0) break
|
1772
|
+
bytes.push(
|
1773
|
+
codePoint >> 0xC | 0xE0,
|
1774
|
+
codePoint >> 0x6 & 0x3F | 0x80,
|
1775
|
+
codePoint & 0x3F | 0x80
|
1776
|
+
)
|
1777
|
+
} else if (codePoint < 0x110000) {
|
1778
|
+
if ((units -= 4) < 0) break
|
1779
|
+
bytes.push(
|
1780
|
+
codePoint >> 0x12 | 0xF0,
|
1781
|
+
codePoint >> 0xC & 0x3F | 0x80,
|
1782
|
+
codePoint >> 0x6 & 0x3F | 0x80,
|
1783
|
+
codePoint & 0x3F | 0x80
|
1784
|
+
)
|
1785
|
+
} else {
|
1786
|
+
throw new Error('Invalid code point')
|
1787
|
+
}
|
1788
|
+
}
|
1789
|
+
|
1790
|
+
return bytes
|
1791
|
+
}
|
1792
|
+
|
1793
|
+
function asciiToBytes (str) {
|
1794
|
+
var byteArray = []
|
1795
|
+
for (var i = 0; i < str.length; i++) {
|
1796
|
+
// Node's code seems to be doing this and not & 0x7F..
|
1797
|
+
byteArray.push(str.charCodeAt(i) & 0xFF)
|
1798
|
+
}
|
1799
|
+
return byteArray
|
1800
|
+
}
|
1801
|
+
|
1802
|
+
function utf16leToBytes (str, units) {
|
1803
|
+
var c, hi, lo
|
1804
|
+
var byteArray = []
|
1805
|
+
for (var i = 0; i < str.length; i++) {
|
1806
|
+
if ((units -= 2) < 0) break
|
1807
|
+
|
1808
|
+
c = str.charCodeAt(i)
|
1809
|
+
hi = c >> 8
|
1810
|
+
lo = c % 256
|
1811
|
+
byteArray.push(lo)
|
1812
|
+
byteArray.push(hi)
|
1813
|
+
}
|
1814
|
+
|
1815
|
+
return byteArray
|
1816
|
+
}
|
1817
|
+
|
1818
|
+
function base64ToBytes (str) {
|
1819
|
+
return base64.toByteArray(base64clean(str))
|
1820
|
+
}
|
1821
|
+
|
1822
|
+
function blitBuffer (src, dst, offset, length) {
|
1823
|
+
for (var i = 0; i < length; i++) {
|
1824
|
+
if ((i + offset >= dst.length) || (i >= src.length)) break
|
1825
|
+
dst[i + offset] = src[i]
|
1826
|
+
}
|
1827
|
+
return i
|
1828
|
+
}
|
1829
|
+
|
1830
|
+
function isnan (val) {
|
1831
|
+
return val !== val // eslint-disable-line no-self-compare
|
1832
|
+
}
|
1833
|
+
|
1834
|
+
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
1835
|
+
},{"base64-js":1,"ieee754":4,"isarray":5}],4:[function(require,module,exports){
|
1836
|
+
exports.read = function (buffer, offset, isLE, mLen, nBytes) {
|
1837
|
+
var e, m
|
1838
|
+
var eLen = nBytes * 8 - mLen - 1
|
1839
|
+
var eMax = (1 << eLen) - 1
|
1840
|
+
var eBias = eMax >> 1
|
1841
|
+
var nBits = -7
|
1842
|
+
var i = isLE ? (nBytes - 1) : 0
|
1843
|
+
var d = isLE ? -1 : 1
|
1844
|
+
var s = buffer[offset + i]
|
1845
|
+
|
1846
|
+
i += d
|
1847
|
+
|
1848
|
+
e = s & ((1 << (-nBits)) - 1)
|
1849
|
+
s >>= (-nBits)
|
1850
|
+
nBits += eLen
|
1851
|
+
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
|
1852
|
+
|
1853
|
+
m = e & ((1 << (-nBits)) - 1)
|
1854
|
+
e >>= (-nBits)
|
1855
|
+
nBits += mLen
|
1856
|
+
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
|
1857
|
+
|
1858
|
+
if (e === 0) {
|
1859
|
+
e = 1 - eBias
|
1860
|
+
} else if (e === eMax) {
|
1861
|
+
return m ? NaN : ((s ? -1 : 1) * Infinity)
|
1862
|
+
} else {
|
1863
|
+
m = m + Math.pow(2, mLen)
|
1864
|
+
e = e - eBias
|
1865
|
+
}
|
1866
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
|
1867
|
+
}
|
1868
|
+
|
1869
|
+
exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
|
1870
|
+
var e, m, c
|
1871
|
+
var eLen = nBytes * 8 - mLen - 1
|
1872
|
+
var eMax = (1 << eLen) - 1
|
1873
|
+
var eBias = eMax >> 1
|
1874
|
+
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
|
1875
|
+
var i = isLE ? 0 : (nBytes - 1)
|
1876
|
+
var d = isLE ? 1 : -1
|
1877
|
+
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
|
1878
|
+
|
1879
|
+
value = Math.abs(value)
|
1880
|
+
|
1881
|
+
if (isNaN(value) || value === Infinity) {
|
1882
|
+
m = isNaN(value) ? 1 : 0
|
1883
|
+
e = eMax
|
1884
|
+
} else {
|
1885
|
+
e = Math.floor(Math.log(value) / Math.LN2)
|
1886
|
+
if (value * (c = Math.pow(2, -e)) < 1) {
|
1887
|
+
e--
|
1888
|
+
c *= 2
|
1889
|
+
}
|
1890
|
+
if (e + eBias >= 1) {
|
1891
|
+
value += rt / c
|
1892
|
+
} else {
|
1893
|
+
value += rt * Math.pow(2, 1 - eBias)
|
1894
|
+
}
|
1895
|
+
if (value * c >= 2) {
|
1896
|
+
e++
|
1897
|
+
c /= 2
|
1898
|
+
}
|
1899
|
+
|
1900
|
+
if (e + eBias >= eMax) {
|
1901
|
+
m = 0
|
1902
|
+
e = eMax
|
1903
|
+
} else if (e + eBias >= 1) {
|
1904
|
+
m = (value * c - 1) * Math.pow(2, mLen)
|
1905
|
+
e = e + eBias
|
1906
|
+
} else {
|
1907
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
|
1908
|
+
e = 0
|
1909
|
+
}
|
1910
|
+
}
|
1911
|
+
|
1912
|
+
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
1913
|
+
|
1914
|
+
e = (e << mLen) | m
|
1915
|
+
eLen += mLen
|
1916
|
+
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
1917
|
+
|
1918
|
+
buffer[offset + i - d] |= s * 128
|
1919
|
+
}
|
1920
|
+
|
1921
|
+
},{}],5:[function(require,module,exports){
|
1922
|
+
var toString = {}.toString;
|
1923
|
+
|
1924
|
+
module.exports = Array.isArray || function (arr) {
|
1925
|
+
return toString.call(arr) == '[object Array]';
|
1926
|
+
};
|
1927
|
+
|
1928
|
+
},{}],6:[function(require,module,exports){
|
1929
|
+
(function (Buffer,__dirname){
|
1930
|
+
'use strict';
|
1931
|
+
|
1932
|
+
/**
|
1933
|
+
* Typo is a JavaScript implementation of a spellchecker using hunspell-style
|
1934
|
+
* dictionaries.
|
1935
|
+
*/
|
1936
|
+
|
1937
|
+
/**
|
1938
|
+
* Typo constructor.
|
1939
|
+
*
|
1940
|
+
* @param {String} [dictionary] The locale code of the dictionary being used. e.g.,
|
1941
|
+
* "en_US". This is only used to auto-load dictionaries.
|
1942
|
+
* @param {String} [affData] The data from the dictionary's .aff file. If omitted
|
1943
|
+
* and Typo.js is being used in a Chrome extension, the .aff
|
1944
|
+
* file will be loaded automatically from
|
1945
|
+
* lib/typo/dictionaries/[dictionary]/[dictionary].aff
|
1946
|
+
* In other environments, it will be loaded from
|
1947
|
+
* [settings.dictionaryPath]/dictionaries/[dictionary]/[dictionary].aff
|
1948
|
+
* @param {String} [wordsData] The data from the dictionary's .dic file. If omitted
|
1949
|
+
* and Typo.js is being used in a Chrome extension, the .dic
|
1950
|
+
* file will be loaded automatically from
|
1951
|
+
* lib/typo/dictionaries/[dictionary]/[dictionary].dic
|
1952
|
+
* In other environments, it will be loaded from
|
1953
|
+
* [settings.dictionaryPath]/dictionaries/[dictionary]/[dictionary].dic
|
1954
|
+
* @param {Object} [settings] Constructor settings. Available properties are:
|
1955
|
+
* {String} [dictionaryPath]: path to load dictionary from in non-chrome
|
1956
|
+
* environment.
|
1957
|
+
* {Object} [flags]: flag information.
|
1958
|
+
*
|
1959
|
+
*
|
1960
|
+
* @returns {Typo} A Typo object.
|
1961
|
+
*/
|
1962
|
+
|
1963
|
+
var Typo = function (dictionary, affData, wordsData, settings) {
|
1964
|
+
settings = settings || {};
|
1965
|
+
|
1966
|
+
this.dictionary = null;
|
1967
|
+
|
1968
|
+
this.rules = {};
|
1969
|
+
this.dictionaryTable = {};
|
1970
|
+
|
1971
|
+
this.compoundRules = [];
|
1972
|
+
this.compoundRuleCodes = {};
|
1973
|
+
|
1974
|
+
this.replacementTable = [];
|
1975
|
+
|
1976
|
+
this.flags = settings.flags || {};
|
1977
|
+
|
1978
|
+
if (dictionary) {
|
1979
|
+
this.dictionary = dictionary;
|
1980
|
+
|
1981
|
+
if (typeof window !== 'undefined' && 'chrome' in window && 'extension' in window.chrome && 'getURL' in window.chrome.extension) {
|
1982
|
+
if (!affData) affData = this._readFile(chrome.extension.getURL("lib/typo/dictionaries/" + dictionary + "/" + dictionary + ".aff"));
|
1983
|
+
if (!wordsData) wordsData = this._readFile(chrome.extension.getURL("lib/typo/dictionaries/" + dictionary + "/" + dictionary + ".dic"));
|
1984
|
+
} else {
|
1985
|
+
if (settings.dictionaryPath) {
|
1986
|
+
var path = settings.dictionaryPath;
|
1987
|
+
}
|
1988
|
+
else if (typeof __dirname !== 'undefined') {
|
1989
|
+
var path = __dirname + '/dictionaries';
|
1990
|
+
}
|
1991
|
+
else {
|
1992
|
+
var path = './dictionaries';
|
1993
|
+
}
|
1994
|
+
|
1995
|
+
if (!affData) affData = this._readFile(path + "/" + dictionary + "/" + dictionary + ".aff");
|
1996
|
+
if (!wordsData) wordsData = this._readFile(path + "/" + dictionary + "/" + dictionary + ".dic");
|
1997
|
+
}
|
1998
|
+
|
1999
|
+
this.rules = this._parseAFF(affData);
|
2000
|
+
|
2001
|
+
// Save the rule codes that are used in compound rules.
|
2002
|
+
this.compoundRuleCodes = {};
|
2003
|
+
|
2004
|
+
for (var i = 0, _len = this.compoundRules.length; i < _len; i++) {
|
2005
|
+
var rule = this.compoundRules[i];
|
2006
|
+
|
2007
|
+
for (var j = 0, _jlen = rule.length; j < _jlen; j++) {
|
2008
|
+
this.compoundRuleCodes[rule[j]] = [];
|
2009
|
+
}
|
2010
|
+
}
|
2011
|
+
|
2012
|
+
// If we add this ONLYINCOMPOUND flag to this.compoundRuleCodes, then _parseDIC
|
2013
|
+
// will do the work of saving the list of words that are compound-only.
|
2014
|
+
if ("ONLYINCOMPOUND" in this.flags) {
|
2015
|
+
this.compoundRuleCodes[this.flags.ONLYINCOMPOUND] = [];
|
2016
|
+
}
|
2017
|
+
|
2018
|
+
this.dictionaryTable = this._parseDIC(wordsData);
|
2019
|
+
|
2020
|
+
// Get rid of any codes from the compound rule codes that are never used
|
2021
|
+
// (or that were special regex characters). Not especially necessary...
|
2022
|
+
for (var i in this.compoundRuleCodes) {
|
2023
|
+
if (this.compoundRuleCodes[i].length == 0) {
|
2024
|
+
delete this.compoundRuleCodes[i];
|
2025
|
+
}
|
2026
|
+
}
|
2027
|
+
|
2028
|
+
// Build the full regular expressions for each compound rule.
|
2029
|
+
// I have a feeling (but no confirmation yet) that this method of
|
2030
|
+
// testing for compound words is probably slow.
|
2031
|
+
for (var i = 0, _len = this.compoundRules.length; i < _len; i++) {
|
2032
|
+
var ruleText = this.compoundRules[i];
|
2033
|
+
|
2034
|
+
var expressionText = "";
|
2035
|
+
|
2036
|
+
for (var j = 0, _jlen = ruleText.length; j < _jlen; j++) {
|
2037
|
+
var character = ruleText[j];
|
2038
|
+
|
2039
|
+
if (character in this.compoundRuleCodes) {
|
2040
|
+
expressionText += "(" + this.compoundRuleCodes[character].join("|") + ")";
|
2041
|
+
}
|
2042
|
+
else {
|
2043
|
+
expressionText += character;
|
2044
|
+
}
|
2045
|
+
}
|
2046
|
+
|
2047
|
+
this.compoundRules[i] = new RegExp(expressionText, "i");
|
2048
|
+
}
|
2049
|
+
}
|
2050
|
+
|
2051
|
+
return this;
|
2052
|
+
};
|
2053
|
+
|
2054
|
+
Typo.prototype = {
|
2055
|
+
/**
|
2056
|
+
* Loads a Typo instance from a hash of all of the Typo properties.
|
2057
|
+
*
|
2058
|
+
* @param object obj A hash of Typo properties, probably gotten from a JSON.parse(JSON.stringify(typo_instance)).
|
2059
|
+
*/
|
2060
|
+
|
2061
|
+
load : function (obj) {
|
2062
|
+
for (var i in obj) {
|
2063
|
+
this[i] = obj[i];
|
2064
|
+
}
|
2065
|
+
|
2066
|
+
return this;
|
2067
|
+
},
|
2068
|
+
|
2069
|
+
/**
|
2070
|
+
* Read the contents of a file.
|
2071
|
+
*
|
2072
|
+
* @param {String} path The path (relative) to the file.
|
2073
|
+
* @param {String} [charset="ISO8859-1"] The expected charset of the file
|
2074
|
+
* @returns string The file data.
|
2075
|
+
*/
|
2076
|
+
|
2077
|
+
_readFile : function (path, charset) {
|
2078
|
+
if (!charset) charset = "utf8";
|
2079
|
+
|
2080
|
+
if (typeof XMLHttpRequest !== 'undefined') {
|
2081
|
+
var req = new XMLHttpRequest();
|
2082
|
+
req.open("GET", path, false);
|
2083
|
+
|
2084
|
+
if (req.overrideMimeType)
|
2085
|
+
req.overrideMimeType("text/plain; charset=" + charset);
|
2086
|
+
|
2087
|
+
req.send(null);
|
2088
|
+
|
2089
|
+
return req.responseText;
|
2090
|
+
}
|
2091
|
+
else if (typeof require !== 'undefined') {
|
2092
|
+
// Node.js
|
2093
|
+
var fs = require("fs");
|
2094
|
+
|
2095
|
+
try {
|
2096
|
+
if (fs.existsSync(path)) {
|
2097
|
+
var stats = fs.statSync(path);
|
2098
|
+
|
2099
|
+
var fileDescriptor = fs.openSync(path, 'r');
|
2100
|
+
|
2101
|
+
var buffer = new Buffer(stats.size);
|
2102
|
+
|
2103
|
+
fs.readSync(fileDescriptor, buffer, 0, buffer.length, null);
|
2104
|
+
|
2105
|
+
return buffer.toString(charset, 0, buffer.length);
|
2106
|
+
}
|
2107
|
+
else {
|
2108
|
+
console.log("Path " + path + " does not exist.");
|
2109
|
+
}
|
2110
|
+
} catch (e) {
|
2111
|
+
console.log(e);
|
2112
|
+
return '';
|
2113
|
+
}
|
2114
|
+
}
|
2115
|
+
},
|
2116
|
+
|
2117
|
+
/**
|
2118
|
+
* Parse the rules out from a .aff file.
|
2119
|
+
*
|
2120
|
+
* @param {String} data The contents of the affix file.
|
2121
|
+
* @returns object The rules from the file.
|
2122
|
+
*/
|
2123
|
+
|
2124
|
+
_parseAFF : function (data) {
|
2125
|
+
var rules = {};
|
2126
|
+
|
2127
|
+
// Remove comment lines
|
2128
|
+
data = this._removeAffixComments(data);
|
2129
|
+
|
2130
|
+
var lines = data.split("\n");
|
2131
|
+
|
2132
|
+
for (var i = 0, _len = lines.length; i < _len; i++) {
|
2133
|
+
var line = lines[i];
|
2134
|
+
|
2135
|
+
var definitionParts = line.split(/\s+/);
|
2136
|
+
|
2137
|
+
var ruleType = definitionParts[0];
|
2138
|
+
|
2139
|
+
if (ruleType == "PFX" || ruleType == "SFX") {
|
2140
|
+
var ruleCode = definitionParts[1];
|
2141
|
+
var combineable = definitionParts[2];
|
2142
|
+
var numEntries = parseInt(definitionParts[3], 10);
|
2143
|
+
|
2144
|
+
var entries = [];
|
2145
|
+
|
2146
|
+
for (var j = i + 1, _jlen = i + 1 + numEntries; j < _jlen; j++) {
|
2147
|
+
var line = lines[j];
|
2148
|
+
|
2149
|
+
var lineParts = line.split(/\s+/);
|
2150
|
+
var charactersToRemove = lineParts[2];
|
2151
|
+
|
2152
|
+
var additionParts = lineParts[3].split("/");
|
2153
|
+
|
2154
|
+
var charactersToAdd = additionParts[0];
|
2155
|
+
if (charactersToAdd === "0") charactersToAdd = "";
|
2156
|
+
|
2157
|
+
var continuationClasses = this.parseRuleCodes(additionParts[1]);
|
2158
|
+
|
2159
|
+
var regexToMatch = lineParts[4];
|
2160
|
+
|
2161
|
+
var entry = {};
|
2162
|
+
entry.add = charactersToAdd;
|
2163
|
+
|
2164
|
+
if (continuationClasses.length > 0) entry.continuationClasses = continuationClasses;
|
2165
|
+
|
2166
|
+
if (regexToMatch !== ".") {
|
2167
|
+
if (ruleType === "SFX") {
|
2168
|
+
entry.match = new RegExp(regexToMatch + "$");
|
2169
|
+
}
|
2170
|
+
else {
|
2171
|
+
entry.match = new RegExp("^" + regexToMatch);
|
2172
|
+
}
|
2173
|
+
}
|
2174
|
+
|
2175
|
+
if (charactersToRemove != "0") {
|
2176
|
+
if (ruleType === "SFX") {
|
2177
|
+
entry.remove = new RegExp(charactersToRemove + "$");
|
2178
|
+
}
|
2179
|
+
else {
|
2180
|
+
entry.remove = charactersToRemove;
|
2181
|
+
}
|
2182
|
+
}
|
2183
|
+
|
2184
|
+
entries.push(entry);
|
2185
|
+
}
|
2186
|
+
|
2187
|
+
rules[ruleCode] = { "type" : ruleType, "combineable" : (combineable == "Y"), "entries" : entries };
|
2188
|
+
|
2189
|
+
i += numEntries;
|
2190
|
+
}
|
2191
|
+
else if (ruleType === "COMPOUNDRULE") {
|
2192
|
+
var numEntries = parseInt(definitionParts[1], 10);
|
2193
|
+
|
2194
|
+
for (var j = i + 1, _jlen = i + 1 + numEntries; j < _jlen; j++) {
|
2195
|
+
var line = lines[j];
|
2196
|
+
|
2197
|
+
var lineParts = line.split(/\s+/);
|
2198
|
+
this.compoundRules.push(lineParts[1]);
|
2199
|
+
}
|
2200
|
+
|
2201
|
+
i += numEntries;
|
2202
|
+
}
|
2203
|
+
else if (ruleType === "REP") {
|
2204
|
+
var lineParts = line.split(/\s+/);
|
2205
|
+
|
2206
|
+
if (lineParts.length === 3) {
|
2207
|
+
this.replacementTable.push([ lineParts[1], lineParts[2] ]);
|
2208
|
+
}
|
2209
|
+
}
|
2210
|
+
else {
|
2211
|
+
// ONLYINCOMPOUND
|
2212
|
+
// COMPOUNDMIN
|
2213
|
+
// FLAG
|
2214
|
+
// KEEPCASE
|
2215
|
+
// NEEDAFFIX
|
2216
|
+
|
2217
|
+
this.flags[ruleType] = definitionParts[1];
|
2218
|
+
}
|
2219
|
+
}
|
2220
|
+
|
2221
|
+
return rules;
|
2222
|
+
},
|
2223
|
+
|
2224
|
+
/**
|
2225
|
+
* Removes comment lines and then cleans up blank lines and trailing whitespace.
|
2226
|
+
*
|
2227
|
+
* @param {String} data The data from an affix file.
|
2228
|
+
* @return {String} The cleaned-up data.
|
2229
|
+
*/
|
2230
|
+
|
2231
|
+
_removeAffixComments : function (data) {
|
2232
|
+
// Remove comments
|
2233
|
+
data = data.replace(/#.*$/mg, "");
|
2234
|
+
|
2235
|
+
// Trim each line
|
2236
|
+
data = data.replace(/^\s\s*/m, '').replace(/\s\s*$/m, '');
|
2237
|
+
|
2238
|
+
// Remove blank lines.
|
2239
|
+
data = data.replace(/\n{2,}/g, "\n");
|
2240
|
+
|
2241
|
+
// Trim the entire string
|
2242
|
+
data = data.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
|
2243
|
+
|
2244
|
+
return data;
|
2245
|
+
},
|
2246
|
+
|
2247
|
+
/**
|
2248
|
+
* Parses the words out from the .dic file.
|
2249
|
+
*
|
2250
|
+
* @param {String} data The data from the dictionary file.
|
2251
|
+
* @returns object The lookup table containing all of the words and
|
2252
|
+
* word forms from the dictionary.
|
2253
|
+
*/
|
2254
|
+
|
2255
|
+
_parseDIC : function (data) {
|
2256
|
+
data = this._removeDicComments(data);
|
2257
|
+
|
2258
|
+
var lines = data.split("\n");
|
2259
|
+
var dictionaryTable = {};
|
2260
|
+
|
2261
|
+
function addWord(word, rules) {
|
2262
|
+
// Some dictionaries will list the same word multiple times with different rule sets.
|
2263
|
+
if (!(word in dictionaryTable) || typeof dictionaryTable[word] != 'object') {
|
2264
|
+
dictionaryTable[word] = [];
|
2265
|
+
}
|
2266
|
+
|
2267
|
+
dictionaryTable[word].push(rules);
|
2268
|
+
}
|
2269
|
+
|
2270
|
+
// The first line is the number of words in the dictionary.
|
2271
|
+
for (var i = 1, _len = lines.length; i < _len; i++) {
|
2272
|
+
var line = lines[i];
|
2273
|
+
|
2274
|
+
var parts = line.split("/", 2);
|
2275
|
+
|
2276
|
+
var word = parts[0];
|
2277
|
+
|
2278
|
+
// Now for each affix rule, generate that form of the word.
|
2279
|
+
if (parts.length > 1) {
|
2280
|
+
var ruleCodesArray = this.parseRuleCodes(parts[1]);
|
2281
|
+
|
2282
|
+
// Save the ruleCodes for compound word situations.
|
2283
|
+
if (!("NEEDAFFIX" in this.flags) || ruleCodesArray.indexOf(this.flags.NEEDAFFIX) == -1) {
|
2284
|
+
addWord(word, ruleCodesArray);
|
2285
|
+
}
|
2286
|
+
|
2287
|
+
for (var j = 0, _jlen = ruleCodesArray.length; j < _jlen; j++) {
|
2288
|
+
var code = ruleCodesArray[j];
|
2289
|
+
|
2290
|
+
var rule = this.rules[code];
|
2291
|
+
|
2292
|
+
if (rule) {
|
2293
|
+
var newWords = this._applyRule(word, rule);
|
2294
|
+
|
2295
|
+
for (var ii = 0, _iilen = newWords.length; ii < _iilen; ii++) {
|
2296
|
+
var newWord = newWords[ii];
|
2297
|
+
|
2298
|
+
addWord(newWord, []);
|
2299
|
+
|
2300
|
+
if (rule.combineable) {
|
2301
|
+
for (var k = j + 1; k < _jlen; k++) {
|
2302
|
+
var combineCode = ruleCodesArray[k];
|
2303
|
+
|
2304
|
+
var combineRule = this.rules[combineCode];
|
2305
|
+
|
2306
|
+
if (combineRule) {
|
2307
|
+
if (combineRule.combineable && (rule.type != combineRule.type)) {
|
2308
|
+
var otherNewWords = this._applyRule(newWord, combineRule);
|
2309
|
+
|
2310
|
+
for (var iii = 0, _iiilen = otherNewWords.length; iii < _iiilen; iii++) {
|
2311
|
+
var otherNewWord = otherNewWords[iii];
|
2312
|
+
addWord(otherNewWord, []);
|
2313
|
+
}
|
2314
|
+
}
|
2315
|
+
}
|
2316
|
+
}
|
2317
|
+
}
|
2318
|
+
}
|
2319
|
+
}
|
2320
|
+
|
2321
|
+
if (code in this.compoundRuleCodes) {
|
2322
|
+
this.compoundRuleCodes[code].push(word);
|
2323
|
+
}
|
2324
|
+
}
|
2325
|
+
}
|
2326
|
+
else {
|
2327
|
+
addWord(word.trim(), []);
|
2328
|
+
}
|
2329
|
+
}
|
2330
|
+
|
2331
|
+
return dictionaryTable;
|
2332
|
+
},
|
2333
|
+
|
2334
|
+
|
2335
|
+
/**
|
2336
|
+
* Removes comment lines and then cleans up blank lines and trailing whitespace.
|
2337
|
+
*
|
2338
|
+
* @param {String} data The data from a .dic file.
|
2339
|
+
* @return {String} The cleaned-up data.
|
2340
|
+
*/
|
2341
|
+
|
2342
|
+
_removeDicComments : function (data) {
|
2343
|
+
// I can't find any official documentation on it, but at least the de_DE
|
2344
|
+
// dictionary uses tab-indented lines as comments.
|
2345
|
+
|
2346
|
+
// Remove comments
|
2347
|
+
data = data.replace(/^\t.*$/mg, "");
|
2348
|
+
|
2349
|
+
return data;
|
2350
|
+
},
|
2351
|
+
|
2352
|
+
parseRuleCodes : function (textCodes) {
|
2353
|
+
if (!textCodes) {
|
2354
|
+
return [];
|
2355
|
+
}
|
2356
|
+
else if (!("FLAG" in this.flags)) {
|
2357
|
+
return textCodes.split("");
|
2358
|
+
}
|
2359
|
+
else if (this.flags.FLAG === "long") {
|
2360
|
+
var flags = [];
|
2361
|
+
|
2362
|
+
for (var i = 0, _len = textCodes.length; i < _len; i += 2) {
|
2363
|
+
flags.push(textCodes.substr(i, 2));
|
2364
|
+
}
|
2365
|
+
|
2366
|
+
return flags;
|
2367
|
+
}
|
2368
|
+
else if (this.flags.FLAG === "num") {
|
2369
|
+
return textCode.split(",");
|
2370
|
+
}
|
2371
|
+
},
|
2372
|
+
|
2373
|
+
/**
|
2374
|
+
* Applies an affix rule to a word.
|
2375
|
+
*
|
2376
|
+
* @param {String} word The base word.
|
2377
|
+
* @param {Object} rule The affix rule.
|
2378
|
+
* @returns {String[]} The new words generated by the rule.
|
2379
|
+
*/
|
2380
|
+
|
2381
|
+
_applyRule : function (word, rule) {
|
2382
|
+
var entries = rule.entries;
|
2383
|
+
var newWords = [];
|
2384
|
+
|
2385
|
+
for (var i = 0, _len = entries.length; i < _len; i++) {
|
2386
|
+
var entry = entries[i];
|
2387
|
+
|
2388
|
+
if (!entry.match || word.match(entry.match)) {
|
2389
|
+
var newWord = word;
|
2390
|
+
|
2391
|
+
if (entry.remove) {
|
2392
|
+
newWord = newWord.replace(entry.remove, "");
|
2393
|
+
}
|
2394
|
+
|
2395
|
+
if (rule.type === "SFX") {
|
2396
|
+
newWord = newWord + entry.add;
|
2397
|
+
}
|
2398
|
+
else {
|
2399
|
+
newWord = entry.add + newWord;
|
2400
|
+
}
|
2401
|
+
|
2402
|
+
newWords.push(newWord);
|
2403
|
+
|
2404
|
+
if ("continuationClasses" in entry) {
|
2405
|
+
for (var j = 0, _jlen = entry.continuationClasses.length; j < _jlen; j++) {
|
2406
|
+
var continuationRule = this.rules[entry.continuationClasses[j]];
|
2407
|
+
|
2408
|
+
if (continuationRule) {
|
2409
|
+
newWords = newWords.concat(this._applyRule(newWord, continuationRule));
|
2410
|
+
}
|
2411
|
+
/*
|
2412
|
+
else {
|
2413
|
+
// This shouldn't happen, but it does, at least in the de_DE dictionary.
|
2414
|
+
// I think the author mistakenly supplied lower-case rule codes instead
|
2415
|
+
// of upper-case.
|
2416
|
+
}
|
2417
|
+
*/
|
2418
|
+
}
|
2419
|
+
}
|
2420
|
+
}
|
2421
|
+
}
|
2422
|
+
|
2423
|
+
return newWords;
|
2424
|
+
},
|
2425
|
+
|
2426
|
+
/**
|
2427
|
+
* Checks whether a word or a capitalization variant exists in the current dictionary.
|
2428
|
+
* The word is trimmed and several variations of capitalizations are checked.
|
2429
|
+
* If you want to check a word without any changes made to it, call checkExact()
|
2430
|
+
*
|
2431
|
+
* @see http://blog.stevenlevithan.com/archives/faster-trim-javascript re:trimming function
|
2432
|
+
*
|
2433
|
+
* @param {String} aWord The word to check.
|
2434
|
+
* @returns {Boolean}
|
2435
|
+
*/
|
2436
|
+
|
2437
|
+
check : function (aWord) {
|
2438
|
+
// Remove leading and trailing whitespace
|
2439
|
+
var trimmedWord = aWord.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
|
2440
|
+
|
2441
|
+
if (this.checkExact(trimmedWord)) {
|
2442
|
+
return true;
|
2443
|
+
}
|
2444
|
+
|
2445
|
+
// The exact word is not in the dictionary.
|
2446
|
+
if (trimmedWord.toUpperCase() === trimmedWord) {
|
2447
|
+
// The word was supplied in all uppercase.
|
2448
|
+
// Check for a capitalized form of the word.
|
2449
|
+
var capitalizedWord = trimmedWord[0] + trimmedWord.substring(1).toLowerCase();
|
2450
|
+
|
2451
|
+
if (this.hasFlag(capitalizedWord, "KEEPCASE")) {
|
2452
|
+
// Capitalization variants are not allowed for this word.
|
2453
|
+
return false;
|
2454
|
+
}
|
2455
|
+
|
2456
|
+
if (this.checkExact(capitalizedWord)) {
|
2457
|
+
return true;
|
2458
|
+
}
|
2459
|
+
}
|
2460
|
+
|
2461
|
+
var lowercaseWord = trimmedWord.toLowerCase();
|
2462
|
+
|
2463
|
+
if (lowercaseWord !== trimmedWord) {
|
2464
|
+
if (this.hasFlag(lowercaseWord, "KEEPCASE")) {
|
2465
|
+
// Capitalization variants are not allowed for this word.
|
2466
|
+
return false;
|
2467
|
+
}
|
2468
|
+
|
2469
|
+
// Check for a lowercase form
|
2470
|
+
if (this.checkExact(lowercaseWord)) {
|
2471
|
+
return true;
|
2472
|
+
}
|
2473
|
+
}
|
2474
|
+
|
2475
|
+
return false;
|
2476
|
+
},
|
2477
|
+
|
2478
|
+
/**
|
2479
|
+
* Checks whether a word exists in the current dictionary.
|
2480
|
+
*
|
2481
|
+
* @param {String} word The word to check.
|
2482
|
+
* @returns {Boolean}
|
2483
|
+
*/
|
2484
|
+
|
2485
|
+
checkExact : function (word) {
|
2486
|
+
var ruleCodes = this.dictionaryTable[word];
|
2487
|
+
|
2488
|
+
if (typeof ruleCodes === 'undefined') {
|
2489
|
+
// Check if this might be a compound word.
|
2490
|
+
if ("COMPOUNDMIN" in this.flags && word.length >= this.flags.COMPOUNDMIN) {
|
2491
|
+
for (var i = 0, _len = this.compoundRules.length; i < _len; i++) {
|
2492
|
+
if (word.match(this.compoundRules[i])) {
|
2493
|
+
return true;
|
2494
|
+
}
|
2495
|
+
}
|
2496
|
+
}
|
2497
|
+
|
2498
|
+
return false;
|
2499
|
+
}
|
2500
|
+
else if (typeof ruleCodes === 'object') { // this.dictionary['hasOwnProperty'] will be a function.
|
2501
|
+
for (var i = 0, _len = ruleCodes.length; i < _len; i++) {
|
2502
|
+
if (!this.hasFlag(word, "ONLYINCOMPOUND", ruleCodes[i])) {
|
2503
|
+
return true;
|
2504
|
+
}
|
2505
|
+
}
|
2506
|
+
|
2507
|
+
return false;
|
2508
|
+
}
|
2509
|
+
},
|
2510
|
+
|
2511
|
+
/**
|
2512
|
+
* Looks up whether a given word is flagged with a given flag.
|
2513
|
+
*
|
2514
|
+
* @param {String} word The word in question.
|
2515
|
+
* @param {String} flag The flag in question.
|
2516
|
+
* @return {Boolean}
|
2517
|
+
*/
|
2518
|
+
|
2519
|
+
hasFlag : function (word, flag, wordFlags) {
|
2520
|
+
if (flag in this.flags) {
|
2521
|
+
if (typeof wordFlags === 'undefined') {
|
2522
|
+
var wordFlags = Array.prototype.concat.apply([], this.dictionaryTable[word]);
|
2523
|
+
}
|
2524
|
+
|
2525
|
+
if (wordFlags && wordFlags.indexOf(this.flags[flag]) !== -1) {
|
2526
|
+
return true;
|
2527
|
+
}
|
2528
|
+
}
|
2529
|
+
|
2530
|
+
return false;
|
2531
|
+
},
|
2532
|
+
|
2533
|
+
/**
|
2534
|
+
* Returns a list of suggestions for a misspelled word.
|
2535
|
+
*
|
2536
|
+
* @see http://www.norvig.com/spell-correct.html for the basis of this suggestor.
|
2537
|
+
* This suggestor is primitive, but it works.
|
2538
|
+
*
|
2539
|
+
* @param {String} word The misspelling.
|
2540
|
+
* @param {Number} [limit=5] The maximum number of suggestions to return.
|
2541
|
+
* @returns {String[]} The array of suggestions.
|
2542
|
+
*/
|
2543
|
+
|
2544
|
+
alphabet : "",
|
2545
|
+
|
2546
|
+
suggest : function (word, limit) {
|
2547
|
+
if (!limit) limit = 5;
|
2548
|
+
|
2549
|
+
if (this.check(word)) return [];
|
2550
|
+
|
2551
|
+
// Check the replacement table.
|
2552
|
+
for (var i = 0, _len = this.replacementTable.length; i < _len; i++) {
|
2553
|
+
var replacementEntry = this.replacementTable[i];
|
2554
|
+
|
2555
|
+
if (word.indexOf(replacementEntry[0]) !== -1) {
|
2556
|
+
var correctedWord = word.replace(replacementEntry[0], replacementEntry[1]);
|
2557
|
+
|
2558
|
+
if (this.check(correctedWord)) {
|
2559
|
+
return [ correctedWord ];
|
2560
|
+
}
|
2561
|
+
}
|
2562
|
+
}
|
2563
|
+
|
2564
|
+
var self = this;
|
2565
|
+
self.alphabet = "abcdefghijklmnopqrstuvwxyz";
|
2566
|
+
|
2567
|
+
/*
|
2568
|
+
if (!self.alphabet) {
|
2569
|
+
// Use the alphabet as implicitly defined by the words in the dictionary.
|
2570
|
+
var alphaHash = {};
|
2571
|
+
|
2572
|
+
for (var i in self.dictionaryTable) {
|
2573
|
+
for (var j = 0, _len = i.length; j < _len; j++) {
|
2574
|
+
alphaHash[i[j]] = true;
|
2575
|
+
}
|
2576
|
+
}
|
2577
|
+
|
2578
|
+
for (var i in alphaHash) {
|
2579
|
+
self.alphabet += i;
|
2580
|
+
}
|
2581
|
+
|
2582
|
+
var alphaArray = self.alphabet.split("");
|
2583
|
+
alphaArray.sort();
|
2584
|
+
self.alphabet = alphaArray.join("");
|
2585
|
+
}
|
2586
|
+
*/
|
2587
|
+
|
2588
|
+
function edits1(words) {
|
2589
|
+
var rv = [];
|
2590
|
+
|
2591
|
+
for (var ii = 0, _iilen = words.length; ii < _iilen; ii++) {
|
2592
|
+
var word = words[ii];
|
2593
|
+
|
2594
|
+
var splits = [];
|
2595
|
+
|
2596
|
+
for (var i = 0, _len = word.length + 1; i < _len; i++) {
|
2597
|
+
splits.push([ word.substring(0, i), word.substring(i, word.length) ]);
|
2598
|
+
}
|
2599
|
+
|
2600
|
+
var deletes = [];
|
2601
|
+
|
2602
|
+
for (var i = 0, _len = splits.length; i < _len; i++) {
|
2603
|
+
var s = splits[i];
|
2604
|
+
|
2605
|
+
if (s[1]) {
|
2606
|
+
deletes.push(s[0] + s[1].substring(1));
|
2607
|
+
}
|
2608
|
+
}
|
2609
|
+
|
2610
|
+
var transposes = [];
|
2611
|
+
|
2612
|
+
for (var i = 0, _len = splits.length; i < _len; i++) {
|
2613
|
+
var s = splits[i];
|
2614
|
+
|
2615
|
+
if (s[1].length > 1) {
|
2616
|
+
transposes.push(s[0] + s[1][1] + s[1][0] + s[1].substring(2));
|
2617
|
+
}
|
2618
|
+
}
|
2619
|
+
|
2620
|
+
var replaces = [];
|
2621
|
+
|
2622
|
+
for (var i = 0, _len = splits.length; i < _len; i++) {
|
2623
|
+
var s = splits[i];
|
2624
|
+
|
2625
|
+
if (s[1]) {
|
2626
|
+
for (var j = 0, _jlen = self.alphabet.length; j < _jlen; j++) {
|
2627
|
+
replaces.push(s[0] + self.alphabet[j] + s[1].substring(1));
|
2628
|
+
}
|
2629
|
+
}
|
2630
|
+
}
|
2631
|
+
|
2632
|
+
var inserts = [];
|
2633
|
+
|
2634
|
+
for (var i = 0, _len = splits.length; i < _len; i++) {
|
2635
|
+
var s = splits[i];
|
2636
|
+
|
2637
|
+
if (s[1]) {
|
2638
|
+
for (var j = 0, _jlen = self.alphabet.length; j < _jlen; j++) {
|
2639
|
+
replaces.push(s[0] + self.alphabet[j] + s[1]);
|
2640
|
+
}
|
2641
|
+
}
|
2642
|
+
}
|
2643
|
+
|
2644
|
+
rv = rv.concat(deletes);
|
2645
|
+
rv = rv.concat(transposes);
|
2646
|
+
rv = rv.concat(replaces);
|
2647
|
+
rv = rv.concat(inserts);
|
2648
|
+
}
|
2649
|
+
|
2650
|
+
return rv;
|
2651
|
+
}
|
2652
|
+
|
2653
|
+
function known(words) {
|
2654
|
+
var rv = [];
|
2655
|
+
|
2656
|
+
for (var i = 0; i < words.length; i++) {
|
2657
|
+
if (self.check(words[i])) {
|
2658
|
+
rv.push(words[i]);
|
2659
|
+
}
|
2660
|
+
}
|
2661
|
+
|
2662
|
+
return rv;
|
2663
|
+
}
|
2664
|
+
|
2665
|
+
function correct(word) {
|
2666
|
+
// Get the edit-distance-1 and edit-distance-2 forms of this word.
|
2667
|
+
var ed1 = edits1([word]);
|
2668
|
+
var ed2 = edits1(ed1);
|
2669
|
+
|
2670
|
+
var corrections = known(ed1).concat(known(ed2));
|
2671
|
+
|
2672
|
+
// Sort the edits based on how many different ways they were created.
|
2673
|
+
var weighted_corrections = {};
|
2674
|
+
|
2675
|
+
for (var i = 0, _len = corrections.length; i < _len; i++) {
|
2676
|
+
if (!(corrections[i] in weighted_corrections)) {
|
2677
|
+
weighted_corrections[corrections[i]] = 1;
|
2678
|
+
}
|
2679
|
+
else {
|
2680
|
+
weighted_corrections[corrections[i]] += 1;
|
2681
|
+
}
|
2682
|
+
}
|
2683
|
+
|
2684
|
+
var sorted_corrections = [];
|
2685
|
+
|
2686
|
+
for (var i in weighted_corrections) {
|
2687
|
+
sorted_corrections.push([ i, weighted_corrections[i] ]);
|
2688
|
+
}
|
2689
|
+
|
2690
|
+
function sorter(a, b) {
|
2691
|
+
if (a[1] < b[1]) {
|
2692
|
+
return -1;
|
2693
|
+
}
|
2694
|
+
|
2695
|
+
return 1;
|
2696
|
+
}
|
2697
|
+
|
2698
|
+
sorted_corrections.sort(sorter).reverse();
|
2699
|
+
|
2700
|
+
var rv = [];
|
2701
|
+
|
2702
|
+
for (var i = 0, _len = Math.min(limit, sorted_corrections.length); i < _len; i++) {
|
2703
|
+
if (!self.hasFlag(sorted_corrections[i][0], "NOSUGGEST")) {
|
2704
|
+
rv.push(sorted_corrections[i][0]);
|
2705
|
+
}
|
2706
|
+
}
|
2707
|
+
|
2708
|
+
return rv;
|
2709
|
+
}
|
2710
|
+
|
2711
|
+
return correct(word);
|
2712
|
+
}
|
2713
|
+
};
|
2714
|
+
|
2715
|
+
// Support for use as a node.js module.
|
2716
|
+
if (typeof module !== 'undefined') {
|
2717
|
+
module.exports = Typo;
|
2718
|
+
}
|
2719
|
+
}).call(this,require("buffer").Buffer,"/node_modules/typo-js")
|
2720
|
+
},{"buffer":3,"fs":2}],7:[function(require,module,exports){
|
2721
|
+
// Use strict mode (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode)
|
2722
|
+
"use strict";
|
2723
|
+
|
2724
|
+
|
2725
|
+
// Requires
|
2726
|
+
var Typo = require("typo-js");
|
2727
|
+
|
2728
|
+
|
2729
|
+
// Create function
|
2730
|
+
function CodeMirrorSpellChecker(options) {
|
2731
|
+
// Initialize
|
2732
|
+
options = options || {};
|
2733
|
+
|
2734
|
+
|
2735
|
+
// Verify
|
2736
|
+
if(typeof options.codeMirrorInstance !== "function" || typeof options.codeMirrorInstance.defineMode !== "function") {
|
2737
|
+
console.log("CodeMirror Spell Checker: You must provide an instance of CodeMirror via the option `codeMirrorInstance`");
|
2738
|
+
return;
|
2739
|
+
}
|
2740
|
+
|
2741
|
+
|
2742
|
+
// Because some browsers don't support this functionality yet
|
2743
|
+
if(!String.prototype.includes) {
|
2744
|
+
String.prototype.includes = function() {
|
2745
|
+
"use strict";
|
2746
|
+
return String.prototype.indexOf.apply(this, arguments) !== -1;
|
2747
|
+
};
|
2748
|
+
}
|
2749
|
+
|
2750
|
+
|
2751
|
+
// Define the new mode
|
2752
|
+
options.codeMirrorInstance.defineMode("spell-checker", function(config) {
|
2753
|
+
// Load AFF/DIC data
|
2754
|
+
if(!CodeMirrorSpellChecker.aff_loading) {
|
2755
|
+
CodeMirrorSpellChecker.aff_loading = true;
|
2756
|
+
var xhr_aff = new XMLHttpRequest();
|
2757
|
+
xhr_aff.open("GET", "https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.aff", true);
|
2758
|
+
xhr_aff.onload = function() {
|
2759
|
+
if(xhr_aff.readyState === 4 && xhr_aff.status === 200) {
|
2760
|
+
CodeMirrorSpellChecker.aff_data = xhr_aff.responseText;
|
2761
|
+
CodeMirrorSpellChecker.num_loaded++;
|
2762
|
+
|
2763
|
+
if(CodeMirrorSpellChecker.num_loaded == 2) {
|
2764
|
+
CodeMirrorSpellChecker.typo = new Typo("en_US", CodeMirrorSpellChecker.aff_data, CodeMirrorSpellChecker.dic_data, {
|
2765
|
+
platform: "any"
|
2766
|
+
});
|
2767
|
+
}
|
2768
|
+
}
|
2769
|
+
};
|
2770
|
+
xhr_aff.send(null);
|
2771
|
+
}
|
2772
|
+
|
2773
|
+
if(!CodeMirrorSpellChecker.dic_loading) {
|
2774
|
+
CodeMirrorSpellChecker.dic_loading = true;
|
2775
|
+
var xhr_dic = new XMLHttpRequest();
|
2776
|
+
xhr_dic.open("GET", "https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.dic", true);
|
2777
|
+
xhr_dic.onload = function() {
|
2778
|
+
if(xhr_dic.readyState === 4 && xhr_dic.status === 200) {
|
2779
|
+
CodeMirrorSpellChecker.dic_data = xhr_dic.responseText;
|
2780
|
+
CodeMirrorSpellChecker.num_loaded++;
|
2781
|
+
|
2782
|
+
if(CodeMirrorSpellChecker.num_loaded == 2) {
|
2783
|
+
CodeMirrorSpellChecker.typo = new Typo("en_US", CodeMirrorSpellChecker.aff_data, CodeMirrorSpellChecker.dic_data, {
|
2784
|
+
platform: "any"
|
2785
|
+
});
|
2786
|
+
}
|
2787
|
+
}
|
2788
|
+
};
|
2789
|
+
xhr_dic.send(null);
|
2790
|
+
}
|
2791
|
+
|
2792
|
+
|
2793
|
+
// Define what separates a word
|
2794
|
+
var rx_word = "!\"#$%&()*+,-./:;<=>?@[\\]^_`{|}~ ";
|
2795
|
+
|
2796
|
+
|
2797
|
+
// Create the overlay and such
|
2798
|
+
var overlay = {
|
2799
|
+
token: function(stream) {
|
2800
|
+
var ch = stream.peek();
|
2801
|
+
var word = "";
|
2802
|
+
|
2803
|
+
if(rx_word.includes(ch)) {
|
2804
|
+
stream.next();
|
2805
|
+
return null;
|
2806
|
+
}
|
2807
|
+
|
2808
|
+
while((ch = stream.peek()) != null && !rx_word.includes(ch)) {
|
2809
|
+
word += ch;
|
2810
|
+
stream.next();
|
2811
|
+
}
|
2812
|
+
|
2813
|
+
if(CodeMirrorSpellChecker.typo && !CodeMirrorSpellChecker.typo.check(word))
|
2814
|
+
return "spell-error"; // CSS class: cm-spell-error
|
2815
|
+
|
2816
|
+
return null;
|
2817
|
+
}
|
2818
|
+
};
|
2819
|
+
|
2820
|
+
var mode = options.codeMirrorInstance.getMode(
|
2821
|
+
config, config.backdrop || "text/plain"
|
2822
|
+
);
|
2823
|
+
|
2824
|
+
return options.codeMirrorInstance.overlayMode(mode, overlay, true);
|
2825
|
+
});
|
2826
|
+
}
|
2827
|
+
|
2828
|
+
|
2829
|
+
// Initialize data globally to reduce memory consumption
|
2830
|
+
CodeMirrorSpellChecker.num_loaded = 0;
|
2831
|
+
CodeMirrorSpellChecker.aff_loading = false;
|
2832
|
+
CodeMirrorSpellChecker.dic_loading = false;
|
2833
|
+
CodeMirrorSpellChecker.aff_data = "";
|
2834
|
+
CodeMirrorSpellChecker.dic_data = "";
|
2835
|
+
CodeMirrorSpellChecker.typo;
|
2836
|
+
|
2837
|
+
|
2838
|
+
// Export
|
2839
|
+
module.exports = CodeMirrorSpellChecker;
|
2840
|
+
},{"typo-js":6}]},{},[7])(7)
|
2841
|
+
});
|