@promptbook/utils 0.60.1 → 0.61.0-1
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/README.md +17 -19
- package/esm/index.es.js +392 -274
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +61 -4
- package/esm/typings/src/_packages/core.index.d.ts +8 -8
- package/esm/typings/src/_packages/markdown-utils.d.ts +17 -0
- package/esm/typings/src/_packages/types.index.d.ts +11 -6
- package/esm/typings/src/_packages/utils.index.d.ts +23 -19
- package/esm/typings/src/cli/cli-commands/hello.d.ts +7 -0
- package/esm/typings/src/cli/cli-commands/make.d.ts +7 -0
- package/esm/typings/src/cli/cli-commands/prettify.d.ts +7 -0
- package/esm/typings/src/collection/collectionToJson.d.ts +3 -0
- package/esm/typings/src/collection/collectionToJson.test.d.ts +6 -0
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +2 -1
- package/esm/typings/src/commands/BLOCK/BlockCommand.d.ts +11 -0
- package/esm/typings/src/commands/BLOCK/BlockTypes.d.ts +13 -0
- package/esm/typings/src/commands/BLOCK/blockCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/EXPECT/ExpectAmountCommand.d.ts +14 -0
- package/esm/typings/src/commands/EXPECT/ExpectCommand.d.ts +9 -0
- package/esm/typings/src/commands/EXPECT/ExpectFormatCommand.d.ts +7 -0
- package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/JOKER/JokerCommand.d.ts +11 -0
- package/esm/typings/src/commands/JOKER/jokerCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +12 -0
- package/esm/typings/src/commands/KNOWLEDGE/knowledgeCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/MODEL/ModelCommand.d.ts +13 -0
- package/esm/typings/src/commands/MODEL/modelCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/PARAMETER/ParameterCommand.d.ts +15 -0
- package/esm/typings/src/commands/PARAMETER/parameterCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/PERSONA/PersonaCommand.d.ts +11 -0
- package/esm/typings/src/commands/PERSONA/personaCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/POSTPROCESS/PostprocessCommand.d.ts +11 -0
- package/esm/typings/src/commands/POSTPROCESS/postprocessCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/PROMPTBOOK_VERSION/PromptbookVersionCommand.d.ts +11 -0
- package/esm/typings/src/commands/PROMPTBOOK_VERSION/promptbookVersionCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/URL/UrlCommand.d.ts +10 -0
- package/esm/typings/src/commands/URL/urlCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/X_ACTION/ActionCommand.d.ts +9 -0
- package/esm/typings/src/commands/X_ACTION/actionCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/X_ACTION/actionCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/X_INSTRUMENT/InstrumentCommand.d.ts +9 -0
- package/esm/typings/src/commands/X_INSTRUMENT/instrumentCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/X_INSTRUMENT/instrumentCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/_BOILERPLATE/BoilerplateCommand.d.ts +10 -0
- package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +12 -0
- package/esm/typings/src/commands/_common/parseCommand.d.ts +12 -0
- package/esm/typings/src/commands/_common/parseCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/_common/types/Command.d.ts +6 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +36 -0
- package/esm/typings/src/commands/_common/types/CommandUsagePlaces.d.ts +9 -0
- package/esm/typings/src/commands/index.d.ts +4 -0
- package/esm/typings/src/config.d.ts +4 -0
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +2 -0
- package/esm/typings/src/conversion/pipelineStringToJson.d.ts +2 -3
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +4 -2
- package/esm/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts +2 -2
- package/esm/typings/src/conversion/utils/extractVariables.d.ts +1 -1
- package/esm/typings/src/conversion/validation/validatePipeline-logicErrors.test.d.ts +3 -0
- package/esm/typings/src/errors/NotYetImplementedError.d.ts +7 -0
- package/esm/typings/src/errors/{SyntaxError.d.ts → ParsingError.d.ts} +2 -2
- package/{umd/typings/src/errors/ExecutionError.d.ts → esm/typings/src/errors/PipelineExecutionError.d.ts} +2 -2
- package/esm/typings/src/errors/_ExpectError.d.ts +2 -2
- package/esm/typings/src/execution/ExecutionTools.d.ts +4 -3
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +24 -5
- package/esm/typings/src/execution/PromptResult.d.ts +2 -2
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +1 -1
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +1 -1
- package/esm/typings/src/execution/utils/checkExpectations.d.ts +1 -1
- package/esm/typings/src/execution/utils/replaceParameters.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +5 -0
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +5 -5
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -0
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +5 -0
- package/esm/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +5 -0
- package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +5 -0
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +10 -0
- package/esm/typings/src/llm-providers/mocked/fakeTextToExpectations.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/test/fakeTextToExpectations.test.d.ts +1 -0
- package/esm/typings/src/llm-providers/mocked/test/faked-completion.test.d.ts +1 -0
- package/esm/typings/src/llm-providers/mocked/test/mocked-chat.test.d.ts +5 -0
- package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +14 -1
- package/esm/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +16 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +6 -1
- package/esm/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +13 -3
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
- package/esm/typings/src/personas/personaToModelRequirements.d.ts +6 -0
- package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +2 -1
- package/esm/typings/src/types/Arrayable.d.ts +10 -0
- package/esm/typings/src/types/PipelineJson/Expectations.d.ts +28 -0
- package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +16 -0
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +8 -2
- package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +7 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +6 -142
- package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +77 -0
- package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +14 -0
- package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +7 -0
- package/esm/typings/src/types/Prompt.d.ts +3 -3
- package/esm/typings/src/types/TaskProgress.d.ts +2 -2
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +3 -3
- package/esm/typings/src/types/typeAliases.d.ts +50 -6
- package/esm/typings/src/utils/arrayableToArray.d.ts +11 -0
- package/esm/typings/src/utils/arrayableToArray.test.d.ts +1 -0
- package/esm/typings/src/utils/emojis.d.ts +1 -0
- package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countLines.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countPages.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countWords.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/index.d.ts +2 -2
- package/esm/typings/src/utils/markdown/flattenMarkdown.d.ts +14 -0
- package/esm/typings/src/utils/markdown/flattenMarkdown.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/parseMarkdownSection.d.ts +30 -0
- package/esm/typings/src/utils/markdown/parseMarkdownSection.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/prettifyMarkdown.d.ts +1 -0
- package/esm/typings/src/utils/markdown/splitMarkdownIntoSections.d.ts +12 -0
- package/esm/typings/src/utils/markdown/splitMarkdownIntoSections.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +8 -1
- package/esm/typings/src/utils/normalization/normalizeTo_PascalCase.d.ts +8 -1
- package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +13 -1
- package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +8 -1
- package/esm/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +8 -1
- package/esm/typings/src/{conversion/utils → utils}/parseNumber.d.ts +1 -1
- package/esm/typings/src/utils/parseNumber.test.d.ts +1 -0
- package/esm/typings/src/utils/sets/difference.d.ts +2 -0
- package/esm/typings/src/utils/sets/intersection.d.ts +2 -0
- package/esm/typings/src/utils/sets/union.d.ts +2 -0
- package/esm/typings/src/utils/validators/email/isValidEmail.d.ts +5 -0
- package/esm/typings/src/utils/validators/email/isValidEmail.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +7 -0
- package/esm/typings/src/utils/validators/filePath/isValidFilePath.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +2 -0
- package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +12 -0
- package/esm/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +9 -0
- package/esm/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.d.ts +9 -0
- package/esm/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/url/isUrlOnPrivateNetwork.d.ts +12 -0
- package/esm/typings/src/utils/validators/url/isUrlOnPrivateNetwork.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +12 -0
- package/esm/typings/src/utils/validators/url/isValidPipelineUrl.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +3 -0
- package/esm/typings/src/utils/validators/uuid/isValidUuid.d.ts +5 -0
- package/esm/typings/src/utils/validators/uuid/isValidUuid.test.d.ts +1 -0
- package/esm/typings/src/version.d.ts +3 -2
- package/package.json +1 -1
- package/umd/index.umd.js +400 -278
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/promptbook-collection/index.d.ts +61 -4
- package/umd/typings/src/_packages/core.index.d.ts +8 -8
- package/umd/typings/src/_packages/markdown-utils.d.ts +17 -0
- package/umd/typings/src/_packages/types.index.d.ts +11 -6
- package/umd/typings/src/_packages/utils.index.d.ts +23 -19
- package/umd/typings/src/cli/cli-commands/hello.d.ts +7 -0
- package/umd/typings/src/cli/cli-commands/make.d.ts +7 -0
- package/umd/typings/src/cli/cli-commands/prettify.d.ts +7 -0
- package/umd/typings/src/collection/collectionToJson.d.ts +3 -0
- package/umd/typings/src/collection/collectionToJson.test.d.ts +6 -0
- package/umd/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +2 -1
- package/umd/typings/src/commands/BLOCK/BlockCommand.d.ts +11 -0
- package/umd/typings/src/commands/BLOCK/BlockTypes.d.ts +13 -0
- package/umd/typings/src/commands/BLOCK/blockCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/BLOCK/blockCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/EXPECT/ExpectAmountCommand.d.ts +14 -0
- package/umd/typings/src/commands/EXPECT/ExpectCommand.d.ts +9 -0
- package/umd/typings/src/commands/EXPECT/ExpectFormatCommand.d.ts +7 -0
- package/umd/typings/src/commands/EXPECT/expectCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/EXPECT/expectCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/JOKER/JokerCommand.d.ts +11 -0
- package/umd/typings/src/commands/JOKER/jokerCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/JOKER/jokerCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +12 -0
- package/umd/typings/src/commands/KNOWLEDGE/knowledgeCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/KNOWLEDGE/knowledgeCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/MODEL/ModelCommand.d.ts +13 -0
- package/umd/typings/src/commands/MODEL/modelCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/MODEL/modelCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/PARAMETER/ParameterCommand.d.ts +15 -0
- package/umd/typings/src/commands/PARAMETER/parameterCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/PARAMETER/parameterCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/PERSONA/PersonaCommand.d.ts +11 -0
- package/umd/typings/src/commands/PERSONA/personaCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/PERSONA/personaCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/POSTPROCESS/PostprocessCommand.d.ts +11 -0
- package/umd/typings/src/commands/POSTPROCESS/postprocessCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/POSTPROCESS/postprocessCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/PROMPTBOOK_VERSION/PromptbookVersionCommand.d.ts +11 -0
- package/umd/typings/src/commands/PROMPTBOOK_VERSION/promptbookVersionCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/PROMPTBOOK_VERSION/promptbookVersionCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/URL/UrlCommand.d.ts +10 -0
- package/umd/typings/src/commands/URL/urlCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/URL/urlCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/X_ACTION/ActionCommand.d.ts +9 -0
- package/umd/typings/src/commands/X_ACTION/actionCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/X_ACTION/actionCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/X_INSTRUMENT/InstrumentCommand.d.ts +9 -0
- package/umd/typings/src/commands/X_INSTRUMENT/instrumentCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/X_INSTRUMENT/instrumentCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/_BOILERPLATE/BoilerplateCommand.d.ts +10 -0
- package/umd/typings/src/commands/_BOILERPLATE/boilerplateCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +12 -0
- package/umd/typings/src/commands/_common/parseCommand.d.ts +12 -0
- package/umd/typings/src/commands/_common/parseCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/_common/types/Command.d.ts +6 -0
- package/umd/typings/src/commands/_common/types/CommandParser.d.ts +36 -0
- package/umd/typings/src/commands/_common/types/CommandUsagePlaces.d.ts +9 -0
- package/umd/typings/src/commands/index.d.ts +4 -0
- package/umd/typings/src/config.d.ts +4 -0
- package/umd/typings/src/conversion/pipelineJsonToString.d.ts +2 -0
- package/umd/typings/src/conversion/pipelineStringToJson.d.ts +2 -3
- package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +4 -2
- package/umd/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts +2 -2
- package/umd/typings/src/conversion/utils/extractVariables.d.ts +1 -1
- package/umd/typings/src/conversion/validation/validatePipeline-logicErrors.test.d.ts +3 -0
- package/umd/typings/src/errors/NotYetImplementedError.d.ts +7 -0
- package/umd/typings/src/errors/{SyntaxError.d.ts → ParsingError.d.ts} +2 -2
- package/{esm/typings/src/errors/ExecutionError.d.ts → umd/typings/src/errors/PipelineExecutionError.d.ts} +2 -2
- package/umd/typings/src/errors/_ExpectError.d.ts +2 -2
- package/umd/typings/src/execution/ExecutionTools.d.ts +4 -3
- package/umd/typings/src/execution/LlmExecutionTools.d.ts +24 -5
- package/umd/typings/src/execution/PromptResult.d.ts +2 -2
- package/umd/typings/src/execution/assertsExecutionSuccessful.d.ts +1 -1
- package/umd/typings/src/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +1 -1
- package/umd/typings/src/execution/utils/checkExpectations.d.ts +1 -1
- package/umd/typings/src/execution/utils/replaceParameters.d.ts +1 -1
- package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +5 -0
- package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +5 -5
- package/umd/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -0
- package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +5 -0
- package/umd/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +5 -0
- package/umd/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +5 -0
- package/umd/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +10 -0
- package/umd/typings/src/llm-providers/mocked/fakeTextToExpectations.d.ts +1 -1
- package/umd/typings/src/llm-providers/mocked/test/fakeTextToExpectations.test.d.ts +1 -0
- package/umd/typings/src/llm-providers/mocked/test/faked-completion.test.d.ts +1 -0
- package/umd/typings/src/llm-providers/mocked/test/mocked-chat.test.d.ts +5 -0
- package/umd/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +14 -1
- package/umd/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +16 -0
- package/umd/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +6 -1
- package/umd/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +1 -1
- package/umd/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
- package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +13 -3
- package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
- package/umd/typings/src/personas/personaToModelRequirements.d.ts +6 -0
- package/umd/typings/src/scripting/javascript/utils/preserve.d.ts +2 -1
- package/umd/typings/src/types/Arrayable.d.ts +10 -0
- package/umd/typings/src/types/PipelineJson/Expectations.d.ts +28 -0
- package/umd/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +16 -0
- package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +8 -2
- package/umd/typings/src/types/PipelineJson/PromptDialogJson.d.ts +7 -0
- package/umd/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +6 -142
- package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +77 -0
- package/umd/typings/src/types/PipelineJson/ScriptJson.d.ts +14 -0
- package/umd/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +7 -0
- package/umd/typings/src/types/Prompt.d.ts +3 -3
- package/umd/typings/src/types/TaskProgress.d.ts +2 -2
- package/umd/typings/src/types/execution-report/ExecutionReportJson.d.ts +3 -3
- package/umd/typings/src/types/typeAliases.d.ts +50 -6
- package/umd/typings/src/utils/arrayableToArray.d.ts +11 -0
- package/umd/typings/src/utils/arrayableToArray.test.d.ts +1 -0
- package/umd/typings/src/utils/emojis.d.ts +1 -0
- package/umd/typings/src/utils/expectation-counters/countCharacters.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/countLines.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/countPages.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/countParagraphs.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/countSentences.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/countWords.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/index.d.ts +2 -2
- package/umd/typings/src/utils/markdown/flattenMarkdown.d.ts +14 -0
- package/umd/typings/src/utils/markdown/flattenMarkdown.test.d.ts +1 -0
- package/umd/typings/src/utils/markdown/parseMarkdownSection.d.ts +30 -0
- package/umd/typings/src/utils/markdown/parseMarkdownSection.test.d.ts +1 -0
- package/umd/typings/src/utils/markdown/prettifyMarkdown.d.ts +1 -0
- package/umd/typings/src/utils/markdown/splitMarkdownIntoSections.d.ts +12 -0
- package/umd/typings/src/utils/markdown/splitMarkdownIntoSections.test.d.ts +1 -0
- package/umd/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +8 -1
- package/umd/typings/src/utils/normalization/normalizeTo_PascalCase.d.ts +8 -1
- package/umd/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +13 -1
- package/umd/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +8 -1
- package/umd/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +8 -1
- package/umd/typings/src/{conversion/utils → utils}/parseNumber.d.ts +1 -1
- package/umd/typings/src/utils/parseNumber.test.d.ts +1 -0
- package/umd/typings/src/utils/sets/difference.d.ts +2 -0
- package/umd/typings/src/utils/sets/intersection.d.ts +2 -0
- package/umd/typings/src/utils/sets/union.d.ts +2 -0
- package/umd/typings/src/utils/validators/email/isValidEmail.d.ts +5 -0
- package/umd/typings/src/utils/validators/email/isValidEmail.test.d.ts +1 -0
- package/umd/typings/src/utils/validators/filePath/isValidFilePath.d.ts +7 -0
- package/umd/typings/src/utils/validators/filePath/isValidFilePath.test.d.ts +1 -0
- package/umd/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +2 -0
- package/umd/typings/src/utils/validators/javascriptName/isValidJavascriptName.test.d.ts +1 -0
- package/umd/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +12 -0
- package/umd/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.test.d.ts +1 -0
- package/umd/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +9 -0
- package/umd/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.test.d.ts +1 -0
- package/umd/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.d.ts +9 -0
- package/umd/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.test.d.ts +1 -0
- package/umd/typings/src/utils/validators/url/isUrlOnPrivateNetwork.d.ts +12 -0
- package/umd/typings/src/utils/validators/url/isUrlOnPrivateNetwork.test.d.ts +1 -0
- package/umd/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +12 -0
- package/umd/typings/src/utils/validators/url/isValidPipelineUrl.test.d.ts +1 -0
- package/umd/typings/src/utils/validators/url/isValidUrl.d.ts +3 -0
- package/umd/typings/src/utils/validators/uuid/isValidUuid.d.ts +5 -0
- package/umd/typings/src/utils/validators/uuid/isValidUuid.test.d.ts +1 -0
- package/umd/typings/src/version.d.ts +3 -2
- package/esm/typings/src/cli/actions/hello.d.ts +0 -7
- package/esm/typings/src/cli/actions/make.d.ts +0 -7
- package/esm/typings/src/cli/actions/prettify.d.ts +0 -7
- package/esm/typings/src/conversion/utils/parseCommand.d.ts +0 -11
- package/esm/typings/src/conversion/utils/parseCommand.test.d.ts +0 -4
- package/esm/typings/src/errors/TemplateError.d.ts +0 -9
- package/esm/typings/src/llm-providers/mocked/mocked-chat.test.d.ts +0 -4
- package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionToolsOptions.d.ts +0 -24
- package/esm/typings/src/types/Command.d.ts +0 -101
- package/esm/typings/src/types/ExecutionTypes.d.ts +0 -13
- package/esm/typings/src/utils/markdown-json/MarkdownStructure.d.ts +0 -25
- package/esm/typings/src/utils/markdown-json/countMarkdownStructureDeepness.d.ts +0 -7
- package/esm/typings/src/utils/markdown-json/markdownToMarkdownStructure.d.ts +0 -13
- package/umd/typings/src/cli/actions/hello.d.ts +0 -7
- package/umd/typings/src/cli/actions/make.d.ts +0 -7
- package/umd/typings/src/cli/actions/prettify.d.ts +0 -7
- package/umd/typings/src/conversion/utils/parseCommand.d.ts +0 -11
- package/umd/typings/src/conversion/utils/parseCommand.test.d.ts +0 -4
- package/umd/typings/src/errors/TemplateError.d.ts +0 -9
- package/umd/typings/src/llm-providers/mocked/mocked-chat.test.d.ts +0 -4
- package/umd/typings/src/llm-providers/multiple/MultipleLlmExecutionToolsOptions.d.ts +0 -24
- package/umd/typings/src/types/Command.d.ts +0 -101
- package/umd/typings/src/types/ExecutionTypes.d.ts +0 -13
- package/umd/typings/src/utils/markdown-json/MarkdownStructure.d.ts +0 -25
- package/umd/typings/src/utils/markdown-json/countMarkdownStructureDeepness.d.ts +0 -7
- package/umd/typings/src/utils/markdown-json/markdownToMarkdownStructure.d.ts +0 -13
- /package/esm/typings/src/{conversion/utils/parseNumber.test.d.ts → commands/BLOCK/blockCommand.test.d.ts} +0 -0
- /package/esm/typings/src/{llm-providers/mocked/fakeTextToExpectations.test.d.ts → commands/EXPECT/expectCommand.test.d.ts} +0 -0
- /package/esm/typings/src/{llm-providers/mocked/faked-completion.test.d.ts → commands/JOKER/jokerCommand.test.d.ts} +0 -0
- /package/esm/typings/src/{utils/markdown-json/countMarkdownStructureDeepness.test.d.ts → commands/KNOWLEDGE/knowledgeCommand.test.d.ts} +0 -0
- /package/esm/typings/src/{utils/markdown-json/markdownToMarkdownStructure.test.d.ts → commands/MODEL/modelCommand.test.d.ts} +0 -0
- /package/{umd/typings/src/conversion/utils/parseNumber.test.d.ts → esm/typings/src/commands/PARAMETER/parameterCommand.test.d.ts} +0 -0
- /package/{umd/typings/src/llm-providers/mocked/fakeTextToExpectations.test.d.ts → esm/typings/src/commands/PERSONA/personaCommand.test.d.ts} +0 -0
- /package/{umd/typings/src/llm-providers/mocked/faked-completion.test.d.ts → esm/typings/src/commands/POSTPROCESS/postprocessCommand.test.d.ts} +0 -0
- /package/{umd/typings/src/utils/markdown-json/countMarkdownStructureDeepness.test.d.ts → esm/typings/src/commands/PROMPTBOOK_VERSION/promptbookVersionCommand.test.d.ts} +0 -0
- /package/{umd/typings/src/utils/markdown-json/markdownToMarkdownStructure.test.d.ts → esm/typings/src/commands/URL/urlCommand.test.d.ts} +0 -0
- /package/esm/typings/src/llm-providers/mocked/{joker.test.d.ts → test/joker.test.d.ts} +0 -0
- /package/esm/typings/src/llm-providers/mocked/{mocked-completion.test.d.ts → test/mocked-completion.test.d.ts} +0 -0
- /package/umd/typings/src/llm-providers/mocked/{joker.test.d.ts → test/joker.test.d.ts} +0 -0
- /package/umd/typings/src/llm-providers/mocked/{mocked-completion.test.d.ts → test/mocked-completion.test.d.ts} +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -137,16 +137,15 @@
|
|
|
137
137
|
return UnexpectedError;
|
|
138
138
|
}(Error));
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
function normalizeTo_camelCase(sentence, __firstLetterCapital) {
|
|
140
|
+
function normalizeTo_camelCase(text, _isFirstLetterCapital) {
|
|
142
141
|
var e_1, _a;
|
|
143
|
-
if (
|
|
142
|
+
if (_isFirstLetterCapital === void 0) { _isFirstLetterCapital = false; }
|
|
144
143
|
var charType;
|
|
145
144
|
var lastCharType = null;
|
|
146
145
|
var normalizedName = '';
|
|
147
146
|
try {
|
|
148
|
-
for (var
|
|
149
|
-
var char =
|
|
147
|
+
for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
|
|
148
|
+
var char = text_1_1.value;
|
|
150
149
|
var normalizedChar = void 0;
|
|
151
150
|
if (/^[a-z]$/.test(char)) {
|
|
152
151
|
charType = 'LOWERCASE';
|
|
@@ -165,7 +164,7 @@
|
|
|
165
164
|
normalizedChar = '';
|
|
166
165
|
}
|
|
167
166
|
if (!lastCharType) {
|
|
168
|
-
if (
|
|
167
|
+
if (_isFirstLetterCapital) {
|
|
169
168
|
normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
|
|
170
169
|
}
|
|
171
170
|
}
|
|
@@ -182,7 +181,7 @@
|
|
|
182
181
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
183
182
|
finally {
|
|
184
183
|
try {
|
|
185
|
-
if (
|
|
184
|
+
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
186
185
|
}
|
|
187
186
|
finally { if (e_1) throw e_1.error; }
|
|
188
187
|
}
|
|
@@ -444,16 +443,15 @@
|
|
|
444
443
|
});
|
|
445
444
|
}
|
|
446
445
|
|
|
447
|
-
|
|
448
|
-
function normalizeToKebabCase(sentence) {
|
|
446
|
+
function normalizeToKebabCase(text) {
|
|
449
447
|
var e_1, _a;
|
|
450
|
-
|
|
448
|
+
text = removeDiacritics(text);
|
|
451
449
|
var charType;
|
|
452
450
|
var lastCharType = 'OTHER';
|
|
453
451
|
var normalizedName = '';
|
|
454
452
|
try {
|
|
455
|
-
for (var
|
|
456
|
-
var char =
|
|
453
|
+
for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
|
|
454
|
+
var char = text_1_1.value;
|
|
457
455
|
var normalizedChar = void 0;
|
|
458
456
|
if (/^[a-z]$/.test(char)) {
|
|
459
457
|
charType = 'LOWERCASE';
|
|
@@ -488,7 +486,7 @@
|
|
|
488
486
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
489
487
|
finally {
|
|
490
488
|
try {
|
|
491
|
-
if (
|
|
489
|
+
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
492
490
|
}
|
|
493
491
|
finally { if (e_1) throw e_1.error; }
|
|
494
492
|
}
|
|
@@ -612,15 +610,15 @@
|
|
|
612
610
|
/**
|
|
613
611
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
614
612
|
*/
|
|
615
|
-
var
|
|
616
|
-
__extends(
|
|
617
|
-
function
|
|
613
|
+
var ParsingError = /** @class */ (function (_super) {
|
|
614
|
+
__extends(ParsingError, _super);
|
|
615
|
+
function ParsingError(message) {
|
|
618
616
|
var _this = _super.call(this, message) || this;
|
|
619
|
-
_this.name = '
|
|
620
|
-
Object.setPrototypeOf(_this,
|
|
617
|
+
_this.name = 'ParsingError';
|
|
618
|
+
Object.setPrototypeOf(_this, ParsingError.prototype);
|
|
621
619
|
return _this;
|
|
622
620
|
}
|
|
623
|
-
return
|
|
621
|
+
return ParsingError;
|
|
624
622
|
}(Error));
|
|
625
623
|
|
|
626
624
|
/**
|
|
@@ -628,7 +626,7 @@
|
|
|
628
626
|
*
|
|
629
627
|
* @param script from which to extract the variables
|
|
630
628
|
* @returns the list of variable names
|
|
631
|
-
* @throws {
|
|
629
|
+
* @throws {ParsingError} if the script is invalid
|
|
632
630
|
*/
|
|
633
631
|
function extractVariables(script) {
|
|
634
632
|
var variables = new Set();
|
|
@@ -644,9 +642,8 @@
|
|
|
644
642
|
}
|
|
645
643
|
var undefinedName = error.message.split(' ')[0];
|
|
646
644
|
/*
|
|
647
|
-
Note:
|
|
648
|
-
|
|
649
|
-
To: [Error: Parameter {thing} is not defined],
|
|
645
|
+
Note: Parsing the error
|
|
646
|
+
[ReferenceError: thing is not defined]
|
|
650
647
|
*/
|
|
651
648
|
if (!undefinedName) {
|
|
652
649
|
throw error;
|
|
@@ -664,7 +661,7 @@
|
|
|
664
661
|
if (!(error instanceof Error)) {
|
|
665
662
|
throw error;
|
|
666
663
|
}
|
|
667
|
-
throw new
|
|
664
|
+
throw new ParsingError(spacetrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
|
|
668
665
|
}
|
|
669
666
|
return variables;
|
|
670
667
|
}
|
|
@@ -677,7 +674,7 @@
|
|
|
677
674
|
*
|
|
678
675
|
* @param promptTemplate the template with used parameters
|
|
679
676
|
* @returns the set of parameter names
|
|
680
|
-
* @throws {
|
|
677
|
+
* @throws {ParsingError} if the script is invalid
|
|
681
678
|
*/
|
|
682
679
|
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
683
680
|
var e_1, _a, e_2, _b;
|
|
@@ -695,7 +692,7 @@
|
|
|
695
692
|
}
|
|
696
693
|
finally { if (e_1) throw e_1.error; }
|
|
697
694
|
}
|
|
698
|
-
if (promptTemplate.
|
|
695
|
+
if (promptTemplate.blockType === 'SCRIPT') {
|
|
699
696
|
try {
|
|
700
697
|
for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
701
698
|
var parameterName = _f.value;
|
|
@@ -716,73 +713,6 @@
|
|
|
716
713
|
* TODO: [🔣] If script require contentLanguage
|
|
717
714
|
*/
|
|
718
715
|
|
|
719
|
-
/**
|
|
720
|
-
* Function parseNumber will parse number from string
|
|
721
|
-
*
|
|
722
|
-
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
723
|
-
* Note: it also works only with decimal numbers
|
|
724
|
-
*
|
|
725
|
-
* @returns parsed number
|
|
726
|
-
* @throws {SyntaxError} if the value is not a number
|
|
727
|
-
*
|
|
728
|
-
* @private within the parseCommand
|
|
729
|
-
*/
|
|
730
|
-
function parseNumber(value) {
|
|
731
|
-
var originalValue = value;
|
|
732
|
-
if (typeof value === 'number') {
|
|
733
|
-
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
734
|
-
}
|
|
735
|
-
if (typeof value !== 'string') {
|
|
736
|
-
return 0;
|
|
737
|
-
}
|
|
738
|
-
value = value.trim();
|
|
739
|
-
if (value.startsWith('+')) {
|
|
740
|
-
return parseNumber(value.substring(1));
|
|
741
|
-
}
|
|
742
|
-
if (value.startsWith('-')) {
|
|
743
|
-
var number = parseNumber(value.substring(1));
|
|
744
|
-
if (number === 0) {
|
|
745
|
-
return 0; // <- Note: To prevent -0
|
|
746
|
-
}
|
|
747
|
-
return -number;
|
|
748
|
-
}
|
|
749
|
-
value = value.replace(/,/g, '.');
|
|
750
|
-
value = value.toUpperCase();
|
|
751
|
-
if (value === '') {
|
|
752
|
-
return 0;
|
|
753
|
-
}
|
|
754
|
-
if (value === '♾' || value.startsWith('INF')) {
|
|
755
|
-
return Infinity;
|
|
756
|
-
}
|
|
757
|
-
if (value.includes('/')) {
|
|
758
|
-
var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
|
|
759
|
-
var numerator = parseNumber(numerator_);
|
|
760
|
-
var denominator = parseNumber(denominator_);
|
|
761
|
-
if (denominator === 0) {
|
|
762
|
-
throw new SyntaxError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
763
|
-
}
|
|
764
|
-
return numerator / denominator;
|
|
765
|
-
}
|
|
766
|
-
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
|
767
|
-
return 0;
|
|
768
|
-
}
|
|
769
|
-
if (value.includes('E')) {
|
|
770
|
-
var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
|
|
771
|
-
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
772
|
-
}
|
|
773
|
-
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
774
|
-
throw new SyntaxError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
775
|
-
}
|
|
776
|
-
var num = parseFloat(value);
|
|
777
|
-
if (isNaN(num)) {
|
|
778
|
-
throw new SyntaxError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
779
|
-
}
|
|
780
|
-
return num;
|
|
781
|
-
}
|
|
782
|
-
/**
|
|
783
|
-
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
784
|
-
*/
|
|
785
|
-
|
|
786
716
|
/**
|
|
787
717
|
* This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
|
|
788
718
|
*/
|
|
@@ -933,19 +863,17 @@
|
|
|
933
863
|
var LOOP_LIMIT = 1000;
|
|
934
864
|
|
|
935
865
|
/**
|
|
936
|
-
* This error
|
|
937
|
-
*
|
|
938
|
-
* Note: This is a kindof subtype of ExecutionError because it occurs during the execution of the pipeline
|
|
866
|
+
* This error indicates errors during the execution of the pipeline
|
|
939
867
|
*/
|
|
940
|
-
var
|
|
941
|
-
__extends(
|
|
942
|
-
function
|
|
868
|
+
var PipelineExecutionError = /** @class */ (function (_super) {
|
|
869
|
+
__extends(PipelineExecutionError, _super);
|
|
870
|
+
function PipelineExecutionError(message) {
|
|
943
871
|
var _this = _super.call(this, message) || this;
|
|
944
|
-
_this.name = '
|
|
945
|
-
Object.setPrototypeOf(_this,
|
|
872
|
+
_this.name = 'PipelineExecutionError';
|
|
873
|
+
Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
|
|
946
874
|
return _this;
|
|
947
875
|
}
|
|
948
|
-
return
|
|
876
|
+
return PipelineExecutionError;
|
|
949
877
|
}(Error));
|
|
950
878
|
|
|
951
879
|
/**
|
|
@@ -954,7 +882,7 @@
|
|
|
954
882
|
* @param template the template with parameters in {curly} braces
|
|
955
883
|
* @param parameters the object with parameters
|
|
956
884
|
* @returns the template with replaced parameters
|
|
957
|
-
* @throws {
|
|
885
|
+
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
958
886
|
*
|
|
959
887
|
* @private within the createPipelineExecutor
|
|
960
888
|
*/
|
|
@@ -972,14 +900,14 @@
|
|
|
972
900
|
return "continue";
|
|
973
901
|
}
|
|
974
902
|
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
975
|
-
throw new
|
|
903
|
+
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
976
904
|
}
|
|
977
905
|
if (parameters[parameterName] === undefined) {
|
|
978
|
-
throw new
|
|
906
|
+
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
979
907
|
}
|
|
980
908
|
var parameterValue = parameters[parameterName];
|
|
981
909
|
if (parameterValue === undefined) {
|
|
982
|
-
throw new
|
|
910
|
+
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
983
911
|
}
|
|
984
912
|
parameterValue = parameterValue.toString();
|
|
985
913
|
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
@@ -999,11 +927,11 @@
|
|
|
999
927
|
}
|
|
1000
928
|
// [💫] Check if there are parameters that are not closed properly
|
|
1001
929
|
if (/{\w+$/.test(replacedTemplate)) {
|
|
1002
|
-
throw new
|
|
930
|
+
throw new PipelineExecutionError('Parameter is not closed');
|
|
1003
931
|
}
|
|
1004
932
|
// [💫] Check if there are parameters that are not opened properly
|
|
1005
933
|
if (/^\w+}/.test(replacedTemplate)) {
|
|
1006
|
-
throw new
|
|
934
|
+
throw new PipelineExecutionError('Parameter is not opened');
|
|
1007
935
|
}
|
|
1008
936
|
return replacedTemplate;
|
|
1009
937
|
}
|
|
@@ -1109,152 +1037,6 @@
|
|
|
1109
1037
|
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
1110
1038
|
}
|
|
1111
1039
|
|
|
1112
|
-
/**
|
|
1113
|
-
* Extracts all code blocks from markdown.
|
|
1114
|
-
*
|
|
1115
|
-
* Note: There are 3 simmilar function:
|
|
1116
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
1117
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
1118
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
1119
|
-
*
|
|
1120
|
-
* @param markdown any valid markdown
|
|
1121
|
-
* @returns code blocks with language and content
|
|
1122
|
-
*
|
|
1123
|
-
*/
|
|
1124
|
-
function extractAllBlocksFromMarkdown(markdown) {
|
|
1125
|
-
var e_1, _a;
|
|
1126
|
-
var codeBlocks = [];
|
|
1127
|
-
var lines = markdown.split('\n');
|
|
1128
|
-
var currentCodeBlock = null;
|
|
1129
|
-
try {
|
|
1130
|
-
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
1131
|
-
var line = lines_1_1.value;
|
|
1132
|
-
if (line.startsWith('```')) {
|
|
1133
|
-
var language = line.slice(3).trim() || null;
|
|
1134
|
-
if (currentCodeBlock === null) {
|
|
1135
|
-
currentCodeBlock = { language: language, content: '' };
|
|
1136
|
-
}
|
|
1137
|
-
else {
|
|
1138
|
-
if (language !== null) {
|
|
1139
|
-
// [🌻]
|
|
1140
|
-
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
1141
|
-
}
|
|
1142
|
-
codeBlocks.push(currentCodeBlock);
|
|
1143
|
-
currentCodeBlock = null;
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
else if (currentCodeBlock !== null) {
|
|
1147
|
-
if (currentCodeBlock.content !== '') {
|
|
1148
|
-
currentCodeBlock.content += '\n';
|
|
1149
|
-
}
|
|
1150
|
-
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1155
|
-
finally {
|
|
1156
|
-
try {
|
|
1157
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
1158
|
-
}
|
|
1159
|
-
finally { if (e_1) throw e_1.error; }
|
|
1160
|
-
}
|
|
1161
|
-
if (currentCodeBlock !== null) {
|
|
1162
|
-
// [🌻]
|
|
1163
|
-
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
1164
|
-
}
|
|
1165
|
-
return codeBlocks;
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
/**
|
|
1169
|
-
* Utility function to extract all list items from markdown
|
|
1170
|
-
*
|
|
1171
|
-
* Note: It works with both ul and ol
|
|
1172
|
-
* Note: It omits list items in code blocks
|
|
1173
|
-
* Note: It flattens nested lists
|
|
1174
|
-
* Note: It can not work with html syntax and comments
|
|
1175
|
-
*
|
|
1176
|
-
* @param markdown any valid markdown
|
|
1177
|
-
* @returns
|
|
1178
|
-
*/
|
|
1179
|
-
function extractAllListItemsFromMarkdown(markdown) {
|
|
1180
|
-
var e_1, _a;
|
|
1181
|
-
var lines = markdown.split('\n');
|
|
1182
|
-
var listItems = [];
|
|
1183
|
-
var isInCodeBlock = false;
|
|
1184
|
-
try {
|
|
1185
|
-
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
1186
|
-
var line = lines_1_1.value;
|
|
1187
|
-
var trimmedLine = line.trim();
|
|
1188
|
-
if (trimmedLine.startsWith('```')) {
|
|
1189
|
-
isInCodeBlock = !isInCodeBlock;
|
|
1190
|
-
}
|
|
1191
|
-
if (!isInCodeBlock && (trimmedLine.startsWith('-') || trimmedLine.match(/^\d+\./))) {
|
|
1192
|
-
var listItem = trimmedLine.replace(/^-|\d+\./, '').trim();
|
|
1193
|
-
listItems.push(listItem);
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1198
|
-
finally {
|
|
1199
|
-
try {
|
|
1200
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
1201
|
-
}
|
|
1202
|
-
finally { if (e_1) throw e_1.error; }
|
|
1203
|
-
}
|
|
1204
|
-
return listItems;
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
/**
|
|
1208
|
-
* Extracts exactly ONE code block from markdown.
|
|
1209
|
-
*
|
|
1210
|
-
* Note: If there are multiple or no code blocks the function throws an error
|
|
1211
|
-
*
|
|
1212
|
-
* Note: There are 3 simmilar function:
|
|
1213
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
1214
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
1215
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
1216
|
-
*
|
|
1217
|
-
* @param markdown any valid markdown
|
|
1218
|
-
* @returns code block with language and content
|
|
1219
|
-
*/
|
|
1220
|
-
function extractOneBlockFromMarkdown(markdown) {
|
|
1221
|
-
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
1222
|
-
if (codeBlocks.length !== 1) {
|
|
1223
|
-
// TODO: Report more specific place where the error happened
|
|
1224
|
-
throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
|
|
1225
|
-
}
|
|
1226
|
-
return codeBlocks[0];
|
|
1227
|
-
}
|
|
1228
|
-
/***
|
|
1229
|
-
* TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
1230
|
-
*/
|
|
1231
|
-
|
|
1232
|
-
/**
|
|
1233
|
-
* Removes HTML or Markdown comments from a string.
|
|
1234
|
-
*
|
|
1235
|
-
* @param {string} content - The string to remove comments from.
|
|
1236
|
-
* @returns {string} The input string with all comments removed.
|
|
1237
|
-
*/
|
|
1238
|
-
function removeContentComments(content) {
|
|
1239
|
-
return spacetrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1242
|
-
/**
|
|
1243
|
-
* Removes Markdown formatting tags from a string.
|
|
1244
|
-
*
|
|
1245
|
-
* @param {string} str - The string to remove Markdown tags from.
|
|
1246
|
-
* @returns {string} The input string with all Markdown tags removed.
|
|
1247
|
-
*/
|
|
1248
|
-
function removeMarkdownFormatting(str) {
|
|
1249
|
-
// Remove bold formatting
|
|
1250
|
-
str = str.replace(/\*\*(.*?)\*\*/g, '$1');
|
|
1251
|
-
// Remove italic formatting
|
|
1252
|
-
str = str.replace(/\*(.*?)\*/g, '$1');
|
|
1253
|
-
// Remove code formatting
|
|
1254
|
-
str = str.replace(/`(.*?)`/g, '$1');
|
|
1255
|
-
return str;
|
|
1256
|
-
}
|
|
1257
|
-
|
|
1258
1040
|
/**
|
|
1259
1041
|
* Makes first letter of a string uppercase
|
|
1260
1042
|
*
|
|
@@ -1263,22 +1045,14 @@
|
|
|
1263
1045
|
return word.substring(0, 1).toLowerCase() + word.substring(1);
|
|
1264
1046
|
}
|
|
1265
1047
|
|
|
1266
|
-
|
|
1267
|
-
/*
|
|
1268
|
-
TODO: Tests
|
|
1269
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
|
|
1270
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
|
|
1271
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
|
|
1272
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
|
|
1273
|
-
*/
|
|
1274
|
-
function normalizeTo_SCREAMING_CASE(sentence) {
|
|
1048
|
+
function normalizeTo_SCREAMING_CASE(text) {
|
|
1275
1049
|
var e_1, _a;
|
|
1276
1050
|
var charType;
|
|
1277
1051
|
var lastCharType = 'OTHER';
|
|
1278
1052
|
var normalizedName = '';
|
|
1279
1053
|
try {
|
|
1280
|
-
for (var
|
|
1281
|
-
var char =
|
|
1054
|
+
for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
|
|
1055
|
+
var char = text_1_1.value;
|
|
1282
1056
|
var normalizedChar = void 0;
|
|
1283
1057
|
if (/^[a-z]$/.test(char)) {
|
|
1284
1058
|
charType = 'LOWERCASE';
|
|
@@ -1313,7 +1087,7 @@
|
|
|
1313
1087
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1314
1088
|
finally {
|
|
1315
1089
|
try {
|
|
1316
|
-
if (
|
|
1090
|
+
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
1317
1091
|
}
|
|
1318
1092
|
finally { if (e_1) throw e_1.error; }
|
|
1319
1093
|
}
|
|
@@ -1324,6 +1098,11 @@
|
|
|
1324
1098
|
return normalizedName;
|
|
1325
1099
|
}
|
|
1326
1100
|
/**
|
|
1101
|
+
* TODO: Tests
|
|
1102
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
|
|
1103
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
|
|
1104
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
|
|
1105
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
|
|
1327
1106
|
* TODO: [🌺] Use some intermediate util splitWords
|
|
1328
1107
|
*/
|
|
1329
1108
|
|
|
@@ -1373,13 +1152,12 @@
|
|
|
1373
1152
|
.filter(function (value) { return value !== ''; });
|
|
1374
1153
|
}
|
|
1375
1154
|
|
|
1376
|
-
function normalizeTo_PascalCase(
|
|
1377
|
-
return normalizeTo_camelCase(
|
|
1155
|
+
function normalizeTo_PascalCase(text) {
|
|
1156
|
+
return normalizeTo_camelCase(text, true);
|
|
1378
1157
|
}
|
|
1379
1158
|
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
return normalizeTo_SCREAMING_CASE(sentence).toLowerCase();
|
|
1159
|
+
function normalizeTo_snake_case(text) {
|
|
1160
|
+
return normalizeTo_SCREAMING_CASE(text).toLowerCase();
|
|
1383
1161
|
}
|
|
1384
1162
|
|
|
1385
1163
|
/**
|
|
@@ -1449,6 +1227,154 @@
|
|
|
1449
1227
|
return true;
|
|
1450
1228
|
}
|
|
1451
1229
|
|
|
1230
|
+
/**
|
|
1231
|
+
* Function parseNumber will parse number from string
|
|
1232
|
+
*
|
|
1233
|
+
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
1234
|
+
* Note: it also works only with decimal numbers
|
|
1235
|
+
*
|
|
1236
|
+
* @returns parsed number
|
|
1237
|
+
* @throws {ParsingError} if the value is not a number
|
|
1238
|
+
*
|
|
1239
|
+
* @private within the parseCommand
|
|
1240
|
+
*/
|
|
1241
|
+
function parseNumber(value) {
|
|
1242
|
+
var originalValue = value;
|
|
1243
|
+
if (typeof value === 'number') {
|
|
1244
|
+
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
1245
|
+
}
|
|
1246
|
+
if (typeof value !== 'string') {
|
|
1247
|
+
return 0;
|
|
1248
|
+
}
|
|
1249
|
+
value = value.trim();
|
|
1250
|
+
if (value.startsWith('+')) {
|
|
1251
|
+
return parseNumber(value.substring(1));
|
|
1252
|
+
}
|
|
1253
|
+
if (value.startsWith('-')) {
|
|
1254
|
+
var number = parseNumber(value.substring(1));
|
|
1255
|
+
if (number === 0) {
|
|
1256
|
+
return 0; // <- Note: To prevent -0
|
|
1257
|
+
}
|
|
1258
|
+
return -number;
|
|
1259
|
+
}
|
|
1260
|
+
value = value.replace(/,/g, '.');
|
|
1261
|
+
value = value.toUpperCase();
|
|
1262
|
+
if (value === '') {
|
|
1263
|
+
return 0;
|
|
1264
|
+
}
|
|
1265
|
+
if (value === '♾' || value.startsWith('INF')) {
|
|
1266
|
+
return Infinity;
|
|
1267
|
+
}
|
|
1268
|
+
if (value.includes('/')) {
|
|
1269
|
+
var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
|
|
1270
|
+
var numerator = parseNumber(numerator_);
|
|
1271
|
+
var denominator = parseNumber(denominator_);
|
|
1272
|
+
if (denominator === 0) {
|
|
1273
|
+
throw new ParsingError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
1274
|
+
}
|
|
1275
|
+
return numerator / denominator;
|
|
1276
|
+
}
|
|
1277
|
+
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
|
1278
|
+
return 0;
|
|
1279
|
+
}
|
|
1280
|
+
if (value.includes('E')) {
|
|
1281
|
+
var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
|
|
1282
|
+
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
1283
|
+
}
|
|
1284
|
+
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
1285
|
+
throw new ParsingError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
1286
|
+
}
|
|
1287
|
+
var num = parseFloat(value);
|
|
1288
|
+
if (isNaN(num)) {
|
|
1289
|
+
throw new ParsingError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
1290
|
+
}
|
|
1291
|
+
return num;
|
|
1292
|
+
}
|
|
1293
|
+
/**
|
|
1294
|
+
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
1295
|
+
*/
|
|
1296
|
+
|
|
1297
|
+
/**
|
|
1298
|
+
* Extracts all code blocks from markdown.
|
|
1299
|
+
*
|
|
1300
|
+
* Note: There are 3 simmilar function:
|
|
1301
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
1302
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
1303
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
1304
|
+
*
|
|
1305
|
+
* @param markdown any valid markdown
|
|
1306
|
+
* @returns code blocks with language and content
|
|
1307
|
+
*
|
|
1308
|
+
*/
|
|
1309
|
+
function extractAllBlocksFromMarkdown(markdown) {
|
|
1310
|
+
var e_1, _a;
|
|
1311
|
+
var codeBlocks = [];
|
|
1312
|
+
var lines = markdown.split('\n');
|
|
1313
|
+
var currentCodeBlock = null;
|
|
1314
|
+
try {
|
|
1315
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
1316
|
+
var line = lines_1_1.value;
|
|
1317
|
+
if (line.startsWith('```')) {
|
|
1318
|
+
var language = line.slice(3).trim() || null;
|
|
1319
|
+
if (currentCodeBlock === null) {
|
|
1320
|
+
currentCodeBlock = { language: language, content: '' };
|
|
1321
|
+
}
|
|
1322
|
+
else {
|
|
1323
|
+
if (language !== null) {
|
|
1324
|
+
// [🌻]
|
|
1325
|
+
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
1326
|
+
}
|
|
1327
|
+
codeBlocks.push(currentCodeBlock);
|
|
1328
|
+
currentCodeBlock = null;
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
else if (currentCodeBlock !== null) {
|
|
1332
|
+
if (currentCodeBlock.content !== '') {
|
|
1333
|
+
currentCodeBlock.content += '\n';
|
|
1334
|
+
}
|
|
1335
|
+
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1340
|
+
finally {
|
|
1341
|
+
try {
|
|
1342
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
1343
|
+
}
|
|
1344
|
+
finally { if (e_1) throw e_1.error; }
|
|
1345
|
+
}
|
|
1346
|
+
if (currentCodeBlock !== null) {
|
|
1347
|
+
// [🌻]
|
|
1348
|
+
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
1349
|
+
}
|
|
1350
|
+
return codeBlocks;
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
/**
|
|
1354
|
+
* Extracts exactly ONE code block from markdown.
|
|
1355
|
+
*
|
|
1356
|
+
* Note: If there are multiple or no code blocks the function throws an error
|
|
1357
|
+
*
|
|
1358
|
+
* Note: There are 3 simmilar function:
|
|
1359
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
1360
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
1361
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
1362
|
+
*
|
|
1363
|
+
* @param markdown any valid markdown
|
|
1364
|
+
* @returns code block with language and content
|
|
1365
|
+
*/
|
|
1366
|
+
function extractOneBlockFromMarkdown(markdown) {
|
|
1367
|
+
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
1368
|
+
if (codeBlocks.length !== 1) {
|
|
1369
|
+
// TODO: Report more specific place where the error happened
|
|
1370
|
+
throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
|
|
1371
|
+
}
|
|
1372
|
+
return codeBlocks[0];
|
|
1373
|
+
}
|
|
1374
|
+
/***
|
|
1375
|
+
* TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
1376
|
+
*/
|
|
1377
|
+
|
|
1452
1378
|
/**
|
|
1453
1379
|
* Extracts code block from markdown.
|
|
1454
1380
|
*
|
|
@@ -1489,6 +1415,8 @@
|
|
|
1489
1415
|
|
|
1490
1416
|
/**
|
|
1491
1417
|
* Create difference set of two sets.
|
|
1418
|
+
*
|
|
1419
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
1492
1420
|
*/
|
|
1493
1421
|
function difference(a, b, isEqual) {
|
|
1494
1422
|
var e_1, _a;
|
|
@@ -1517,6 +1445,8 @@
|
|
|
1517
1445
|
|
|
1518
1446
|
/**
|
|
1519
1447
|
* Creates a new set with all elements that are present in all sets
|
|
1448
|
+
*
|
|
1449
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
1520
1450
|
*/
|
|
1521
1451
|
function intersection() {
|
|
1522
1452
|
var e_1, _a;
|
|
@@ -1554,6 +1484,8 @@
|
|
|
1554
1484
|
|
|
1555
1485
|
/**
|
|
1556
1486
|
* Creates a new set with all elements that are present in either set
|
|
1487
|
+
*
|
|
1488
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
1557
1489
|
*/
|
|
1558
1490
|
function union() {
|
|
1559
1491
|
var e_1, _a, e_2, _b;
|
|
@@ -1692,10 +1624,196 @@
|
|
|
1692
1624
|
* TODO: [🧠] Should this also unwrap the (parenthesis)
|
|
1693
1625
|
*/
|
|
1694
1626
|
|
|
1627
|
+
/**
|
|
1628
|
+
* Tests if given string is valid URL.
|
|
1629
|
+
*
|
|
1630
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
1631
|
+
*/
|
|
1632
|
+
function isValidFilePath(filePath) {
|
|
1633
|
+
if (typeof filePath !== 'string') {
|
|
1634
|
+
return false;
|
|
1635
|
+
}
|
|
1636
|
+
var filePathSlashes = filePath.split('\\').join('/');
|
|
1637
|
+
// Absolute Unix path: /hello.txt
|
|
1638
|
+
if (/^(\/)/i.test(filePathSlashes)) {
|
|
1639
|
+
return true;
|
|
1640
|
+
}
|
|
1641
|
+
// Absolute Windows path: /hello.txt
|
|
1642
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
|
|
1643
|
+
return true;
|
|
1644
|
+
}
|
|
1645
|
+
// Relative path: ./hello.txt
|
|
1646
|
+
if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
|
|
1647
|
+
return true;
|
|
1648
|
+
}
|
|
1649
|
+
return false;
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
function isValidJavascriptName(javascriptName) {
|
|
1653
|
+
if (typeof javascriptName !== 'string') {
|
|
1654
|
+
return false;
|
|
1655
|
+
}
|
|
1656
|
+
return /^[a-zA-Z_$][0-9a-zA-Z_$]*$/i.test(javascriptName);
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
/**
|
|
1660
|
+
* Tests if given string is valid semantic version
|
|
1661
|
+
*
|
|
1662
|
+
* Note: There are two simmilar functions:
|
|
1663
|
+
* - `isValidSemanticVersion` which tests any semantic version
|
|
1664
|
+
* - `isValidPromptbookVersion` *(this one)* which tests just Promptbook versions
|
|
1665
|
+
*/
|
|
1666
|
+
function isValidSemanticVersion(version) {
|
|
1667
|
+
if (typeof version !== 'string') {
|
|
1668
|
+
return false;
|
|
1669
|
+
}
|
|
1670
|
+
if (version.startsWith('0.0.0')) {
|
|
1671
|
+
return false;
|
|
1672
|
+
}
|
|
1673
|
+
return /^\d+\.\d+\.\d+(-\d+)?$/i.test(version);
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
/**
|
|
1677
|
+
* Tests if given string is valid promptbook version
|
|
1678
|
+
* It looks into list of known promptbook versions.
|
|
1679
|
+
*
|
|
1680
|
+
* @see https://www.npmjs.com/package/promptbook?activeTab=versions
|
|
1681
|
+
* Note: When you are using for example promptbook 2.0.0 and there already is promptbook 3.0.0 it don`t know about it.
|
|
1682
|
+
* Note: There are two simmilar functions:
|
|
1683
|
+
* - `isValidSemanticVersion` which tests any semantic version
|
|
1684
|
+
* - `isValidPromptbookVersion` *(this one)* which tests just Promptbook versions
|
|
1685
|
+
*/
|
|
1686
|
+
function isValidPromptbookVersion(version) {
|
|
1687
|
+
if (!isValidSemanticVersion(version)) {
|
|
1688
|
+
return false;
|
|
1689
|
+
}
|
|
1690
|
+
if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
|
|
1691
|
+
return false;
|
|
1692
|
+
}
|
|
1693
|
+
// <- TODO: !!!! Check isValidPromptbookVersion against PROMPTBOOK_VERSIONS
|
|
1694
|
+
return true;
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
/**
|
|
1698
|
+
* Checks if an URL is reserved for private networks or localhost.
|
|
1699
|
+
*
|
|
1700
|
+
* Note: There are two simmilar functions:
|
|
1701
|
+
* - `isUrlOnPrivateNetwork` which tests full URL
|
|
1702
|
+
* - `isHostnameOnPrivateNetwork` *(this one)* which tests just hostname
|
|
1703
|
+
*/
|
|
1704
|
+
function isHostnameOnPrivateNetwork(hostname) {
|
|
1705
|
+
if (hostname === 'example.com' ||
|
|
1706
|
+
hostname === 'localhost' ||
|
|
1707
|
+
hostname.endsWith('.localhost') ||
|
|
1708
|
+
hostname.endsWith('.local') ||
|
|
1709
|
+
hostname.endsWith('.test') ||
|
|
1710
|
+
hostname === '127.0.0.1' ||
|
|
1711
|
+
hostname === '::1') {
|
|
1712
|
+
return true;
|
|
1713
|
+
}
|
|
1714
|
+
if (hostname.includes(':')) {
|
|
1715
|
+
// IPv6
|
|
1716
|
+
var ipParts = hostname.split(':');
|
|
1717
|
+
return ipParts[0] === 'fc00' || ipParts[0] === 'fd00' || ipParts[0] === 'fe80';
|
|
1718
|
+
}
|
|
1719
|
+
else {
|
|
1720
|
+
// IPv4
|
|
1721
|
+
var ipParts = hostname.split('.').map(function (part) { return Number.parseInt(part, 10); });
|
|
1722
|
+
return (ipParts[0] === 10 ||
|
|
1723
|
+
(ipParts[0] === 172 && ipParts[1] >= 16 && ipParts[1] <= 31) ||
|
|
1724
|
+
(ipParts[0] === 192 && ipParts[1] === 168));
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
/**
|
|
1729
|
+
* Checks if an IP address or hostname is reserved for private networks or localhost.
|
|
1730
|
+
*
|
|
1731
|
+
* Note: There are two simmilar functions:
|
|
1732
|
+
* - `isUrlOnPrivateNetwork` *(this one)* which tests full URL
|
|
1733
|
+
* - `isHostnameOnPrivateNetwork` which tests just hostname
|
|
1734
|
+
*
|
|
1735
|
+
* @param {string} ipAddress - The IP address to check.
|
|
1736
|
+
* @returns {boolean} Returns true if the IP address is reserved for private networks or localhost, otherwise false.
|
|
1737
|
+
*/
|
|
1738
|
+
function isUrlOnPrivateNetwork(url) {
|
|
1739
|
+
if (typeof url === 'string') {
|
|
1740
|
+
url = new URL(url);
|
|
1741
|
+
}
|
|
1742
|
+
return isHostnameOnPrivateNetwork(url.hostname);
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
/**
|
|
1746
|
+
* Tests if given string is valid URL.
|
|
1747
|
+
*
|
|
1748
|
+
* Note: Dataurl are considered perfectly valid.
|
|
1749
|
+
* Note: There are two simmilar functions:
|
|
1750
|
+
* - `isValidUrl` which tests any URL
|
|
1751
|
+
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
1752
|
+
*/
|
|
1753
|
+
function isValidUrl(url) {
|
|
1754
|
+
if (typeof url !== 'string') {
|
|
1755
|
+
return false;
|
|
1756
|
+
}
|
|
1757
|
+
try {
|
|
1758
|
+
if (url.startsWith('blob:')) {
|
|
1759
|
+
url = url.replace(/^blob:/, '');
|
|
1760
|
+
}
|
|
1761
|
+
var urlObject = new URL(url /* because fail is handled */);
|
|
1762
|
+
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
1763
|
+
return false;
|
|
1764
|
+
}
|
|
1765
|
+
return true;
|
|
1766
|
+
}
|
|
1767
|
+
catch (error) {
|
|
1768
|
+
return false;
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
/**
|
|
1773
|
+
* Tests if given string is valid pipeline URL URL.
|
|
1774
|
+
*
|
|
1775
|
+
* Note: There are two simmilar functions:
|
|
1776
|
+
* - `isValidUrl` which tests any URL
|
|
1777
|
+
* - `isValidPipelineUrl` *(this one)* which tests just pipeline URL
|
|
1778
|
+
*/
|
|
1779
|
+
function isValidPipelineUrl(url) {
|
|
1780
|
+
if (!isValidUrl(url)) {
|
|
1781
|
+
return false;
|
|
1782
|
+
}
|
|
1783
|
+
if (!url.startsWith('https://')) {
|
|
1784
|
+
return false;
|
|
1785
|
+
}
|
|
1786
|
+
if (!url.endsWith('.ptbk.md')) {
|
|
1787
|
+
return false;
|
|
1788
|
+
}
|
|
1789
|
+
if (url.includes('#')) {
|
|
1790
|
+
// TODO: [🐠]
|
|
1791
|
+
return false;
|
|
1792
|
+
}
|
|
1793
|
+
if (isUrlOnPrivateNetwork(url)) {
|
|
1794
|
+
return false;
|
|
1795
|
+
}
|
|
1796
|
+
return true;
|
|
1797
|
+
}
|
|
1798
|
+
/**
|
|
1799
|
+
* TODO: [🐠] Maybe more info why the URL is invalid
|
|
1800
|
+
*/
|
|
1801
|
+
|
|
1802
|
+
/**
|
|
1803
|
+
* Checks if value is valid uuid
|
|
1804
|
+
*/
|
|
1805
|
+
function isValidUuid(value) {
|
|
1806
|
+
if (typeof value !== 'string') {
|
|
1807
|
+
return false;
|
|
1808
|
+
}
|
|
1809
|
+
return /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i.test(value);
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1695
1812
|
/**
|
|
1696
1813
|
* The version of the Promptbook library
|
|
1697
1814
|
*/
|
|
1698
|
-
var PROMPTBOOK_VERSION = '0.
|
|
1815
|
+
var PROMPTBOOK_VERSION = '0.61.0-0';
|
|
1816
|
+
// TODO: !!!! List here all the versions and annotate + put into script
|
|
1699
1817
|
|
|
1700
1818
|
// @promptbook/utils
|
|
1701
1819
|
// And the normalization (originally n12 library) utilities:
|
|
@@ -1709,7 +1827,7 @@
|
|
|
1709
1827
|
'kebab-case': normalizeToKebabCase,
|
|
1710
1828
|
};
|
|
1711
1829
|
/**
|
|
1712
|
-
* TODO: [🧠] Maybe create some indipendent package like
|
|
1830
|
+
* TODO: [🧠] Maybe create some indipendent package like `@promptbook/markdown-utils`
|
|
1713
1831
|
* Note: [🕙] It does not make sence to have simple lower / UPPER case normalization
|
|
1714
1832
|
*/
|
|
1715
1833
|
|
|
@@ -1729,17 +1847,23 @@
|
|
|
1729
1847
|
exports.countWords = countWords;
|
|
1730
1848
|
exports.decapitalize = decapitalize;
|
|
1731
1849
|
exports.difference = difference;
|
|
1732
|
-
exports.extractAllBlocksFromMarkdown = extractAllBlocksFromMarkdown;
|
|
1733
|
-
exports.extractAllListItemsFromMarkdown = extractAllListItemsFromMarkdown;
|
|
1734
1850
|
exports.extractBlock = extractBlock;
|
|
1735
|
-
exports.extractOneBlockFromMarkdown = extractOneBlockFromMarkdown;
|
|
1736
1851
|
exports.extractParameters = extractParameters;
|
|
1737
1852
|
exports.extractParametersFromPromptTemplate = extractParametersFromPromptTemplate;
|
|
1738
1853
|
exports.extractVariables = extractVariables;
|
|
1739
1854
|
exports.forEachAsync = forEachAsync;
|
|
1740
1855
|
exports.intersection = intersection;
|
|
1856
|
+
exports.isHostnameOnPrivateNetwork = isHostnameOnPrivateNetwork;
|
|
1857
|
+
exports.isUrlOnPrivateNetwork = isUrlOnPrivateNetwork;
|
|
1858
|
+
exports.isValidFilePath = isValidFilePath;
|
|
1859
|
+
exports.isValidJavascriptName = isValidJavascriptName;
|
|
1741
1860
|
exports.isValidJsonString = isValidJsonString;
|
|
1742
1861
|
exports.isValidKeyword = isValidKeyword;
|
|
1862
|
+
exports.isValidPipelineUrl = isValidPipelineUrl;
|
|
1863
|
+
exports.isValidPromptbookVersion = isValidPromptbookVersion;
|
|
1864
|
+
exports.isValidSemanticVersion = isValidSemanticVersion;
|
|
1865
|
+
exports.isValidUrl = isValidUrl;
|
|
1866
|
+
exports.isValidUuid = isValidUuid;
|
|
1743
1867
|
exports.nameToUriPart = nameToUriPart;
|
|
1744
1868
|
exports.nameToUriParts = nameToUriParts;
|
|
1745
1869
|
exports.normalizeTo = normalizeTo;
|
|
@@ -1752,10 +1876,8 @@
|
|
|
1752
1876
|
exports.parseKeywords = parseKeywords;
|
|
1753
1877
|
exports.parseKeywordsFromString = parseKeywordsFromString;
|
|
1754
1878
|
exports.parseNumber = parseNumber;
|
|
1755
|
-
exports.removeContentComments = removeContentComments;
|
|
1756
1879
|
exports.removeDiacritics = removeDiacritics;
|
|
1757
1880
|
exports.removeEmojis = removeEmojis;
|
|
1758
|
-
exports.removeMarkdownFormatting = removeMarkdownFormatting;
|
|
1759
1881
|
exports.removeQuotes = removeQuotes;
|
|
1760
1882
|
exports.renameParameter = renameParameter;
|
|
1761
1883
|
exports.renderPromptbookMermaid = renderPromptbookMermaid;
|