Skip to content

Commit f289986

Browse files
Initial commit.
1 parent e2458cb commit f289986

27 files changed

+1364
-0
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.idea/
2+
node_modules/
3+
yarn.lock
4+
package-lock.json
5+
.*
6+
!.csscomb.json
7+
!.gitignore
8+
!.gitattributes
9+
!.hound.yml
10+
!.scss-lint.yml
11+
!.stylelintrc.json
12+
temp

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SassString
2+
3+
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 14.2.0.
4+
5+
## Code scaffolding
6+
7+
Run `ng generate component component-name --project sass-string` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project sass-string`.
8+
> Note: Don't forget to add `--project sass-string` or else it will be added to the default project in your `angular.json` file.
9+
10+
## Build
11+
12+
Run `ng build sass-string` to build the project. The build artifacts will be stored in the `dist/` directory.
13+
14+
## Publishing
15+
16+
After building your library with `ng build sass-string`, go to the dist folder `cd dist/sass-string` and run `npm publish`.
17+
18+
## Running unit tests
19+
20+
Run `ng test sass-string` to execute the unit tests via [Karma](https://karma-runner.github.io).
21+
22+
## Further help
23+
24+
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.

index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@forward "src/lib";

karma.conf.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Karma configuration file, see link for more information
2+
// https://karma-runner.github.io/1.0/config/configuration-file.html
3+
4+
module.exports = function (config) {
5+
config.set({
6+
basePath: '',
7+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
8+
plugins: [
9+
require('karma-jasmine'),
10+
require('karma-chrome-launcher'),
11+
require('karma-jasmine-html-reporter'),
12+
require('karma-coverage'),
13+
require('@angular-devkit/build-angular/plugins/karma')
14+
],
15+
client: {
16+
jasmine: {
17+
// you can add configuration options for Jasmine here
18+
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
19+
// for example, you can disable the random execution with `random: false`
20+
// or set a specific seed with `seed: 4321`
21+
},
22+
clearContext: false // leave Jasmine Spec Runner output visible in browser
23+
},
24+
jasmineHtmlReporter: {
25+
suppressAll: true // removes the duplicated traces
26+
},
27+
coverageReporter: {
28+
dir: require('path').join(__dirname, '../../coverage/sass-string'),
29+
subdir: '.',
30+
reporters: [
31+
{ type: 'html' },
32+
{ type: 'text-summary' }
33+
]
34+
},
35+
reporters: ['progress', 'kjhtml'],
36+
port: 9876,
37+
colors: true,
38+
logLevel: config.LOG_INFO,
39+
autoWatch: true,
40+
browsers: ['Chrome'],
41+
singleRun: false,
42+
restartOnFileChange: true
43+
});
44+
};

ng-package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3+
"dest": "../../dist/sass-string",
4+
"lib": {
5+
"entryFile": "src/public-api.ts"
6+
},
7+
"assets": [
8+
"./src/lib/**/*.scss",
9+
"*.scss"
10+
]
11+
}

package.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "@angular-package/sass-string",
3+
"version": "1.0.0-beta",
4+
"author": "@angular-package <contact@angular-package.dev>",
5+
"homepage": "https://angular-package.github.io/spectre.css",
6+
"description": "Extension for sass modules and new modules.",
7+
"main": "./index.scss",
8+
"license": "MIT",
9+
"publishConfig": {
10+
"access": "public",
11+
"registry": "https://registry.npmjs.org"
12+
},
13+
"devDependencies": {
14+
"stylelint": "^15.10.3",
15+
"stylelint-config-prettier-scss": "^1.0.0",
16+
"stylelint-config-standard-scss": "^11.0.0",
17+
"stylelint-order": "^6.0.3"
18+
},
19+
"peerDependencies": {
20+
"sass": "^1.78.0"
21+
},
22+
"scripts": {
23+
"dart": "dart compile-sass.dart"
24+
},
25+
"repository": {
26+
"type": "git",
27+
"url": "https://github.com/angular-package/sass-string"
28+
},
29+
"bugs": {
30+
"url": "https://github.com/angular-package/sass-string/issues"
31+
},
32+
"keywords": [
33+
"@angular-package",
34+
"sass:string",
35+
"scss",
36+
"string"
37+
],
38+
"funding": [
39+
{
40+
"type": "individual",
41+
"url": "https://checkout.revolut.com/pay/048b10a3-0e10-42c8-a917-e3e9cb4c8e29"
42+
},
43+
{
44+
"type": "individual",
45+
"url": "https://docs.angular-package.dev/donate/cryptocurrency"
46+
},
47+
{
48+
"type": "patreon",
49+
"url": "https://www.patreon.com/angularpackage"
50+
},
51+
{
52+
"type": "github",
53+
"url": "https://github.com/sponsors/angular-package"
54+
}
55+
]
56+
}

spec.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Not active.
2+
3+
// @use "./src/lib/spec";
4+
// @use "../sass-string";
5+
6+
// @debug sass-string.ends-with("primary dark", dark); // true

src/lib/_index.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@forward "string.ends-with.function";
2+
@forward "string.index.function";
3+
@forward "string.is-lower-case.function";
4+
@forward "string.is-upper-case.function";
5+
@forward "string.is.function";
6+
@forward "string.join.function";
7+
@forward "string.of.function";
8+
@forward "string.replace-multiple.function";
9+
@forward "string.replace.function";
10+
@forward "string.split.function";
11+
@forward "string.starts-with.function";
12+
@forward "string.to-map.function";
13+
@forward "string.unquote.function";
14+
@forward "sass:string" hide index, split, unquote;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Sass.
2+
@use 'sass:meta';
3+
@use 'sass:string';
4+
5+
// Completed
6+
// The `string.ends-with()` function determines whether `$string` ends with `$search-string` at `$position`.
7+
// @param `$string` String to determine that it ends with `$search-string` at `$position`.
8+
// @param `$search-string` String to determine that ends in `$string` at `$position`.
9+
// @param `$position` Position at which `$search-string` is expected to be found.
10+
// @returns The returned value is a `bool` indicating whether `$string` ends with `$search-string` at `$position`.
11+
@function ends-with($string, $search-string, $position: null) {
12+
@if not (meta.type-of($string) == string) {
13+
@error "$string: #{$string} is not string";
14+
}
15+
@if not (meta.type-of($search-string) == string) {
16+
@error "$search-string: #{$search-string} is not string";
17+
}
18+
$index: string.index($string, $search-string);
19+
@if if($position, $position and $index == $position, true) {
20+
@return ($index - 1) + string.length($search-string) == string.length($string);
21+
}
22+
@return false;
23+
}
24+
25+
// Examples.
26+
// $-text: 'Primary color red';
27+
28+
// @debug ends-with($-text, 'red'); // true
29+
// @debug ends-with($-text, 'color red'); // true
30+
31+
// Position.
32+
// @debug ends-with($-text, 'color red', 9); // true
33+
// @debug ends-with($-text, 'color red', 4); // false

src/lib/_string.index.function.scss

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Sass.
2+
@use 'sass:list';
3+
@use 'sass:meta';
4+
@use 'sass:string';
5+
6+
// Completed
7+
// The `string.index()` function returns index of required `$substring` and additional indexes of `$substrings`.
8+
// @param `$string` String to check whether it contains required `$substring` and additional `$substrings`.
9+
// @param `$substring` A substring to find in `$string`.
10+
// @arbitrary `$substrings...` Additional substrings to find in `$string`.
11+
// @returns The returned value is index of `$substring` and additional indexes of `$substrings`.
12+
@function index($string, $substring, $substrings...) {
13+
@if not (meta.type-of($string) == string) {
14+
@error "$string: #{$string} is not string";
15+
}
16+
$result: ();
17+
@each $substring in list.join($substring, $substrings, comma) {
18+
$result: list.append(
19+
$result,
20+
meta.type-of($substring) == string
21+
and string.index($string, $substring)
22+
or null,
23+
comma
24+
);
25+
}
26+
@if list.length($result) > 0 {
27+
@return list.length($result) > 1
28+
and $result
29+
or list.nth($result, 1);
30+
}
31+
@return null;
32+
}
33+
34+
// Examples.
35+
// Single
36+
// @debug index("Helvetica Neue", "Helvetica"); // 1
37+
// @debug index("Helvetica Neue", "Neue"); // 11
38+
39+
// Multiple
40+
// @debug index("Helvetica Neue", "Helvetica", "Neue"); // 1, 11
41+
// @debug index("Helvetica Neue", "Helvetica", "Neue", "Wrong"); // 1, 11, null
42+
// @debug index("Helvetica Neue", "Helvetica", "Neue", "Wrong", true); // 1, 11, null, null
43+
44+
// null
45+
// @debug index("Helvetica Neue", "d"); // null
46+
47+
// Different type of the `$string`
48+
// @debug index(true, "Helvetica"); // error
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Sass.
2+
@use 'sass:meta';
3+
@use 'sass:string';
4+
5+
// Completed
6+
// The `string.is-lower-case()` function determines `$string` is written in small letters.
7+
// @param `$string` String to determine is written in small letters.
8+
// @returns The returned value is `bool` indicating `$string` is written in small letters.
9+
@function is-lower-case($string) {
10+
@if not (meta.type-of($string) == string) {
11+
@error "$string: #{$string} is not string";
12+
}
13+
@for $i from 1 through string.length($string) {
14+
$letter: string.slice($string, $i, $i);
15+
@if ($letter != string.to-lower-case($letter)) {
16+
@return false;
17+
}
18+
}
19+
@return true;
20+
}
21+
22+
// Examples.
23+
// @debug is-lower-case('test test test'); // true
24+
// @debug is-lower-case('TEST TEST TEST'); // false
25+
// @debug is-lower-case('TEST test TEST'); // false
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Sass.
2+
@use 'sass:meta';
3+
@use 'sass:string';
4+
5+
// Completed
6+
// The `string.is-upper-case()` function determines `$string` is written in capital letters.
7+
// @param `$string` String to determine is written in capital letters.
8+
// @returns The returned value is `bool` indicating `$string` is written in capital letters.
9+
@function is-upper-case($string) {
10+
@if not (meta.type-of($string) == string) {
11+
@error "$string: #{$string} is not string";
12+
}
13+
@for $i from 1 through string.length($string) {
14+
$letter: string.slice($string, $i, $i);
15+
@if ($letter != string.to-upper-case($letter)) {
16+
@return false;
17+
}
18+
}
19+
@return true;
20+
}
21+
22+
// Examples.
23+
// @debug is-upper-case('TEST TEST TEST'); // true
24+
// @debug is-upper-case('test test test'); // false
25+
// @debug is-upper-case('TEST test TEST'); // false

src/lib/_string.is.function.scss

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Sass.
2+
@use 'sass:list';
3+
@use 'sass:meta';
4+
5+
// Completed
6+
// The `string.is()` function checks whether `$value` is `string` type.
7+
// @param `$value` Any value to check against `string` type.
8+
// @arbitrary `$values...` Additional values to check against `string` type.
9+
// @return The returned value is `bool` indicating whether `$value` is `string` type.
10+
@function is($value, $values...) {
11+
@each $value in list.join(($value,), $values, comma) {
12+
@if not (meta.type-of($value) == string) {
13+
@return false;
14+
}
15+
}
16+
@return true;
17+
}
18+
19+
// Examples.
20+
// @debug is(test); // true
21+
// @debug is(test, test1, test2); // true
22+
// @debug is(test, test1, 2); // false
23+
24+
// @debug is(1); // false
25+
// @debug is(1, 2); // false

src/lib/_string.join.function.scss

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Sass.
2+
@use 'sass:list';
3+
@use 'sass:meta';
4+
@use 'sass:string';
5+
6+
// Completed
7+
// The `string.join()` function returns the `string` built from `$elements` separated by `$delimiter` in original elements order.
8+
// @param `$delimiter` The delimiter to add between `$elements`.
9+
// @param `$elements...` Elements to join to returned string of `color`, `list`, `number` or `string` type with the `$delimiter`.
10+
// @returns The returned value is a `string` built from `$elements` with `$delimiter`.
11+
@function join($delimiter, $elements...) {
12+
$string: '';
13+
@each $element in $elements {
14+
@if list.index(color list number string, meta.type-of($element)) {
15+
@each $element in $element {
16+
$string: string.insert($string, #{$element}#{$delimiter or ''}, -1);
17+
}
18+
}
19+
}
20+
@return string.slice($string, 1, calc((string.length($delimiter) + 1) * -1));
21+
}
22+
23+
// Examples.
24+
// @debug join('-');
25+
// @debug join('-', 'a', 'b', 'c'); // a-b-c
26+
// @debug join('-', '', 'a', 'b', 'c'); // -a-b-c
27+
// @debug join('-', 'a', 'b', 'c', ''); // a-b-c-
28+
// @debug join('-', '', 'a', 'b', 'c', ''); // a-b-c-
29+
// @debug join('-', 'a', ('b', 'c')); // a-b-c
30+
// @debug join('-', a, b, c); // a-b-c
31+
32+
// Join number.
33+
// @debug join('-', a, 1, b, 2, c, 3); // a-1-b-2-c-3
34+
35+
// Join color.
36+
// @debug join('-', silver, orange, green, red, blue, yellow); // silver-orange-green-red-blue-yellow

0 commit comments

Comments
 (0)