ai 1.1.0 → 2.0.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.
- package/LICENSE +10 -24
- package/dist/ai-stream.d.ts +18 -0
- package/dist/ai-stream.js +132 -0
- package/dist/ai-stream.mjs +13 -0
- package/dist/anthropic-stream.d.ts +5 -0
- package/dist/anthropic-stream.js +133 -0
- package/dist/anthropic-stream.mjs +8 -0
- package/dist/chunk-265FSSO4.mjs +91 -0
- package/dist/chunk-2L3ZO4UM.mjs +45 -0
- package/dist/chunk-EZJ7FC5E.mjs +33 -0
- package/dist/chunk-JGDC3BXD.mjs +22 -0
- package/dist/chunk-NK2CVBLI.mjs +38 -0
- package/dist/chunk-PEYAHBDF.mjs +43 -0
- package/dist/chunk-TJMME6CL.mjs +24 -0
- package/dist/huggingface-stream.d.ts +5 -0
- package/dist/huggingface-stream.js +121 -0
- package/dist/huggingface-stream.mjs +8 -0
- package/dist/index.d.ts +131 -0
- package/dist/index.js +278 -0
- package/dist/index.mjs +35 -0
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.js +12 -0
- package/dist/index.test.mjs +10 -0
- package/dist/langchain-stream.d.ts +12 -0
- package/dist/langchain-stream.js +102 -0
- package/dist/langchain-stream.mjs +8 -0
- package/dist/openai-stream.d.ts +5 -0
- package/dist/openai-stream.js +144 -0
- package/dist/openai-stream.mjs +8 -0
- package/dist/streaming-text-response.d.ts +17 -0
- package/dist/streaming-text-response.js +75 -0
- package/dist/streaming-text-response.mjs +9 -0
- package/package.json +78 -29
- package/react/dist/chunk-5PP6W52J.mjs +202 -0
- package/react/dist/chunk-6EH3SWMP.mjs +55 -0
- package/react/dist/chunk-PW6HSU2N.mjs +154 -0
- package/react/dist/index.d.ts +3 -0
- package/react/dist/index.js +424 -0
- package/react/dist/index.mjs +12 -0
- package/react/dist/types-f862f74a.d.ts +123 -0
- package/react/dist/use-chat.d.ts +42 -0
- package/react/dist/use-chat.js +276 -0
- package/react/dist/use-chat.mjs +8 -0
- package/react/dist/use-completion.d.ts +47 -0
- package/react/dist/use-completion.js +229 -0
- package/react/dist/use-completion.mjs +8 -0
- package/svelte/dist/chunk-6USBQIV6.mjs +177 -0
- package/svelte/dist/chunk-BQ64GHZ3.mjs +136 -0
- package/svelte/dist/chunk-CENOSGDG.mjs +493 -0
- package/svelte/dist/index.d.ts +4 -0
- package/svelte/dist/index.js +808 -0
- package/svelte/dist/index.mjs +11 -0
- package/svelte/dist/types-f862f74a.d.ts +123 -0
- package/svelte/dist/use-chat.d.ts +39 -0
- package/svelte/dist/use-chat.js +680 -0
- package/svelte/dist/use-chat.mjs +7 -0
- package/svelte/dist/use-completion.d.ts +38 -0
- package/svelte/dist/use-completion.js +640 -0
- package/svelte/dist/use-completion.mjs +7 -0
- package/.npmignore +0 -15
- package/.travis.yml +0 -4
- package/README.md +0 -21
- package/bin/ai.js +0 -22
- package/index.js +0 -37
- package/node_modules/request/.npmignore +0 -2
- package/node_modules/request/.travis.yml +0 -12
- package/node_modules/request/CHANGELOG.md +0 -954
- package/node_modules/request/LICENSE +0 -55
- package/node_modules/request/README.md +0 -421
- package/node_modules/request/index.js +0 -166
- package/node_modules/request/lib/cookies.js +0 -40
- package/node_modules/request/lib/copy.js +0 -8
- package/node_modules/request/lib/debug.js +0 -7
- package/node_modules/request/lib/getSafe.js +0 -34
- package/node_modules/request/lib/optional.js +0 -5
- package/node_modules/request/node_modules/aws-sign2/LICENSE +0 -55
- package/node_modules/request/node_modules/aws-sign2/README.md +0 -4
- package/node_modules/request/node_modules/aws-sign2/index.js +0 -202
- package/node_modules/request/node_modules/aws-sign2/package.json +0 -47
- package/node_modules/request/node_modules/forever-agent/LICENSE +0 -55
- package/node_modules/request/node_modules/forever-agent/README.md +0 -4
- package/node_modules/request/node_modules/forever-agent/index.js +0 -119
- package/node_modules/request/node_modules/forever-agent/package.json +0 -46
- package/node_modules/request/node_modules/form-data/License +0 -19
- package/node_modules/request/node_modules/form-data/Readme.md +0 -175
- package/node_modules/request/node_modules/form-data/lib/form_data.js +0 -351
- package/node_modules/request/node_modules/form-data/node_modules/async/.travis.yml +0 -3
- package/node_modules/request/node_modules/form-data/node_modules/async/LICENSE +0 -19
- package/node_modules/request/node_modules/form-data/node_modules/async/README.md +0 -1646
- package/node_modules/request/node_modules/form-data/node_modules/async/component.json +0 -11
- package/node_modules/request/node_modules/form-data/node_modules/async/lib/async.js +0 -1123
- package/node_modules/request/node_modules/form-data/node_modules/async/package.json +0 -60
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/License +0 -19
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/Readme.md +0 -132
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/lib/combined_stream.js +0 -186
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/.npmignore +0 -2
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/License +0 -19
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/Makefile +0 -7
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/Readme.md +0 -154
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/lib/delayed_stream.js +0 -99
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/package.json +0 -42
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/common.js +0 -6
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-http-upload.js +0 -38
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-stream-auto-pause.js +0 -21
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-stream-pause.js +0 -14
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-stream.js +0 -48
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-handle-source-errors.js +0 -15
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-max-data-size.js +0 -18
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-pipe-resumes.js +0 -13
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-proxy-readable.js +0 -13
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/run.js +0 -7
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/package.json +0 -61
- package/node_modules/request/node_modules/form-data/node_modules/mime/LICENSE +0 -19
- package/node_modules/request/node_modules/form-data/node_modules/mime/README.md +0 -66
- package/node_modules/request/node_modules/form-data/node_modules/mime/mime.js +0 -114
- package/node_modules/request/node_modules/form-data/node_modules/mime/package.json +0 -59
- package/node_modules/request/node_modules/form-data/node_modules/mime/test.js +0 -84
- package/node_modules/request/node_modules/form-data/node_modules/mime/types/mime.types +0 -1588
- package/node_modules/request/node_modules/form-data/node_modules/mime/types/node.types +0 -77
- package/node_modules/request/node_modules/form-data/package.json +0 -80
- package/node_modules/request/node_modules/hawk/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/LICENSE +0 -24
- package/node_modules/request/node_modules/hawk/Makefile +0 -10
- package/node_modules/request/node_modules/hawk/README.md +0 -625
- package/node_modules/request/node_modules/hawk/example/usage.js +0 -78
- package/node_modules/request/node_modules/hawk/images/hawk.png +0 -0
- package/node_modules/request/node_modules/hawk/images/logo.png +0 -0
- package/node_modules/request/node_modules/hawk/index.js +0 -1
- package/node_modules/request/node_modules/hawk/lib/browser.js +0 -507
- package/node_modules/request/node_modules/hawk/lib/client.js +0 -371
- package/node_modules/request/node_modules/hawk/lib/crypto.js +0 -118
- package/node_modules/request/node_modules/hawk/lib/index.js +0 -15
- package/node_modules/request/node_modules/hawk/lib/server.js +0 -523
- package/node_modules/request/node_modules/hawk/lib/utils.js +0 -183
- package/node_modules/request/node_modules/hawk/node_modules/boom/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/node_modules/boom/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/node_modules/boom/LICENSE +0 -24
- package/node_modules/request/node_modules/hawk/node_modules/boom/Makefile +0 -11
- package/node_modules/request/node_modules/hawk/node_modules/boom/README.md +0 -6
- package/node_modules/request/node_modules/hawk/node_modules/boom/images/boom.png +0 -0
- package/node_modules/request/node_modules/hawk/node_modules/boom/index.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/boom/lib/index.js +0 -207
- package/node_modules/request/node_modules/hawk/node_modules/boom/package.json +0 -64
- package/node_modules/request/node_modules/hawk/node_modules/boom/test/index.js +0 -245
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/LICENSE +0 -24
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/Makefile +0 -11
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/README.md +0 -6
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/index.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/lib/index.js +0 -68
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/package.json +0 -65
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/test/index.js +0 -101
- package/node_modules/request/node_modules/hawk/node_modules/hoek/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/node_modules/hoek/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/node_modules/hoek/LICENSE +0 -33
- package/node_modules/request/node_modules/hawk/node_modules/hoek/Makefile +0 -10
- package/node_modules/request/node_modules/hawk/node_modules/hoek/README.md +0 -436
- package/node_modules/request/node_modules/hawk/node_modules/hoek/images/hoek.png +0 -0
- package/node_modules/request/node_modules/hawk/node_modules/hoek/index.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/hoek/lib/escape.js +0 -132
- package/node_modules/request/node_modules/hawk/node_modules/hoek/lib/index.js +0 -585
- package/node_modules/request/node_modules/hawk/node_modules/hoek/package.json +0 -70
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/escaper.js +0 -86
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/index.js +0 -1078
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test1.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test2.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test3.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/sntp/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/node_modules/sntp/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/node_modules/sntp/LICENSE +0 -24
- package/node_modules/request/node_modules/hawk/node_modules/sntp/Makefile +0 -11
- package/node_modules/request/node_modules/hawk/node_modules/sntp/README.md +0 -68
- package/node_modules/request/node_modules/hawk/node_modules/sntp/examples/offset.js +0 -16
- package/node_modules/request/node_modules/hawk/node_modules/sntp/examples/time.js +0 -25
- package/node_modules/request/node_modules/hawk/node_modules/sntp/index.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/sntp/lib/index.js +0 -409
- package/node_modules/request/node_modules/hawk/node_modules/sntp/package.json +0 -65
- package/node_modules/request/node_modules/hawk/node_modules/sntp/test/index.js +0 -359
- package/node_modules/request/node_modules/hawk/package.json +0 -70
- package/node_modules/request/node_modules/hawk/test/browser.js +0 -817
- package/node_modules/request/node_modules/hawk/test/client.js +0 -206
- package/node_modules/request/node_modules/hawk/test/crypto.js +0 -86
- package/node_modules/request/node_modules/hawk/test/index.js +0 -316
- package/node_modules/request/node_modules/hawk/test/message.js +0 -246
- package/node_modules/request/node_modules/hawk/test/readme.js +0 -98
- package/node_modules/request/node_modules/hawk/test/server.js +0 -686
- package/node_modules/request/node_modules/hawk/test/uri.js +0 -456
- package/node_modules/request/node_modules/hawk/test/utils.js +0 -120
- package/node_modules/request/node_modules/http-signature/.dir-locals.el +0 -6
- package/node_modules/request/node_modules/http-signature/.npmignore +0 -7
- package/node_modules/request/node_modules/http-signature/LICENSE +0 -18
- package/node_modules/request/node_modules/http-signature/README.md +0 -75
- package/node_modules/request/node_modules/http-signature/http_signing.md +0 -296
- package/node_modules/request/node_modules/http-signature/lib/index.js +0 -25
- package/node_modules/request/node_modules/http-signature/lib/parser.js +0 -304
- package/node_modules/request/node_modules/http-signature/lib/signer.js +0 -179
- package/node_modules/request/node_modules/http-signature/lib/util.js +0 -249
- package/node_modules/request/node_modules/http-signature/lib/verify.js +0 -42
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/.npmignore +0 -2
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/LICENSE +0 -19
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/README.md +0 -50
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/errors.js +0 -13
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/index.js +0 -27
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/reader.js +0 -267
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/types.js +0 -36
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/writer.js +0 -317
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/index.js +0 -20
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/package.json +0 -63
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/tst/ber/reader.test.js +0 -172
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/tst/ber/writer.test.js +0 -296
- package/node_modules/request/node_modules/http-signature/node_modules/assert-plus/README.md +0 -126
- package/node_modules/request/node_modules/http-signature/node_modules/assert-plus/assert.js +0 -196
- package/node_modules/request/node_modules/http-signature/node_modules/assert-plus/package.json +0 -38
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/CHANGELOG +0 -71
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/LICENSE +0 -24
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/README +0 -82
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/README.old +0 -298
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/ctf.js +0 -245
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/ctio.js +0 -1485
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/ctype.js +0 -944
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/man/man3ctype/ctio.3ctype +0 -241
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/package.json +0 -36
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tools/jsl.conf +0 -129
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tools/jsstyle +0 -839
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/float.json +0 -13
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/int.json +0 -13
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/psinfo.json +0 -104
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/struct.json +0 -19
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.fail.js +0 -39
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.float.js +0 -14
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.int.js +0 -14
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.psinfo.js +0 -17
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.struct.js +0 -18
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.typedef.js +0 -15
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/typedef.json +0 -14
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/float/tst.rfloat.js +0 -767
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/float/tst.wfloat.js +0 -753
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.64.js +0 -638
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.rint.js +0 -101
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.wbounds.js +0 -53
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.wint.js +0 -92
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.64.js +0 -451
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.roundtrip.js +0 -81
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.ruint.js +0 -95
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.wuint.js +0 -156
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.basicr.js +0 -50
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.basicw.js +0 -44
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.char.js +0 -42
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.endian.js +0 -45
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.oldwrite.js +0 -28
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.readSize.js +0 -128
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.structw.js +0 -28
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.writeStruct.js +0 -31
- package/node_modules/request/node_modules/http-signature/package.json +0 -54
- package/node_modules/request/node_modules/json-stringify-safe/LICENSE +0 -27
- package/node_modules/request/node_modules/json-stringify-safe/README.md +0 -49
- package/node_modules/request/node_modules/json-stringify-safe/package.json +0 -51
- package/node_modules/request/node_modules/json-stringify-safe/stringify.js +0 -39
- package/node_modules/request/node_modules/json-stringify-safe/test.js +0 -128
- package/node_modules/request/node_modules/mime-types/.npmignore +0 -14
- package/node_modules/request/node_modules/mime-types/.travis.yml +0 -12
- package/node_modules/request/node_modules/mime-types/LICENSE +0 -22
- package/node_modules/request/node_modules/mime-types/Makefile +0 -9
- package/node_modules/request/node_modules/mime-types/README.md +0 -101
- package/node_modules/request/node_modules/mime-types/SOURCES.md +0 -17
- package/node_modules/request/node_modules/mime-types/component.json +0 -16
- package/node_modules/request/node_modules/mime-types/lib/custom.json +0 -27
- package/node_modules/request/node_modules/mime-types/lib/index.js +0 -75
- package/node_modules/request/node_modules/mime-types/lib/mime.json +0 -3317
- package/node_modules/request/node_modules/mime-types/lib/node.json +0 -55
- package/node_modules/request/node_modules/mime-types/package.json +0 -69
- package/node_modules/request/node_modules/node-uuid/.npmignore +0 -2
- package/node_modules/request/node_modules/node-uuid/LICENSE.md +0 -2
- package/node_modules/request/node_modules/node-uuid/README.md +0 -207
- package/node_modules/request/node_modules/node-uuid/benchmark/README.md +0 -53
- package/node_modules/request/node_modules/node-uuid/benchmark/bench.gnu +0 -174
- package/node_modules/request/node_modules/node-uuid/benchmark/bench.sh +0 -34
- package/node_modules/request/node_modules/node-uuid/benchmark/benchmark-native.c +0 -34
- package/node_modules/request/node_modules/node-uuid/benchmark/benchmark.js +0 -84
- package/node_modules/request/node_modules/node-uuid/component.json +0 -18
- package/node_modules/request/node_modules/node-uuid/package.json +0 -54
- package/node_modules/request/node_modules/node-uuid/test/compare_v1.js +0 -63
- package/node_modules/request/node_modules/node-uuid/test/test.html +0 -17
- package/node_modules/request/node_modules/node-uuid/test/test.js +0 -228
- package/node_modules/request/node_modules/node-uuid/uuid.js +0 -245
- package/node_modules/request/node_modules/oauth-sign/LICENSE +0 -55
- package/node_modules/request/node_modules/oauth-sign/README.md +0 -4
- package/node_modules/request/node_modules/oauth-sign/index.js +0 -43
- package/node_modules/request/node_modules/oauth-sign/package.json +0 -49
- package/node_modules/request/node_modules/oauth-sign/test.js +0 -49
- package/node_modules/request/node_modules/qs/.jshintignore +0 -1
- package/node_modules/request/node_modules/qs/.jshintrc +0 -10
- package/node_modules/request/node_modules/qs/.npmignore +0 -18
- package/node_modules/request/node_modules/qs/.travis.yml +0 -4
- package/node_modules/request/node_modules/qs/LICENSE +0 -28
- package/node_modules/request/node_modules/qs/Makefile +0 -8
- package/node_modules/request/node_modules/qs/Readme.md +0 -120
- package/node_modules/request/node_modules/qs/index.js +0 -1
- package/node_modules/request/node_modules/qs/lib/index.js +0 -15
- package/node_modules/request/node_modules/qs/lib/parse.js +0 -151
- package/node_modules/request/node_modules/qs/lib/stringify.js +0 -52
- package/node_modules/request/node_modules/qs/lib/utils.js +0 -131
- package/node_modules/request/node_modules/qs/package.json +0 -61
- package/node_modules/request/node_modules/qs/test/parse.js +0 -236
- package/node_modules/request/node_modules/qs/test/stringify.js +0 -123
- package/node_modules/request/node_modules/stringstream/.npmignore +0 -15
- package/node_modules/request/node_modules/stringstream/.travis.yml +0 -4
- package/node_modules/request/node_modules/stringstream/LICENSE.txt +0 -4
- package/node_modules/request/node_modules/stringstream/README.md +0 -38
- package/node_modules/request/node_modules/stringstream/example.js +0 -27
- package/node_modules/request/node_modules/stringstream/package.json +0 -48
- package/node_modules/request/node_modules/stringstream/stringstream.js +0 -102
- package/node_modules/request/node_modules/tough-cookie/.jshintrc +0 -70
- package/node_modules/request/node_modules/tough-cookie/.npmignore +0 -3
- package/node_modules/request/node_modules/tough-cookie/.travis.yml +0 -8
- package/node_modules/request/node_modules/tough-cookie/LICENSE +0 -78
- package/node_modules/request/node_modules/tough-cookie/README.md +0 -412
- package/node_modules/request/node_modules/tough-cookie/generate-pubsuffix.js +0 -239
- package/node_modules/request/node_modules/tough-cookie/lib/cookie.js +0 -1107
- package/node_modules/request/node_modules/tough-cookie/lib/memstore.js +0 -123
- package/node_modules/request/node_modules/tough-cookie/lib/pubsuffix.js +0 -69
- package/node_modules/request/node_modules/tough-cookie/lib/store.js +0 -37
- package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/LICENSE-MIT.txt +0 -20
- package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/README.md +0 -176
- package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/package.json +0 -87
- package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/punycode.js +0 -528
- package/node_modules/request/node_modules/tough-cookie/package.json +0 -67
- package/node_modules/request/node_modules/tough-cookie/public-suffix.txt +0 -5229
- package/node_modules/request/node_modules/tough-cookie/test.js +0 -1625
- package/node_modules/request/node_modules/tunnel-agent/.jshintrc +0 -5
- package/node_modules/request/node_modules/tunnel-agent/LICENSE +0 -55
- package/node_modules/request/node_modules/tunnel-agent/README.md +0 -4
- package/node_modules/request/node_modules/tunnel-agent/index.js +0 -236
- package/node_modules/request/node_modules/tunnel-agent/package.json +0 -46
- package/node_modules/request/package.json +0 -77
- package/node_modules/request/request.js +0 -1428
- package/test/fixtures/github-response.json +0 -1367
- package/test/index.js +0 -55
@@ -1,436 +0,0 @@
|
|
1
|
-
<a href="https://github.com/spumko"><img src="https://raw.github.com/spumko/spumko/master/images/from.png" align="right" /></a>
|
2
|
-

