peasytext 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d5f8327e1e70b66f18778afd2914da514af0011ac3615cf7744add68544546e8
4
+ data.tar.gz: 4a74e440dff05a09cf3566775ac0e82c84b472453c398c71f22fd5617f091a56
5
+ SHA512:
6
+ metadata.gz: d82f793c433c1974726d249375b3adb5f96fe2fbeb691ee624f6603f4ec656bab8717a547bda6b0cac5fff8442b131e61b941c39606441ec616bc9d389e3d1e3
7
+ data.tar.gz: '0149a27af898071c3093ef29b5aef5f6e13727b5673e5061976bad33c6bae4b39d932667cfeaced2d861af735468c48c1e65bcc911e06b6b4d9eaeec7b4aeb00'
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+ require "base64"
5
+
6
+ module PeasyText
7
+ module_function
8
+
9
+ def uppercase(text) = text.upcase
10
+ def lowercase(text) = text.downcase
11
+ def title_case(text) = text.split.map(&:capitalize).join(" ")
12
+ def camel_case(text) = split_words(text).map.with_index { |w, i| i.zero? ? w.downcase : w.capitalize }.join
13
+ def snake_case(text) = split_words(text).map(&:downcase).join("_")
14
+ def kebab_case(text) = split_words(text).map(&:downcase).join("-")
15
+ def pascal_case(text) = split_words(text).map(&:capitalize).join
16
+ def constant_case(text) = split_words(text).map(&:upcase).join("_")
17
+ def dot_case(text) = split_words(text).map(&:downcase).join(".")
18
+
19
+ def word_count(text) = text.split.size
20
+ def char_count(text) = text.length
21
+ def char_count_no_spaces(text) = text.gsub(/\s/, "").length
22
+ def line_count(text) = text.lines.size
23
+ def sentence_count(text) = text.scan(/[.!?]+/).size
24
+
25
+ def reverse(text) = text.reverse
26
+ def reverse_words(text) = text.split.reverse.join(" ")
27
+
28
+ def truncate(text, length: 100, suffix: "...")
29
+ text.length > length ? text[0, length - suffix.length] + suffix : text
30
+ end
31
+
32
+ def slugify(text)
33
+ text.unicode_normalize(:nfkd)
34
+ .encode("ASCII", replace: "")
35
+ .downcase
36
+ .gsub(/[^a-z0-9]+/, "-")
37
+ .gsub(/\A-|-\z/, "")
38
+ end
39
+
40
+ def base64_encode(text) = Base64.strict_encode64(text)
41
+ def base64_decode(text) = Base64.strict_decode64(text)
42
+ def url_encode(text) = URI.encode_www_form_component(text)
43
+ def url_decode(text) = URI.decode_www_form_component(text)
44
+
45
+ def split_words(text)
46
+ text.gsub(/([a-z])([A-Z])/, "\\1 \\2")
47
+ .gsub(/([A-Z]+)([A-Z][a-z])/, "\\1 \\2")
48
+ .gsub(/[-_.\s]+/, " ")
49
+ .split
50
+ end
51
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PeasyText
4
+ VERSION = "0.1.1"
5
+ end
data/lib/peasytext.rb ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "peasytext/version"
4
+ require_relative "peasytext/engine"
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: peasytext
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - PeasyTools
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Text processing library for Ruby — case conversion (camelCase, snake_case,
13
+ kebab-case, PascalCase), word/character counting, slug generation, Base64/URL encoding.
14
+ Zero dependencies.
15
+ email:
16
+ - hello@peasytools.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/peasytext.rb
22
+ - lib/peasytext/engine.rb
23
+ - lib/peasytext/version.rb
24
+ homepage: https://peasytext.com
25
+ licenses:
26
+ - MIT
27
+ metadata:
28
+ homepage_uri: https://peasytext.com
29
+ source_code_uri: https://github.com/peasytools/peasytext-rb
30
+ changelog_uri: https://github.com/peasytools/peasytext-rb/blob/main/CHANGELOG.md
31
+ documentation_uri: https://peasytext.com
32
+ bug_tracker_uri: https://github.com/peasytools/peasytext-rb/issues
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubygems_version: 4.0.3
48
+ specification_version: 4
49
+ summary: Text analysis — case conversion, word count, slugs, encoding
50
+ test_files: []