diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 5c1146f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T02:59:08.247Z diff --git a/README.md b/README.md index 8b91046..574aa2d 100644 --- a/README.md +++ b/README.md @@ -228,6 +228,13 @@ while ( true ) { @@ -251,6 +258,11 @@ For more information on the project, filing bug reports and feature requests, an --- +## License + +See [LICENSE][stdlib-license]. + + ## Copyright Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. @@ -294,8 +306,18 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [esm-url]: https://github.com/stdlib-js/string-to-grapheme-cluster-iterator/tree/esm [branches-url]: https://github.com/stdlib-js/string-to-grapheme-cluster-iterator/blob/main/branches.md +[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/string-to-grapheme-cluster-iterator/main/LICENSE + [unicode-text-segmentation]: http://www.unicode.org/reports/tr29/ + + +[@stdlib/array/to-iterator]: https://github.com/stdlib-js/array-to-iterator + +[@stdlib/string/to-grapheme-cluster-iterator-right]: https://github.com/stdlib-js/string-to-grapheme-cluster-iterator-right + + + diff --git a/dist/index.js b/dist/index.js index f9f6007..bb77d09 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,32 +1,5 @@ +"use strict";var p=function(e,t){return function(){return t||e((t={exports:{}}).exports,t),t.exports}};var d=p(function(j,m){ +var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),y=require('@stdlib/assert-is-function/dist'),w=require('@stdlib/assert-is-string/dist').isPrimitive,v=require('@stdlib/symbol-iterator/dist'),s=require('@stdlib/string-next-grapheme-cluster-break/dist'),g=require('@stdlib/error-tools-fmtprodmsg/dist');function l(e){var t,a,o,u,r;if(!w(e))throw new TypeError(g('1h1E6',e));if(arguments.length>1){if(u=arguments[1],!y(u))throw new TypeError(g('1h12H',u));t=arguments[2]}return r=0,a={},u?f(a,"next",h):f(a,"next",b),f(a,"return",q),v&&f(a,v,x),a;function h(){var i,n;return o?{done:!0}:(n=s(e,r),n===-1?(o=!0,e.length?{value:u.call(t,e.substring(r),r,e),done:!1}:{done:!0}):(i=u.call(t,e.substring(r,n),r,e),r=n,{value:i,done:!1}))}function b(){var i,n;return o?{done:!0}:(n=s(e,r),n===-1?(o=!0,e.length?{value:e.substring(r),done:!1}:{done:!0}):(i=e.substring(r,n),r=n,{value:i,done:!1}))}function q(i){return o=!0,arguments.length?{value:i,done:!0}:{done:!0}}function x(){return u?l(e,u,t):l(e)}}m.exports=l +});var F=d();module.exports=F; /** @license Apache-2.0 */ - -'use strict'; - -/** -* Create an iterator which iterates over grapheme clusters. -* -* @module @stdlib/string-to-grapheme-cluster-iterator -* -* @example -* var graphemeClusters2iterator = require( '@stdlib/string-to-grapheme-cluster-iterator' ); -* -* var iter = graphemeClusters2iterator( '🌷🍕' ); -* -* var v = iter.next().value; -* // returns '🌷' -* -* v = iter.next().value; -* // returns '🍕' -* -* var bool = iter.next().done; -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; +//# sourceMappingURL=index.js.map diff --git a/dist/main.js b/dist/main.js deleted file mode 100644 index 9459e80..0000000 --- a/dist/main.js +++ /dev/null @@ -1,195 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var nextGraphemeClusterBreak = require( '@stdlib/string-next-grapheme-cluster-break' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each grapheme cluster in a string. -* -* @param {string} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = graphemeClusters2iterator( '🌷🍕' ); -* -* var v = iter.next().value; -* // returns '🌷' -* -* v = iter.next().value; -* // returns '🍕' -* -* var bool = iter.next().done; -* // returns true -*/ -function graphemeClusters2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var i; - if ( !isString( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be astring. Value: `%s`.', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = 0; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - var v; - var j; - if ( FLG ) { - return { - 'done': true - }; - } - j = nextGraphemeClusterBreak( src, i ); - if ( j === -1 ) { - FLG = true; - if ( src.length ) { - return { - 'value': fcn.call( thisArg, src.substring( i ), i, src ), - 'done': false - }; - } - return { - 'done': true - }; - } - v = fcn.call( thisArg, src.substring( i, j ), i, src ); - i = j; - return { - 'value': v, - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - var v; - var j; - if ( FLG ) { - return { - 'done': true - }; - } - j = nextGraphemeClusterBreak( src, i ); - if ( j === -1 ) { - FLG = true; - if ( src.length ) { - return { - 'value': src.substring( i ), - 'done': false - }; - } - return { - 'done': true - }; - } - v = src.substring( i, j ); - i = j; - return { - 'value': v, - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return graphemeClusters2iterator( src, fcn, thisArg ); - } - return graphemeClusters2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = graphemeClusters2iterator;