|
3
|
-
|
4
|
-
General purpose node utilities
|
5
|
-
|
6
|
-
[](http://travis-ci.org/spumko/hoek)
|
7
|
-
|
8
|
-
# Table of Contents
|
9
|
-
|
10
|
-
* [Introduction](#introduction "Introduction")
|
11
|
-
* [Object](#object "Object")
|
12
|
-
* [clone](#cloneobj "clone")
|
13
|
-
* [merge](#mergetarget-source-isnulloverride-ismergearrays "merge")
|
14
|
-
* [applyToDefaults](#applytodefaultsdefaults-options "applyToDefaults")
|
15
|
-
* [unique](#uniquearray-key "unique")
|
16
|
-
* [mapToObject](#maptoobjectarray-key "mapToObject")
|
17
|
-
* [intersect](#intersectarray1-array2 "intersect")
|
18
|
-
* [matchKeys](#matchkeysobj-keys "matchKeys")
|
19
|
-
* [flatten](#flattenarray-target "flatten")
|
20
|
-
* [removeKeys](#removekeysobject-keys "removeKeys")
|
21
|
-
* [reach](#reachobj-chain "reach")
|
22
|
-
* [inheritAsync](#inheritasyncself-obj-keys "inheritAsync")
|
23
|
-
* [rename](#renameobj-from-to "rename")
|
24
|
-
* [Timer](#timer "Timer")
|
25
|
-
* [Binary Encoding/Decoding](#binary "Binary Encoding/Decoding")
|
26
|
-
* [base64urlEncode](#binary64urlEncodevalue "binary64urlEncode")
|
27
|
-
* [base64urlDecode](#binary64urlDecodevalue "binary64urlDecode")
|
28
|
-
* [Escaping Characters](#escaped "Escaping Characters")
|
29
|
-
* [escapeHtml](#escapeHtmlstring "escapeHtml")
|
30
|
-
* [escapeHeaderAttribute](#escapeHeaderAttributeattribute "escapeHeaderAttribute")
|
31
|
-
* [escapeRegex](#escapeRegexstring "escapeRegex")
|
32
|
-
* [Errors](#errors "Errors")
|
33
|
-
* [assert](#assertmessage "assert")
|
34
|
-
* [abort](#abortmessage "abort")
|
35
|
-
* [displayStack](#displayStackslice "displayStack")
|
36
|
-
* [callStack](#callStackslice "callStack")
|
37
|
-
* [toss](#tosscondition "toss")
|
38
|
-
* [Load files](#load-files "Load Files")
|
39
|
-
* [loadPackage](#loadPackagedir "loadpackage")
|
40
|
-
* [loadDirModules](#loadDirModulespath-excludefiles-target "loaddirmodules")
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
# Introduction
|
45
|
-
|
46
|
-
The *Hoek* general purpose node utilities library is used to aid in a variety of manners. It comes with useful methods for Arrays (clone, merge, applyToDefaults), Objects (removeKeys, copy), Asserting and more.
|
47
|
-
|
48
|
-
For example, to use Hoek to set configuration with default options:
|
49
|
-
```javascript
|
50
|
-
var Hoek = require('hoek');
|
51
|
-
|
52
|
-
var default = {url : "www.github.com", port : "8000", debug : true}
|
53
|
-
|
54
|
-
var config = Hoek.applyToDefaults(default, {port : "3000", admin : true});
|
55
|
-
|
56
|
-
// In this case, config would be { url: 'www.github.com', port: '3000', debug: true, admin: true }
|
57
|
-
```
|
58
|
-
|
59
|
-
Under each of the sections (such as Array), there are subsections which correspond to Hoek methods. Each subsection will explain how to use the corresponding method. In each js excerpt below, the var Hoek = require('hoek') is omitted for brevity.
|
60
|
-
|
61
|
-
## Object
|
62
|
-
|
63
|
-
Hoek provides several helpful methods for objects and arrays.
|
64
|
-
|
65
|
-
### clone(obj)
|
66
|
-
|
67
|
-
This method is used to clone an object or an array. A *deep copy* is made (duplicates everything, including values that are objects).
|
68
|
-
|
69
|
-
```javascript
|
70
|
-
|
71
|
-
var nestedObj = {
|
72
|
-
w: /^something$/ig,
|
73
|
-
x: {
|
74
|
-
a: [1, 2, 3],
|
75
|
-
b: 123456,
|
76
|
-
c: new Date()
|
77
|
-
},
|
78
|
-
y: 'y',
|
79
|
-
z: new Date()
|
80
|
-
};
|
81
|
-
|
82
|
-
var copy = Hoek.clone(nestedObj);
|
83
|
-
|
84
|
-
copy.x.b = 100;
|
85
|
-
|
86
|
-
console.log(copy.y) // results in 'y'
|
87
|
-
console.log(nestedObj.x.b) // results in 123456
|
88
|
-
console.log(copy.x.b) // results in 100
|
89
|
-
```
|
90
|
-
|
91
|
-
### merge(target, source, isNullOverride, isMergeArrays)
|
92
|
-
isNullOverride, isMergeArrays default to true
|
93
|
-
|
94
|
-
Merge all the properties of source into target, source wins in conflic, and by default null and undefined from source are applied
|
95
|
-
|
96
|
-
|
97
|
-
```javascript
|
98
|
-
|
99
|
-
var target = {a: 1, b : 2}
|
100
|
-
var source = {a: 0, c: 5}
|
101
|
-
var source2 = {a: null, c: 5}
|
102
|
-
|
103
|
-
var targetArray = [1, 2, 3];
|
104
|
-
var sourceArray = [4, 5];
|
105
|
-
|
106
|
-
var newTarget = Hoek.merge(target, source); // results in {a: 0, b: 2, c: 5}
|
107
|
-
newTarget = Hoek.merge(target, source2); // results in {a: null, b: 2, c: 5}
|
108
|
-
newTarget = Hoek.merge(target, source2, false); // results in {a: 1, b: 2, c: 5}
|
109
|
-
|
110
|
-
newTarget = Hoek.merge(targetArray, sourceArray) // results in [1, 2, 3, 4, 5]
|
111
|
-
newTarget = Hoek.merge(targetArray, sourceArray, true, false) // results in [4, 5]
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
```
|
117
|
-
|
118
|
-
### applyToDefaults(defaults, options)
|
119
|
-
|
120
|
-
Apply options to a copy of the defaults
|
121
|
-
|
122
|
-
```javascript
|
123
|
-
|
124
|
-
var defaults = {host: "localhost", port: 8000};
|
125
|
-
var options = {port: 8080};
|
126
|
-
|
127
|
-
var config = Hoek.applyToDefaults(defaults, options); // results in {host: "localhost", port: 8080};
|
128
|
-
|
129
|
-
|
130
|
-
```
|
131
|
-
|
132
|
-
### unique(array, key)
|
133
|
-
|
134
|
-
Remove duplicate items from Array
|
135
|
-
|
136
|
-
```javascript
|
137
|
-
|
138
|
-
var array = [1, 2, 2, 3, 3, 4, 5, 6];
|
139
|
-
|
140
|
-
var newArray = Hoek.unique(array); // results in [1,2,3,4,5,6];
|
141
|
-
|
142
|
-
array = [{id: 1}, {id: 1}, {id: 2}];
|
143
|
-
|
144
|
-
newArray = Hoek.unique(array, "id") // results in [{id: 1}, {id: 2}]
|
145
|
-
|
146
|
-
```
|
147
|
-
|
148
|
-
### mapToObject(array, key)
|
149
|
-
|
150
|
-
Convert an Array into an Object
|
151
|
-
|
152
|
-
```javascript
|
153
|
-
|
154
|
-
var array = [1,2,3];
|
155
|
-
var newObject = Hoek.mapToObject(array); // results in [{"1": true}, {"2": true}, {"3": true}]
|
156
|
-
|
157
|
-
array = [{id: 1}, {id: 2}];
|
158
|
-
newObject = Hoek.mapToObject(array, "id") // results in [{"id": 1}, {"id": 2}]
|
159
|
-
|
160
|
-
```
|
161
|
-
### intersect(array1, array2)
|
162
|
-
|
163
|
-
Find the common unique items in two arrays
|
164
|
-
|
165
|
-
```javascript
|
166
|
-
|
167
|
-
var array1 = [1, 2, 3];
|
168
|
-
var array2 = [1, 4, 5];
|
169
|
-
|
170
|
-
var newArray = Hoek.intersect(array1, array2) // results in [1]
|
171
|
-
|
172
|
-
```
|
173
|
-
|
174
|
-
### matchKeys(obj, keys)
|
175
|
-
|
176
|
-
Find which keys are present
|
177
|
-
|
178
|
-
```javascript
|
179
|
-
|
180
|
-
var obj = {a: 1, b: 2, c: 3};
|
181
|
-
var keys = ["a", "e"];
|
182
|
-
|
183
|
-
Hoek.matchKeys(obj, keys) // returns ["a"]
|
184
|
-
|
185
|
-
```
|
186
|
-
|
187
|
-
### flatten(array, target)
|
188
|
-
|
189
|
-
Flatten an array
|
190
|
-
|
191
|
-
```javascript
|
192
|
-
|
193
|
-
var array = [1, 2, 3];
|
194
|
-
var target = [4, 5];
|
195
|
-
|
196
|
-
var flattenedArray = Hoek.flatten(array, target) // results in [4, 5, 1, 2, 3];
|
197
|
-
|
198
|
-
```
|
199
|
-
|
200
|
-
### removeKeys(object, keys)
|
201
|
-
|
202
|
-
Remove keys
|
203
|
-
|
204
|
-
```javascript
|
205
|
-
|
206
|
-
var object = {a: 1, b: 2, c: 3, d: 4};
|
207
|
-
|
208
|
-
var keys = ["a", "b"];
|
209
|
-
|
210
|
-
Hoek.removeKeys(object, keys) // object is now {c: 3, d: 4}
|
211
|
-
|
212
|
-
```
|
213
|
-
|
214
|
-
### reach(obj, chain)
|
215
|
-
|
216
|
-
Converts an object key chain string to reference
|
217
|
-
|
218
|
-
```javascript
|
219
|
-
|
220
|
-
var chain = 'a.b.c';
|
221
|
-
var obj = {a : {b : { c : 1}}};
|
222
|
-
|
223
|
-
Hoek.reach(obj, chain) // returns 1
|
224
|
-
|
225
|
-
```
|
226
|
-
|
227
|
-
### inheritAsync(self, obj, keys)
|
228
|
-
|
229
|
-
Inherits a selected set of methods from an object, wrapping functions in asynchronous syntax and catching errors
|
230
|
-
|
231
|
-
```javascript
|
232
|
-
|
233
|
-
var targetFunc = function () { };
|
234
|
-
|
235
|
-
var proto = {
|
236
|
-
a: function () {
|
237
|
-
return 'a!';
|
238
|
-
},
|
239
|
-
b: function () {
|
240
|
-
return 'b!';
|
241
|
-
},
|
242
|
-
c: function () {
|
243
|
-
throw new Error('c!');
|
244
|
-
}
|
245
|
-
};
|
246
|
-
|
247
|
-
var keys = ['a', 'c'];
|
248
|
-
|
249
|
-
Hoek.inheritAsync(targetFunc, proto, ['a', 'c']);
|
250
|
-
|
251
|
-
var target = new targetFunc();
|
252
|
-
|
253
|
-
target.a(function(err, result){console.log(result)} // returns 'a!'
|
254
|
-
|
255
|
-
target.c(function(err, result){console.log(result)} // returns undefined
|
256
|
-
|
257
|
-
target.b(function(err, result){console.log(result)} // gives error: Object [object Object] has no method 'b'
|
258
|
-
|
259
|
-
```
|
260
|
-
|
261
|
-
### rename(obj, from, to)
|
262
|
-
|
263
|
-
Rename a key of an object
|
264
|
-
|
265
|
-
```javascript
|
266
|
-
|
267
|
-
var obj = {a : 1, b : 2};
|
268
|
-
|
269
|
-
Hoek.rename(obj, "a", "c"); // obj is now {c : 1, b : 2}
|
270
|
-
|
271
|
-
```
|
272
|
-
|
273
|
-
|
274
|
-
# Timer
|
275
|
-
|
276
|
-
A Timer object. Initializing a new timer object sets the ts to the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.
|
277
|
-
|
278
|
-
```javascript
|
279
|
-
|
280
|
-
|
281
|
-
example :
|
282
|
-
|
283
|
-
|
284
|
-
var timerObj = new Hoek.Timer();
|
285
|
-
console.log("Time is now: " + timerObj.ts)
|
286
|
-
console.log("Elapsed time from initialization: " + timerObj.elapsed() + 'milliseconds')
|
287
|
-
|
288
|
-
```
|
289
|
-
|
290
|
-
# Binary Encoding/Decoding
|
291
|
-
|
292
|
-
### base64urlEncode(value)
|
293
|
-
|
294
|
-
Encodes value in Base64 or URL encoding
|
295
|
-
|
296
|
-
### base64urlDecode(value)
|
297
|
-
|
298
|
-
Decodes data in Base64 or URL encoding.
|
299
|
-
# Escaping Characters
|
300
|
-
|
301
|
-
Hoek provides convenient methods for escaping html characters. The escaped characters are as followed:
|
302
|
-
|
303
|
-
```javascript
|
304
|
-
|
305
|
-
internals.htmlEscaped = {
|
306
|
-
'&': '&',
|
307
|
-
'<': '<',
|
308
|
-
'>': '>',
|
309
|
-
'"': '"',
|
310
|
-
"'": ''',
|
311
|
-
'`': '`'
|
312
|
-
};
|
313
|
-
|
314
|
-
```
|
315
|
-
|
316
|
-
### escapeHtml(string)
|
317
|
-
|
318
|
-
```javascript
|
319
|
-
|
320
|
-
var string = '<html> hey </html>';
|
321
|
-
var escapedString = Hoek.escapeHtml(string); // returns <html> hey </html>
|
322
|
-
|
323
|
-
```
|
324
|
-
|
325
|
-
### escapeHeaderAttribute(attribute)
|
326
|
-
|
327
|
-
Escape attribute value for use in HTTP header
|
328
|
-
|
329
|
-
```javascript
|
330
|
-
|
331
|
-
var a = Hoek.escapeHeaderAttribute('I said "go w\\o me"'); //returns I said \"go w\\o me\"
|
332
|
-
|
333
|
-
|
334
|
-
```
|
335
|
-
|
336
|
-
|
337
|
-
### escapeRegex(string)
|
338
|
-
|
339
|
-
Escape string for Regex construction
|
340
|
-
|
341
|
-
```javascript
|
342
|
-
|
343
|
-
var a = Hoek.escapeRegex('4^f$s.4*5+-_?%=#!:@|~\\/`"(>)[<]d{}s,'); // returns 4\^f\$s\.4\*5\+\-_\?%\=#\!\:@\|~\\\/`"\(>\)\[<\]d\{\}s\,
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
```
|
348
|
-
|
349
|
-
# Errors
|
350
|
-
|
351
|
-
### assert(message)
|
352
|
-
|
353
|
-
```javascript
|
354
|
-
|
355
|
-
var a = 1, b =2;
|
356
|
-
|
357
|
-
Hoek.assert(a === b, 'a should equal b'); // ABORT: a should equal b
|
358
|
-
|
359
|
-
```
|
360
|
-
|
361
|
-
### abort(message)
|
362
|
-
|
363
|
-
First checks if process.env.NODE_ENV === 'test', and if so, throws error message. Otherwise,
|
364
|
-
displays most recent stack and then exits process.
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
### displayStack(slice)
|
369
|
-
|
370
|
-
Displays the trace stack
|
371
|
-
|
372
|
-
```javascript
|
373
|
-
|
374
|
-
var stack = Hoek.displayStack();
|
375
|
-
console.log(stack) // returns something like:
|
376
|
-
|
377
|
-
[ 'null (/Users/user/Desktop/hoek/test.js:4:18)',
|
378
|
-
'Module._compile (module.js:449:26)',
|
379
|
-
'Module._extensions..js (module.js:467:10)',
|
380
|
-
'Module.load (module.js:356:32)',
|
381
|
-
'Module._load (module.js:312:12)',
|
382
|
-
'Module.runMain (module.js:492:10)',
|
383
|
-
'startup.processNextTick.process._tickCallback (node.js:244:9)' ]
|
384
|
-
|
385
|
-
```
|
386
|
-
|
387
|
-
### callStack(slice)
|
388
|
-
|
389
|
-
Returns a trace stack array.
|
390
|
-
|
391
|
-
```javascript
|
392
|
-
|
393
|
-
var stack = Hoek.callStack();
|
394
|
-
console.log(stack) // returns something like:
|
395
|
-
|
396
|
-
[ [ '/Users/user/Desktop/hoek/test.js', 4, 18, null, false ],
|
397
|
-
[ 'module.js', 449, 26, 'Module._compile', false ],
|
398
|
-
[ 'module.js', 467, 10, 'Module._extensions..js', false ],
|
399
|
-
[ 'module.js', 356, 32, 'Module.load', false ],
|
400
|
-
[ 'module.js', 312, 12, 'Module._load', false ],
|
401
|
-
[ 'module.js', 492, 10, 'Module.runMain', false ],
|
402
|
-
[ 'node.js',
|
403
|
-
244,
|
404
|
-
9,
|
405
|
-
'startup.processNextTick.process._tickCallback',
|
406
|
-
false ] ]
|
407
|
-
|
408
|
-
|
409
|
-
```
|
410
|
-
|
411
|
-
### toss(condition)
|
412
|
-
|
413
|
-
toss(condition /*, [message], callback */)
|
414
|
-
|
415
|
-
Return an error as first argument of a callback
|
416
|
-
|
417
|
-
|
418
|
-
# Load Files
|
419
|
-
|
420
|
-
### loadPackage(dir)
|
421
|
-
|
422
|
-
Load and parse package.json process root or given directory
|
423
|
-
|
424
|
-
```javascript
|
425
|
-
|
426
|
-
var pack = Hoek.loadPackage(); // pack.name === 'hoek'
|
427
|
-
|
428
|
-
```
|
429
|
-
|
430
|
-
### loadDirModules(path, excludeFiles, target)
|
431
|
-
|
432
|
-
Loads modules from a given path; option to exclude files (array).
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
Binary file
|
@@ -1 +0,0 @@
|
|
1
|
-
module.exports = require('./lib');
|
@@ -1,132 +0,0 @@
|
|
1
|
-
// Declare internals
|
2
|
-
|
3
|
-
var internals = {};
|
4
|
-
|
5
|
-
|
6
|
-
exports.escapeJavaScript = function (input) {
|
7
|
-
|
8
|
-
if (!input) {
|
9
|
-
return '';
|
10
|
-
}
|
11
|
-
|
12
|
-
var escaped = '';
|
13
|
-
|
14
|
-
for (var i = 0, il = input.length; i < il; ++i) {
|
15
|
-
|
16
|
-
var charCode = input.charCodeAt(i);
|
17
|
-
|
18
|
-
if (internals.isSafe(charCode)) {
|
19
|
-
escaped += input[i];
|
20
|
-
}
|
21
|
-
else {
|
22
|
-
escaped += internals.escapeJavaScriptChar(charCode);
|
23
|
-
}
|
24
|
-
}
|
25
|
-
|
26
|
-
return escaped;
|
27
|
-
};
|
28
|
-
|
29
|
-
|
30
|
-
exports.escapeHtml = function (input) {
|
31
|
-
|
32
|
-
if (!input) {
|
33
|
-
return '';
|
34
|
-
}
|
35
|
-
|
36
|
-
var escaped = '';
|
37
|
-
|
38
|
-
for (var i = 0, il = input.length; i < il; ++i) {
|
39
|
-
|
40
|
-
var charCode = input.charCodeAt(i);
|
41
|
-
|
42
|
-
if (internals.isSafe(charCode)) {
|
43
|
-
escaped += input[i];
|
44
|
-
}
|
45
|
-
else {
|
46
|
-
escaped += internals.escapeHtmlChar(charCode);
|
47
|
-
}
|
48
|
-
}
|
49
|
-
|
50
|
-
return escaped;
|
51
|
-
};
|
52
|
-
|
53
|
-
|
54
|
-
internals.escapeJavaScriptChar = function (charCode) {
|
55
|
-
|
56
|
-
if (charCode >= 256) {
|
57
|
-
return '\\u' + internals.padLeft('' + charCode, 4);
|
58
|
-
}
|
59
|
-
|
60
|
-
var hexValue = new Buffer(String.fromCharCode(charCode), 'ascii').toString('hex');
|
61
|
-
return '\\x' + internals.padLeft(hexValue, 2);
|
62
|
-
};
|
63
|
-
|
64
|
-
|
65
|
-
internals.escapeHtmlChar = function (charCode) {
|
66
|
-
|
67
|
-
var namedEscape = internals.namedHtml[charCode];
|
68
|
-
if (typeof namedEscape !== 'undefined') {
|
69
|
-
return namedEscape;
|
70
|
-
}
|
71
|
-
|
72
|
-
if (charCode >= 256) {
|
73
|
-
return '&#' + charCode + ';';
|
74
|
-
}
|
75
|
-
|
76
|
-
var hexValue = new Buffer(String.fromCharCode(charCode), 'ascii').toString('hex');
|
77
|
-
return '&#x' + internals.padLeft(hexValue, 2) + ';';
|
78
|
-
};
|
79
|
-
|
80
|
-
|
81
|
-
internals.padLeft = function (str, len) {
|
82
|
-
|
83
|
-
while (str.length < len) {
|
84
|
-
str = '0' + str;
|
85
|
-
}
|
86
|
-
|
87
|
-
return str;
|
88
|
-
};
|
89
|
-
|
90
|
-
|
91
|
-
internals.isSafe = function (charCode) {
|
92
|
-
|
93
|
-
return (typeof internals.safeCharCodes[charCode] !== 'undefined');
|
94
|
-
};
|
95
|
-
|
96
|
-
|
97
|
-
internals.namedHtml = {
|
98
|
-
'38': '&',
|
99
|
-
'60': '<',
|
100
|
-
'62': '>',
|
101
|
-
'34': '"',
|
102
|
-
'160': ' ',
|
103
|
-
'162': '¢',
|
104
|
-
'163': '£',
|
105
|
-
'164': '¤',
|
106
|
-
'169': '©',
|
107
|
-
'174': '®'
|
108
|
-
};
|
109
|
-
|
110
|
-
|
111
|
-
internals.safeCharCodes = (function () {
|
112
|
-
|
113
|
-
var safe = {};
|
114
|
-
|
115
|
-
for (var i = 32; i < 123; ++i) {
|
116
|
-
|
117
|
-
if ((i >= 97 && i <= 122) || // a-z
|
118
|
-
(i >= 65 && i <= 90) || // A-Z
|
119
|
-
(i >= 48 && i <= 57) || // 0-9
|
120
|
-
i === 32 || // space
|
121
|
-
i === 46 || // .
|
122
|
-
i === 44 || // ,
|
123
|
-
i === 45 || // -
|
124
|
-
i === 58 || // :
|
125
|
-
i === 95) { // _
|
126
|
-
|
127
|
-
safe[i] = null;
|
128
|
-
}
|
129
|
-
}
|
130
|
-
|
131
|
-
return safe;
|
132
|
-
}());
|